Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ ENHANCEMENTS:

BUG FIXES:
- Fix `Missing Resource Identity After Update` error for Terraform versions below 1.12 (GH-1023).
- `azapi_resource_action`: Fix inconsistent result error when updating `query_parameters` with `when = "destroy"` (GH-1028).

## v2.8.0

Expand Down
2 changes: 2 additions & 0 deletions internal/services/azapi_resource_action_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,8 @@ func (r *ActionResource) Update(ctx context.Context, request resource.UpdateRequ

if plan.When.ValueString() == "apply" {
r.Action(ctx, plan, &response.State, &response.Diagnostics)
} else {
response.Diagnostics.Append(response.State.Set(ctx, plan)...)
}
}

Expand Down
39 changes: 39 additions & 0 deletions internal/services/azapi_resource_action_resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,22 @@ func TestAccActionResource_updateApiVersion(t *testing.T) {
})
}

func TestAccActionResource_updateQueryParametersWhenDestroy(t *testing.T) {
data := acceptance.BuildTestData(t, "azapi_resource_action", "test")
r := ActionResource{}

data.DataSourceTest(t, []resource.TestStep{
{
Config: r.updateQueryParametersWhenDestroy(data, true),
Check: resource.ComposeTestCheckFunc(),
},
{
Config: r.updateQueryParametersWhenDestroy(data, false),
Check: resource.ComposeTestCheckFunc(),
},
})
}

func (r ActionResource) basic(data acceptance.TestData) string {
return fmt.Sprintf(`
%[1]s
Expand Down Expand Up @@ -430,3 +446,26 @@ resource "azapi_resource_action" "test" {
}
`, apiVersion, data.RandomString)
}

func (r ActionResource) updateQueryParametersWhenDestroy(data acceptance.TestData, includeQueryParam bool) string {
queryParams := ""
if includeQueryParam {
queryParams = `
query_parameters = {
"foo" = ["bar"]
}
`
}
return fmt.Sprintf(`
%[1]s

resource "azapi_resource_action" "test" {
type = "Microsoft.Automation/automationAccounts@2021-06-22"
resource_id = azapi_resource.test.id
action = "listKeys"
when = "destroy"
%[2]s
response_export_values = ["*"]
}
`, GenericResource{}.identityNone(data), queryParams)
}
Loading