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

fix(aom): add ep id in cloud service access request body #5993

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
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,17 @@ 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{} {
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 +185,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 +208,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
Loading