Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OBS: filesystems implementation #2210

Merged
merged 2 commits into from Jul 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/resources/cts_tracker_v3.md
Expand Up @@ -22,7 +22,7 @@ resource "opentelekomcloud_cts_tracker_v3" "tracker_v3" {
bucket_name = var.bucket_name
file_prefix_name = "prefix"
is_lts_enabled = true
status = enabled
status = "enabled"
}
```

Expand Down
15 changes: 14 additions & 1 deletion docs/resources/obs_bucket.md
Expand Up @@ -25,6 +25,15 @@ resource "opentelekomcloud_obs_bucket" "b" {
}
```

### Parallel file system bucket

```hcl
resource "opentelekomcloud_obs_bucket" "b" {
bucket = "my-tf-test-bucket"
parallel_fs = true
}
```

### Enable versioning

```hcl
Expand Down Expand Up @@ -245,6 +254,8 @@ The following arguments are supported:
* `storage_class` - (Optional) Specifies the storage class of the bucket. OBS provides three storage classes:
`STANDARD`, `WARM` (Infrequent Access) and `COLD` (Archive). Defaults to `STANDARD`.

* `parallel_fs` - (Optional) Whether enable a bucket as a parallel file system.

* `acl` - (Optional) Specifies the ACL policy for a bucket. The predefined common policies are as follows:
`private`, `public-read`, `public-read-write` and `log-delivery-write`. Defaults to `private`.

Expand Down Expand Up @@ -399,14 +410,16 @@ The `filter_rule` object supports the following

## Attributes Reference

The following attributes are exported:
In addition to all arguments above, the following attributes are exported:

* `id` - The name of the bucket.

* `bucket_domain_name` - The bucket domain name. Will be of format `bucketname.obs.region.otc.t-systems.com`.

* `region` - The region this bucket resides in.

* `bucket_version` - The OBS version of the bucket.

## Import

OBS bucket can be imported using the `bucket`, e.g.
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Expand Up @@ -14,7 +14,7 @@ require (
github.com/jinzhu/copier v0.3.5
github.com/keybase/go-crypto v0.0.0-20200123153347-de78d2cb44f4
github.com/mitchellh/go-homedir v1.1.0
github.com/opentelekomcloud/gophertelekomcloud v0.7.1-0.20230630095411-cba8b4db3d3b
github.com/opentelekomcloud/gophertelekomcloud v0.7.1-0.20230703122253-28970dde6aba
github.com/unknwon/com v1.0.1
golang.org/x/crypto v0.1.0
golang.org/x/sync v0.1.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Expand Up @@ -171,8 +171,8 @@ github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLA
github.com/nsf/jsondiff v0.0.0-20200515183724-f29ed568f4ce h1:RPclfga2SEJmgMmz2k+Mg7cowZ8yv4Trqw9UsJby758=
github.com/oklog/run v1.0.0 h1:Ru7dDtJNOyC66gQ5dQmaCa0qIsAUFY3sFpK1Xk8igrw=
github.com/oklog/run v1.0.0/go.mod h1:dlhp/R75TPv97u0XWUtDeV/lRKWPKSdTuV0TZvrmrQA=
github.com/opentelekomcloud/gophertelekomcloud v0.7.1-0.20230630095411-cba8b4db3d3b h1:G3u2MN9uQjh1MEuYlGIqBHgoyDUCm2OdVXM6g6ki50o=
github.com/opentelekomcloud/gophertelekomcloud v0.7.1-0.20230630095411-cba8b4db3d3b/go.mod h1:9Deb3q2gJvq5dExV+aX+iO+G+mD9Zr9uFt+YY9ONmq0=
github.com/opentelekomcloud/gophertelekomcloud v0.7.1-0.20230703122253-28970dde6aba h1:JMKwEs5fFItVW97NE+lzggY41gAXZFyHMWnHhJeOkjI=
github.com/opentelekomcloud/gophertelekomcloud v0.7.1-0.20230703122253-28970dde6aba/go.mod h1:9Deb3q2gJvq5dExV+aX+iO+G+mD9Zr9uFt+YY9ONmq0=
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
Expand Down
Expand Up @@ -217,6 +217,26 @@ func TestAccObsBucket_notifications(t *testing.T) {
})
}

func TestAccObsBucket_pfs(t *testing.T) {
rInt := acctest.RandInt()
resourceName := "opentelekomcloud_obs_bucket.bucket"
resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { common.TestAccPreCheck(t) },
ProviderFactories: common.TestAccProviderFactories,
CheckDestroy: testAccCheckObsBucketDestroy,
Steps: []resource.TestStep{
{
Config: testAccObsBucketPfs(rInt),
Check: resource.ComposeTestCheckFunc(
testAccCheckObsBucketExists(resourceName),
resource.TestCheckResourceAttr(resourceName, "parallel_fs", "true"),
resource.TestCheckResourceAttr(resourceName, "bucket_version", "3.0"),
),
},
},
})
}

func testAccCheckObsBucketDestroy(s *terraform.State) error {
config := common.TestAccProvider.Meta().(*cfg.Config)
client, err := config.NewObjectStorageClient(env.OS_REGION_NAME)
Expand Down Expand Up @@ -607,3 +627,12 @@ resource "opentelekomcloud_obs_bucket" "bucket" {
}
`, randInt)
}

func testAccObsBucketPfs(randInt int) string {
return fmt.Sprintf(`
resource "opentelekomcloud_obs_bucket" "bucket" {
bucket = "tf-test-bucket-%d"
parallel_fs = true
}
`, randInt)
}
Expand Up @@ -58,6 +58,11 @@ func ResourceObsBucket() *schema.Resource {
Optional: true,
Default: false,
},
"parallel_fs": {
Type: schema.TypeBool,
Optional: true,
ForceNew: true,
},
"logging": {
Type: schema.TypeSet,
Optional: true,
Expand Down Expand Up @@ -311,6 +316,10 @@ func ResourceObsBucket() *schema.Resource {
},
},
},
"bucket_version": {
Type: schema.TypeString,
Computed: true,
},
},
}
}
Expand All @@ -331,9 +340,10 @@ func resourceObsBucketCreate(ctx context.Context, d *schema.ResourceData, meta i
}

opts := &obs.CreateBucketInput{
Bucket: bucket,
ACL: obs.AclType(acl),
StorageClass: obs.StorageClassType(class),
Bucket: bucket,
ACL: obs.AclType(acl),
IsFSFileInterface: d.Get("parallel_fs").(bool),
StorageClass: obs.StorageClassType(class),
}
opts.Location = config.GetRegion(d)
log.Printf("[DEBUG] OBS bucket create opts: %#v", opts)
Expand Down Expand Up @@ -504,6 +514,11 @@ func resourceObsBucketRead(_ context.Context, d *schema.ResourceData, meta inter
return diag.FromErr(err)
}

// Read parallel_fs
if err := setObsBucketMetadata(client, d); err != nil {
return diag.FromErr(err)
}

return nil
}

Expand Down Expand Up @@ -1334,7 +1349,7 @@ func setObsBucketEncryption(client *obs.ObsClient, d *schema.ResourceData) error
config, err := client.GetBucketEncryption(d.Id())
if err != nil {
if oErr, ok := err.(obs.ObsError); ok {
if oErr.BaseModel.StatusCode == 404 {
if oErr.BaseModel.StatusCode == 404 || oErr.Code == "NoSuchEncryptionConfiguration" || oErr.Code == "FsNotSupport" {
return nil
}
}
Expand Down Expand Up @@ -1392,6 +1407,36 @@ func setObsBucketNotifications(client *obs.ObsClient, d *schema.ResourceData) er
return d.Set("event_notifications", configs)
}

func setObsBucketMetadata(obsClient *obs.ObsClient, d *schema.ResourceData) error {
bucket := d.Id()
input := &obs.GetBucketMetadataInput{
Bucket: bucket,
}
output, err := obsClient.GetBucketMetadata(input)
if err != nil {
return fmt.Errorf("error getting metadata of OBS bucket '%s': %w", bucket, err)
}
log.Printf("[DEBUG] getting metadata of OBS bucket %s: %#v", bucket, output)

mErr := multierror.Append(
d.Set("bucket_version", output.Version),
)

if output.FSStatus == "Enabled" {
mErr = multierror.Append(mErr,
d.Set("parallel_fs", true),
)
} else {
mErr = multierror.Append(mErr,
d.Set("parallel_fs", false),
)
}
if mErr.ErrorOrNil() != nil {
return fmt.Errorf("error saving metadata of OBS bucket %s: %s", bucket, mErr)
}
return nil
}

func filterRulesToMapSlice(src []obs.FilterRule) []interface{} {
res := make([]interface{}, len(src))
for i, v := range src {
Expand Down
4 changes: 4 additions & 0 deletions releasenotes/notes/obs_fs-c5499dfd6df3febc.yaml
@@ -0,0 +1,4 @@
---
enhancements:
- |
**[OBS]** Added file system creation for ``resource/opentelekomcloud_obs_bucket`` (`#2210 <https://github.com/opentelekomcloud/terraform-provider-opentelekomcloud/pull/2210>`_)