Skip to content

Commit

Permalink
Fix crash in GCP iam binding middleware
Browse files Browse the repository at this point in the history
  • Loading branch information
eliecharra committed Jan 7, 2022
1 parent cfec9bd commit 5ee437e
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
23 changes: 23 additions & 0 deletions pkg/middlewares/google_iam_binding_tranformer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,29 @@ func TestGoogleProjectIAMBindingTransformer_Execute(t *testing.T) {
expected []*resource.Resource
mock func(factory *terraform.MockResourceFactory)
}{
{
name: "Test that bindings with nil members does not cause any crash",
resourcesFromState: []*resource.Resource{
{
Type: google.GoogleStorageBucketIamBindingResourceType,
Attrs: &resource.Attributes{
"bucket": "hey",
"role": "storage.admin",
"members": nil,
},
},
{
Type: google.GoogleProjectIamBindingResourceType,
Attrs: &resource.Attributes{
"project": "coucou",
"role": "storage.admin",
"members": nil,
},
},
},
expected: []*resource.Resource{},
mock: nil,
},
{
"Test that project bindings are transformed into member",
[]*resource.Resource{
Expand Down
6 changes: 5 additions & 1 deletion pkg/middlewares/google_iam_binding_transformer.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,11 @@ func (m *GoogleIAMBindingTransformer) Execute(_, resourcesFromState *[]*resource

resName := *stateRes.Attrs.GetString(resField)
roleName := *stateRes.Attrs.GetString("role")
members, _ := stateRes.Attrs.Get("members")
members, exist := stateRes.Attrs.Get("members")

if !exist || members == nil {
continue
}

for _, member := range members.([]interface{}) {
id := fmt.Sprintf("%s/%s/%s", resName, roleName, member)
Expand Down

0 comments on commit 5ee437e

Please sign in to comment.