Skip to content

Commit

Permalink
fix(dom): add ep id in cloud service access request body
Browse files Browse the repository at this point in the history
  • Loading branch information
saf3dfsa committed Dec 10, 2024
1 parent d75be7a commit 4cb06c5
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 9 deletions.
7 changes: 4 additions & 3 deletions docs/resources/aom_cloud_service_access.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@ variable "instance_id" {}
variable "service" {}
resource "huaweicloud_aom_cloud_service_access" "test" {
instance_id = var.instance_id
service = var.service
tag_sync = "auto"
instance_id = var.instance_id
service = var.service
tag_sync = "auto"
enterprise_project_id = "0"
}
```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func resourceCloudServiceAccessCreate(ctx context.Context, d *schema.ResourceDat
createOpt := golangsdk.RequestOpts{
KeepResponseBody: true,
MoreHeaders: buildHeaders(cfg, d),
JSONBody: utils.RemoveNil(buildCloudServiceAccessBodyParams(d)),
JSONBody: utils.RemoveNil(buildCloudServiceAccessBodyParams(cfg, client, d, "")),
}

_, err = client.Request("POST", createPath, &createOpt)
Expand All @@ -93,11 +93,16 @@ func resourceCloudServiceAccessCreate(ctx context.Context, d *schema.ResourceDat
return resourceCloudServiceAccessRead(ctx, d, meta)
}

func buildCloudServiceAccessBodyParams(d *schema.ResourceData) map[string]interface{} {
func buildCloudServiceAccessBodyParams(cfg *config.Config, client *golangsdk.ServiceClient, d *schema.ResourceData, id string) map[string]interface{} {

Check warning on line 96 in huaweicloud/services/aom/resource_huaweicloud_aom_cloud_service_access.go

View workflow job for this annotation

GitHub Actions / golangci

line-length-limit: line is 151 characters, out of limit 150 (revive)
bodyParams := map[string]interface{}{
"provider": d.Get("service"),
"tag_sync": d.Get("tag_sync"),
"tags": []interface{}{},
// id is only used for update
"id": utils.ValueIgnoreEmpty(id),
"provider": d.Get("service"),
"tag_sync": d.Get("tag_sync"),
"tags": []interface{}{},
"prometheus_id": d.Get("instance_id"),
"ep_id": utils.ValueIgnoreEmpty(cfg.GetEnterpriseProjectID(d)),
"project_id": client.ProjectID,
}

return bodyParams
Expand Down Expand Up @@ -179,6 +184,16 @@ func resourceCloudServiceAccessUpdate(ctx context.Context, d *schema.ResourceDat
return diag.Errorf("error creating AOM client: %s", err)
}

access, err := getCloudServiceAccesss(client, d, cfg.GetEnterpriseProjectID(d))
if err != nil {
return diag.FromErr(err)
}

id := utils.PathSearch("id", access, "").(string)
if id == "" {
return diag.Errorf("unable to find ID from API response")
}

updateChanges := []string{
"tag_sync",
}
Expand All @@ -192,7 +207,7 @@ func resourceCloudServiceAccessUpdate(ctx context.Context, d *schema.ResourceDat
updateOpt := golangsdk.RequestOpts{
KeepResponseBody: true,
MoreHeaders: buildHeaders(cfg, d),
JSONBody: utils.RemoveNil(buildCloudServiceAccessBodyParams(d)),
JSONBody: utils.RemoveNil(buildCloudServiceAccessBodyParams(cfg, client, d, id)),
}

_, err = client.Request("PUT", updatePath, &updateOpt)
Expand Down

0 comments on commit 4cb06c5

Please sign in to comment.