-
Notifications
You must be signed in to change notification settings - Fork 77
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'devel' into apigw-features
# Conflicts: # go.mod # go.sum
- Loading branch information
Showing
8 changed files
with
707 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
--- | ||
subcategory: "Object Storage Service (OBS)" | ||
layout: "opentelekomcloud" | ||
page_title: "OpenTelekomCloud: opentelekomcloud_obs_bucket_acl" | ||
sidebar_current: "docs-opentelekomcloud-resource-obs-bucket-acl" | ||
description: |- | ||
Manages a OBS Bucket ACL resource within OpenTelekomCloud. | ||
--- | ||
|
||
|
||
# opentelekomcloud_obs_bucket_acl | ||
|
||
Manages an OBS bucket acl resource within OpenTelekomCloud. | ||
|
||
-> **NOTE:** When creating or updating the OBS bucket acl, the original bucket acl will be overwritten. When deleting | ||
the OBS bucket acl, the full permissions of the bucket owner will be set, and the other permissions will be removed. | ||
|
||
## Example Usage | ||
|
||
```hcl | ||
variable "bucket" {} | ||
variable "account1" {} | ||
variable "account2" {} | ||
resource "opentelekomcloud_obs_bucket_acl" "test" { | ||
bucket = var.bucket | ||
owner_permission { | ||
access_to_bucket = ["READ", "WRITE"] | ||
access_to_acl = ["READ_ACP", "WRITE_ACP"] | ||
} | ||
account_permission { | ||
access_to_bucket = ["READ", "WRITE"] | ||
access_to_acl = ["READ_ACP", "WRITE_ACP"] | ||
account_id = var.account1 | ||
} | ||
account_permission { | ||
access_to_bucket = ["READ"] | ||
access_to_acl = ["READ_ACP", "WRITE_ACP"] | ||
account_id = var.account2 | ||
} | ||
public_permission { | ||
access_to_bucket = ["READ", "WRITE"] | ||
} | ||
log_delivery_user_permission { | ||
access_to_bucket = ["READ", "WRITE"] | ||
access_to_acl = ["READ_ACP", "WRITE_ACP"] | ||
} | ||
} | ||
``` | ||
|
||
## Argument Reference | ||
|
||
The following arguments are supported: | ||
|
||
* `bucket` - (Required, String, ForceNew) Specifies the name of the bucket to which to set the acl. | ||
|
||
Changing this parameter will create a new resource. | ||
|
||
* `owner_permission` - (Optional, List) Specifies the bucket owner permission. If omitted, the current obs bucket acl | ||
owner permission will not be changed. | ||
The [permission_struct](#OBSBucketAcl_permission_struct) structure is documented below. | ||
|
||
* `public_permission` - (Optional, List) Specifies the public permission. | ||
The [permission_struct](#OBSBucketAcl_permission_struct) structure is documented below. | ||
|
||
* `log_delivery_user_permission` - (Optional, List) Specifies the log delivery user permission. | ||
The [permission_struct](#OBSBucketAcl_permission_struct) structure is documented below. | ||
|
||
* `account_permission` - (Optional, List) Specifies the account permissions. | ||
The [account_permission_struct](#OBSBucketAcl_account_permission_struct) structure is documented below. | ||
|
||
<a name="OBSBucketAcl_permission_struct"></a> | ||
The `permission_struct` block supports: | ||
|
||
* `access_to_bucket` - (Optional, List) Specifies the access to bucket. Valid values are **READ** and **WRITE**. | ||
|
||
* `access_to_acl` - (Optional, List) Specifies the access to acl. Valid values are **READ_ACP** and **WRITE_ACP**. | ||
|
||
<a name="OBSBucketAcl_account_permission_struct"></a> | ||
The `account_permission_struct` block supports: | ||
|
||
* `access_to_bucket` - (Optional, List) Specifies the access to bucket. Valid values are **READ** and **WRITE**. | ||
|
||
* `access_to_acl` - (Optional, List) Specifies the access to acl. Valid values are **READ_ACP** and **WRITE_ACP**. | ||
|
||
* `account_id` - (Required, String) Specifies the account id to authorize. The account id cannot be the bucket owner, | ||
and must be unique. | ||
|
||
## Attribute Reference | ||
|
||
In addition to all arguments above, the following attributes are exported: | ||
|
||
* `id` - The name of the bucket. | ||
|
||
|
||
* `region` - The region in which resource is created. | ||
|
||
## Import | ||
|
||
The obs bucket acl can be imported using the `bucket`, e.g. | ||
|
||
```bash | ||
$ terraform import opentelekomcloud_obs_bucket_acl.test <bucket-name> | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
142 changes: 142 additions & 0 deletions
142
opentelekomcloud/acceptance/obs/resource_opentelekomcloud_obs_bucket_acl_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,142 @@ | ||
package acceptance | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform" | ||
"github.com/opentelekomcloud/terraform-provider-opentelekomcloud/opentelekomcloud/acceptance/common" | ||
"github.com/opentelekomcloud/terraform-provider-opentelekomcloud/opentelekomcloud/acceptance/env" | ||
"github.com/opentelekomcloud/terraform-provider-opentelekomcloud/opentelekomcloud/common/cfg" | ||
) | ||
|
||
func getOBSBucketAclResourceFunc(conf *cfg.Config, state *terraform.ResourceState) (interface{}, error) { | ||
client, err := conf.NewObjectStorageClient(env.OS_REGION_NAME) | ||
if err != nil { | ||
return nil, fmt.Errorf("error creating OBS client: %s", err) | ||
} | ||
|
||
output, err := client.GetBucketAcl(state.Primary.ID) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return output, nil | ||
} | ||
|
||
func TestAccOBSBucketAcl_basic(t *testing.T) { | ||
var obj interface{} | ||
|
||
bucketName := fmt.Sprintf("bucket-%s", acctest.RandString(3)) | ||
rName := "opentelekomcloud_obs_bucket_acl.test" | ||
|
||
rc := common.InitResourceCheck( | ||
rName, | ||
&obj, | ||
getOBSBucketAclResourceFunc, | ||
) | ||
|
||
resource.ParallelTest(t, resource.TestCase{ | ||
PreCheck: func() { common.TestAccPreCheck(t) }, | ||
ProviderFactories: common.TestAccProviderFactories, | ||
CheckDestroy: rc.CheckResourceDestroy(), | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testOBSBucketAcl_basic(bucketName), | ||
Check: resource.ComposeTestCheckFunc( | ||
rc.CheckResourceExists(), | ||
resource.TestCheckResourceAttr(rName, "bucket", bucketName), | ||
resource.TestCheckResourceAttr(rName, "log_delivery_user_permission.0.access_to_bucket.0", "READ"), | ||
resource.TestCheckResourceAttr(rName, "log_delivery_user_permission.0.access_to_bucket.1", "WRITE"), | ||
resource.TestCheckResourceAttr(rName, "log_delivery_user_permission.0.access_to_acl.0", "READ_ACP"), | ||
resource.TestCheckResourceAttr(rName, "log_delivery_user_permission.0.access_to_acl.1", "WRITE_ACP"), | ||
resource.TestCheckResourceAttr(rName, "account_permission.#", "2"), | ||
resource.TestCheckResourceAttr(rName, "owner_permission.#", "1"), | ||
), | ||
}, | ||
{ | ||
Config: testOBSBucketAcl_basic_update(bucketName), | ||
Check: resource.ComposeTestCheckFunc( | ||
rc.CheckResourceExists(), | ||
resource.TestCheckResourceAttr(rName, "owner_permission.0.access_to_bucket.0", "WRITE"), | ||
resource.TestCheckResourceAttr(rName, "owner_permission.0.access_to_acl.0", "WRITE_ACP"), | ||
resource.TestCheckResourceAttr(rName, "account_permission.0.access_to_acl.0", "READ_ACP"), | ||
resource.TestCheckResourceAttr(rName, "account_permission.0.account_id", "1000010023"), | ||
resource.TestCheckResourceAttr(rName, "public_permission.0.access_to_bucket.0", "READ"), | ||
resource.TestCheckResourceAttr(rName, "public_permission.0.access_to_bucket.1", "WRITE"), | ||
resource.TestCheckResourceAttr(rName, "owner_permission.#", "1"), | ||
resource.TestCheckResourceAttr(rName, "public_permission.#", "1"), | ||
resource.TestCheckResourceAttr(rName, "account_permission.#", "1"), | ||
resource.TestCheckResourceAttr(rName, "log_delivery_user_permission.#", "0"), | ||
), | ||
}, | ||
{ | ||
ResourceName: rName, | ||
ImportState: true, | ||
ImportStateVerify: true, | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func testOBSBucketAcl_base(bucketName string) string { | ||
return fmt.Sprintf(` | ||
resource "opentelekomcloud_obs_bucket" "bucket" { | ||
bucket = "%s" | ||
storage_class = "STANDARD" | ||
acl = "private" | ||
} | ||
`, bucketName) | ||
} | ||
|
||
func testOBSBucketAcl_basic(bucketName string) string { | ||
return fmt.Sprintf(` | ||
%s | ||
resource "opentelekomcloud_obs_bucket_acl" "test" { | ||
bucket = opentelekomcloud_obs_bucket.bucket.bucket | ||
account_permission { | ||
access_to_bucket = ["READ", "WRITE"] | ||
access_to_acl = ["READ_ACP", "WRITE_ACP"] | ||
account_id = "1000010020" | ||
} | ||
account_permission { | ||
access_to_bucket = ["READ"] | ||
access_to_acl = ["READ_ACP", "WRITE_ACP"] | ||
account_id = "1000010021" | ||
} | ||
log_delivery_user_permission { | ||
access_to_bucket = ["READ", "WRITE"] | ||
access_to_acl = ["READ_ACP", "WRITE_ACP"] | ||
} | ||
} | ||
`, testOBSBucketAcl_base(bucketName)) | ||
} | ||
|
||
func testOBSBucketAcl_basic_update(bucketName string) string { | ||
return fmt.Sprintf(` | ||
%s | ||
resource "opentelekomcloud_obs_bucket_acl" "test" { | ||
bucket = opentelekomcloud_obs_bucket.bucket.bucket | ||
owner_permission { | ||
access_to_bucket = ["WRITE"] | ||
access_to_acl = ["WRITE_ACP"] | ||
} | ||
account_permission { | ||
access_to_acl = ["READ_ACP"] | ||
account_id = "1000010023" | ||
} | ||
public_permission { | ||
access_to_bucket = ["READ", "WRITE"] | ||
} | ||
} | ||
`, testOBSBucketAcl_base(bucketName)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,15 @@ | ||
package obs | ||
|
||
import "github.com/opentelekomcloud/terraform-provider-opentelekomcloud/opentelekomcloud/common/cfg" | ||
|
||
const ( | ||
errCreationClient = "error creating OBS client: %w" | ||
) | ||
|
||
func getDomainID(cfg *cfg.Config) (domainId string) { | ||
domainId = cfg.DomainID | ||
if domainId == "" { | ||
domainId = cfg.DomainClient.DomainID | ||
} | ||
return | ||
} |
Oops, something went wrong.