Skip to content

Commit

Permalink
don't send the condition unless it's set
Browse files Browse the repository at this point in the history
  • Loading branch information
danawillow committed Oct 25, 2019
1 parent 0c0a13b commit d5e5d40
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 10 deletions.
9 changes: 6 additions & 3 deletions third_party/terraform/resources/resource_iam_binding.go.erb
Original file line number Diff line number Diff line change
Expand Up @@ -277,13 +277,16 @@ func resourceIamBindingDelete(newUpdaterFunc newResourceIamUpdaterFunc, enableBa

func getResourceIamBinding(d *schema.ResourceData) *cloudresourcemanager.Binding {
members := d.Get("members").(*schema.Set).List()
return &cloudresourcemanager.Binding{
b := &cloudresourcemanager.Binding{
Members: convertStringArr(members),
Role: d.Get("role").(string),
}
<% unless version == 'ga' -%>
Condition: expandIamCondition(d.Get("condition")),
<% end -%>
if c := expandIamCondition(d.Get("condition")); c != nil {
b.Condition = c
}
<% end -%>
return b
}

<% unless version == 'ga' -%>
Expand Down
9 changes: 6 additions & 3 deletions third_party/terraform/resources/resource_iam_member.go.erb
Original file line number Diff line number Diff line change
Expand Up @@ -159,13 +159,16 @@ func ResourceIamMemberWithBatching(parentSpecificSchema map[string]*schema.Schem
}

func getResourceIamMember(d *schema.ResourceData) *cloudresourcemanager.Binding {
return &cloudresourcemanager.Binding{
b := &cloudresourcemanager.Binding{
Members: []string{d.Get("member").(string)},
Role: d.Get("role").(string),
}
<% unless version == 'ga' -%>
Condition: expandIamCondition(d.Get("condition")),
<% end -%>
if c := expandIamCondition(d.Get("condition")); c != nil {
b.Condition = c
}
<% end -%>
return b
}

func resourceIamMemberCreate(newUpdaterFunc newResourceIamUpdaterFunc, enableBatching bool) schema.CreateFunc {
Expand Down
11 changes: 7 additions & 4 deletions third_party/terraform/utils/iam.go.erb
Original file line number Diff line number Diff line change
Expand Up @@ -259,17 +259,20 @@ func listFromIamBindingMap(bm map[iamBindingKey]map[string]struct{}) []*cloudres
if len(members) == 0 {
continue
}
rb = append(rb, &cloudresourcemanager.Binding{
b := &cloudresourcemanager.Binding{
Role: key.Role,
Members: stringSliceFromGolangSet(members),
}
<% unless version == 'ga' -%>
Condition: &cloudresourcemanager.Expr{
if !key.Condition.Empty() {
b.Condition = &cloudresourcemanager.Expr{
Description: key.Condition.Description,
Expression: key.Condition.Expression,
Title: key.Condition.Title,
},
}
}
<% end -%>
})
rb = append(rb, b)
}
return rb
}
Expand Down

0 comments on commit d5e5d40

Please sign in to comment.