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

resource/alicloud_oss_bucket: Fixes apply error when field "bucket" is omitted #7762

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions alicloud/resource_alicloud_oss_bucket.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ func resourceAlicloudOssBucket() *schema.Resource {
"bucket": {
Type: schema.TypeString,
Optional: true,
Computed: true,
ForceNew: true,
ValidateFunc: StringLenBetween(3, 63),
Default: resource.PrefixedUniqueId("tf-oss-bucket-"),
},

"acl": {
Expand Down Expand Up @@ -485,7 +485,11 @@ func resourceAlicloudOssBucket() *schema.Resource {

func resourceAlicloudOssBucketCreate(d *schema.ResourceData, meta interface{}) error {
client := meta.(*connectivity.AliyunClient)
request := map[string]string{"bucketName": d.Get("bucket").(string)}
bucketName, ok := d.Get("bucket").(string)
zcxsythenew marked this conversation as resolved.
Show resolved Hide resolved
if !ok || bucketName == "" {
bucketName = resource.PrefixedUniqueId("tf-oss-bucket-")
}
request := map[string]string{"bucketName": bucketName}
var requestInfo *oss.Client
raw, err := client.WithOssClient(func(ossClient *oss.Client) (interface{}, error) {
requestInfo = ossClient
Expand All @@ -507,7 +511,7 @@ func resourceAlicloudOssBucketCreate(d *schema.ResourceData, meta interface{}) e
}

req := Request{
d.Get("bucket").(string),
bucketName,
oss.StorageClass(oss.StorageClassType(d.Get("storage_class").(string))),
oss.RedundancyType(oss.DataRedundancyType(d.Get("redundancy_type").(string))),
oss.ACL(oss.ACLType(d.Get("acl").(string))),
Expand Down Expand Up @@ -1715,7 +1719,7 @@ func resourceAlicloudOssBucketDelete(d *schema.ResourceData, meta interface{}) e
if IsExpectedErrors(err, []string{"BucketNotEmpty"}) {
if d.Get("force_destroy").(bool) {
raw, er := client.WithOssClient(func(ossClient *oss.Client) (interface{}, error) {
bucket, _ := ossClient.Bucket(d.Get("bucket").(string))
bucket, _ := ossClient.Bucket(d.Id())
lor, err := bucket.ListObjectVersions()
if err != nil {
return nil, WrapErrorf(err, DefaultErrorMsg, d.Id(), "ListObjectVersions", AliyunOssGoSdk)
Expand Down
43 changes: 43 additions & 0 deletions alicloud/resource_alicloud_oss_bucket_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2258,6 +2258,49 @@ func TestAccAliCloudOssBucketResourceGroup(t *testing.T) {
})
}

func TestAccAliCloudOssBucketOmitBucketName(t *testing.T) {
var v oss.GetBucketInfoResult

resourceId := "alicloud_oss_bucket.default"
ra := resourceAttrInit(resourceId, ossBucketBasicMap)

serviceFunc := func() interface{} {
return &OssService{testAccProvider.Meta().(*connectivity.AliyunClient)}
}
rc := resourceCheckInit(resourceId, &v, serviceFunc)

rac := resourceAttrCheckInit(rc, ra)

testAccCheck := rac.resourceAttrMapUpdateSet()
testAccConfig := resourceTestAccConfigFunc(resourceId, "", resourceOssBucketResourceGroupDependence)
resource.Test(t, resource.TestCase{
PreCheck: func() {
testAccPreCheck(t)
},
// module name
IDRefreshName: resourceId,
Providers: testAccProviders,
CheckDestroy: rac.checkResourceDestroy(),
Steps: []resource.TestStep{
{
Config: testAccConfig(map[string]interface{}{
"resource_group_id": "${data.alicloud_resource_manager_resource_groups.default.groups.1.id}",
"redundancy_type": "LRS",
}),
Check: resource.ComposeTestCheckFunc(
testAccCheck(map[string]string{
"bucket": REGEXMATCH + "^tf\\-oss\\-bucket\\-.*$",
"access_monitor.#": "1",
"access_monitor.0.status": "Disabled",
"resource_group_id": CHECKSET,
"redundancy_type": "LRS",
}),
),
},
},
})
}

func resourceOssBucketConfigBasic(name string) string {
return fmt.Sprintf("")
}
Expand Down
Loading