Skip to content

Commit

Permalink
resource/alicloud_log_store: fix bug while creating Metrics telemetry…
Browse files Browse the repository at this point in the history
…_type.
  • Loading branch information
ChenHanZhang committed Jul 1, 2024
1 parent d010e8a commit 2c95473
Show file tree
Hide file tree
Showing 2 changed files with 401 additions and 5 deletions.
25 changes: 20 additions & 5 deletions alicloud/resource_alicloud_log_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,11 +207,21 @@ func resourceAliCloudSlsLogStoreCreate(d *schema.ResourceData, meta interface{})
client := meta.(*connectivity.AliyunClient)

if v, ok := d.GetOk("telemetry_type"); ok && v == "Metrics" {

projectName := d.Get("project_name").(string)
if v, ok := d.GetOkExists("project"); ok {
projectName = v.(string)
}
logstoreName := d.Get("logstore_name").(string)
if v, ok := d.GetOkExists("name"); ok {
logstoreName = v.(string)
}

logstore := buildLogStore(d)
var requestinfo *sls.Client
err := resource.Retry(d.Timeout(schema.TimeoutCreate), func() *resource.RetryError {
raw, err := client.WithLogClient(func(slsClient *sls.Client) (interface{}, error) {
return nil, slsClient.CreateMetricStore(d.Get("project").(string), logstore)
return nil, slsClient.CreateMetricStore(projectName, logstore)
})
if err != nil {
if IsExpectedErrors(err, []string{"InternalServerError", LogClientTimeout}) {
Expand All @@ -221,15 +231,15 @@ func resourceAliCloudSlsLogStoreCreate(d *schema.ResourceData, meta interface{})
return resource.NonRetryableError(err)
}
addDebug("CreateMetricStore", raw, requestinfo, map[string]interface{}{
"project": d.Get("project").(string),
"project": projectName,
"logstore": logstore,
})
return nil
})
if err != nil {
return WrapErrorf(err, DefaultErrorMsg, "alicloud_log_store", "CreateLogStoreV2", AliyunLogGoSdkERROR)
}
d.SetId(fmt.Sprintf("%s%s%s", d.Get("project").(string), COLON_SEPARATED, d.Get("name").(string)))
d.SetId(fmt.Sprintf("%s%s%s", projectName, COLON_SEPARATED, logstoreName))
return resourceAliCloudSlsLogStoreUpdate(d, meta)
}

Expand Down Expand Up @@ -532,11 +542,16 @@ func resourceAliCloudSlsLogStoreUpdate(d *schema.ResourceData, meta interface{})
}
if v, ok := d.GetOk("telemetry_type"); ok && v == "Metrics" {

projectName := d.Get("project_name").(string)
if v, ok := d.GetOkExists("project"); ok {
projectName = v.(string)
}

logstore := buildLogStore(d)
var requestinfo *sls.Client
err := resource.Retry(d.Timeout(schema.TimeoutCreate), func() *resource.RetryError {
raw, err := client.WithLogClient(func(slsClient *sls.Client) (interface{}, error) {
return nil, slsClient.UpdateMetricStore(d.Get("project").(string), logstore)
return nil, slsClient.UpdateMetricStore(projectName, logstore)
})
if err != nil {
if IsExpectedErrors(err, []string{"InternalServerError", LogClientTimeout}) {
Expand All @@ -546,7 +561,7 @@ func resourceAliCloudSlsLogStoreUpdate(d *schema.ResourceData, meta interface{})
return resource.NonRetryableError(err)
}
addDebug("UpdateMetricStore", raw, requestinfo, map[string]interface{}{
"project": d.Get("project").(string),
"project": projectName,
"logstore": logstore,
})
return nil
Expand Down
Loading

0 comments on commit 2c95473

Please sign in to comment.