Skip to content

Commit

Permalink
🐛 Fix unmarshal for terraform plan replace_paths
Browse files Browse the repository at this point in the history
Migrate #1511

Fixes #1512

Note: These Terraform tests need a proper migration of their test as described in #1787
Signed-off-by: Dominik Richter <[email protected]>
  • Loading branch information
arlimus committed Sep 19, 2023
1 parent fc5c872 commit 076261a
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
"format_version": "1.5",
"terraform_version": "1.5.0",
"resource_changes": [
{
"address": "",
"module_address": "",
"mode": "managed",
"type": "google_service_account_iam_member",
"name": "cloud_deploy_service_account",
"provider_name": "registry.terraform.io/hashicorp/google",
"change": {
"actions": ["delete", "create"],
"before": {
"condition": [],
"etag": "BwYCXPmcVSE=",
"id": "",
"member": "",
"role": "",
"service_account_id": ""
},
"after": {
"condition": [],
"member": "",
"role": "",
"service_account_id": ""
},
"after_unknown": { "condition": [], "etag": true, "id": true },
"before_sensitive": { "condition": [] },
"after_sensitive": { "condition": [] },
"replace_paths": [["member"]]
},
"action_reason": "replace_because_cannot_update"
}
]
}
18 changes: 18 additions & 0 deletions providers/terraform/provider/tfplan_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,3 +96,21 @@ func TestTerraformPlanParsing(t *testing.T) {

assert.Equal(t, 1, len(pc.RootModule.Resources))
}

// // FIXME: This test needs migration
// func TestTerraformPlanParsingReplacePaths(t *testing.T) {
// path := "./testdata/tfplan-replace-paths/tfplan.json"
// query := "terraform.plan.resourceChanges"
// res := testTerraformPlanQueryWithPath(t, query, path)
// require.NotEmpty(t, res)
// assert.Empty(t, res[0].Result().Error)

// query = "terraform.plan.resourceChanges[0].change.replacePaths"
// res = testTerraformPlanQueryWithPath(t, query, path)
// require.NotEmpty(t, res)
// resArrayInterface, ok := res[0].Data.Value.([]interface{})
// require.True(t, ok)
// resArrayStrings, ok := resArrayInterface[0].([]interface{})
// require.True(t, ok)
// assert.Equal(t, "member", resArrayStrings[0].(string))
// }
4 changes: 2 additions & 2 deletions providers/terraform/resources/tfplan.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ func (t *mqlTerraformPlan) resourceChanges() ([]interface{}, error) {
}
}

var replacePaths map[string]interface{}
var replacePaths []interface{}
if rc.Change.ReplacePaths != nil {
if err := json.Unmarshal(rc.Change.ReplacePaths, &replacePaths); err != nil {
return nil, err
Expand All @@ -99,7 +99,7 @@ func (t *mqlTerraformPlan) resourceChanges() ([]interface{}, error) {
"afterUnknown": llx.MapData(afterUnknown, types.Any),
"beforeSensitive": llx.MapData(beforeSensitive, types.Any),
"afterSensitive": llx.MapData(afterSensitive, types.Any),
"replacePaths": llx.MapData(replacePaths, types.Any),
"replacePaths": llx.ArrayData(replacePaths, types.Any),
})
if err != nil {
return nil, err
Expand Down

0 comments on commit 076261a

Please sign in to comment.