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_access_monitor: add wait for status while create and update opertion. #8051

Merged
merged 1 commit into from
Dec 27, 2024
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 20 additions & 3 deletions alicloud/resource_alicloud_oss_bucket_access_monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ func resourceAliCloudOssBucketAccessMonitorCreate(d *schema.ResourceData, meta i
hostMap["bucket"] = StringPointer(d.Get("bucket").(string))

objectDataLocalMap := make(map[string]interface{})

if v := d.Get("status"); v != nil {
objectDataLocalMap["Status"] = v
request["AccessMonitorConfiguration"] = objectDataLocalMap
Expand All @@ -77,16 +78,22 @@ func resourceAliCloudOssBucketAccessMonitorCreate(d *schema.ResourceData, meta i
}
return resource.NonRetryableError(err)
}
addDebug(action, response, request)
return nil
})
addDebug(action, response, request)

if err != nil {
return WrapErrorf(err, DefaultErrorMsg, "alicloud_oss_bucket_access_monitor", action, AlibabaCloudSdkGoERROR)
}

d.SetId(fmt.Sprint(*hostMap["bucket"]))

ossServiceV2 := OssServiceV2{client}
stateConf := BuildStateConf([]string{}, []string{fmt.Sprint(d.Get("status"))}, d.Timeout(schema.TimeoutCreate), 0, ossServiceV2.OssBucketAccessMonitorStateRefreshFunc(d.Id(), "Status", []string{}))
if _, err := stateConf.WaitForState(); err != nil {
return WrapErrorf(err, IdMsg, d.Id())
}

return resourceAliCloudOssBucketAccessMonitorRead(d, meta)
}

Expand All @@ -104,7 +111,9 @@ func resourceAliCloudOssBucketAccessMonitorRead(d *schema.ResourceData, meta int
return WrapError(err)
}

d.Set("status", objectRaw["Status"])
if objectRaw["Status"] != nil {
d.Set("status", objectRaw["Status"])
}

d.Set("bucket", d.Id())

Expand All @@ -118,6 +127,7 @@ func resourceAliCloudOssBucketAccessMonitorUpdate(d *schema.ResourceData, meta i
var query map[string]*string
var body map[string]interface{}
update := false

action := fmt.Sprintf("/?accessmonitor")
conn, err := client.NewOssClient()
if err != nil {
Expand All @@ -128,10 +138,12 @@ func resourceAliCloudOssBucketAccessMonitorUpdate(d *schema.ResourceData, meta i
body = make(map[string]interface{})
hostMap := make(map[string]*string)
hostMap["bucket"] = StringPointer(d.Id())

if d.HasChange("status") {
update = true
}
objectDataLocalMap := make(map[string]interface{})

if v := d.Get("status"); v != nil {
objectDataLocalMap["Status"] = d.Get("status")
request["AccessMonitorConfiguration"] = objectDataLocalMap
Expand All @@ -151,12 +163,17 @@ func resourceAliCloudOssBucketAccessMonitorUpdate(d *schema.ResourceData, meta i
}
return resource.NonRetryableError(err)
}
addDebug(action, response, request)
return nil
})
addDebug(action, response, request)
if err != nil {
return WrapErrorf(err, DefaultErrorMsg, d.Id(), action, AlibabaCloudSdkGoERROR)
}
ossServiceV2 := OssServiceV2{client}
stateConf := BuildStateConf([]string{}, []string{fmt.Sprint(d.Get("status"))}, d.Timeout(schema.TimeoutUpdate), 0, ossServiceV2.OssBucketAccessMonitorStateRefreshFunc(d.Id(), "Status", []string{}))
if _, err := stateConf.WaitForState(); err != nil {
return WrapErrorf(err, IdMsg, d.Id())
}
}

return resourceAliCloudOssBucketAccessMonitorRead(d, meta)
Expand Down
6 changes: 4 additions & 2 deletions alicloud/service_alicloud_oss_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -705,11 +705,13 @@ func (s *OssServiceV2) DescribeOssBucketAccessMonitor(id string) (object map[str
}
return resource.NonRetryableError(err)
}
addDebug(action, response, request)
return nil
})
addDebug(action, response, request)
if err != nil {
addDebug(action, response, request)
if IsExpectedErrors(err, []string{"NoSuchBucket"}) {
return object, WrapErrorf(Error(GetNotFoundMessage("BucketAccessMonitor", id)), NotFoundMsg, response)
}
return object, WrapErrorf(err, DefaultErrorMsg, id, action, AlibabaCloudSdkGoERROR)
}
response = response["body"].(map[string]interface{})
Expand Down
Loading