Skip to content

Commit

Permalink
Validate on deleted IAM members (#2731)
Browse files Browse the repository at this point in the history
Merged PR #2731.
  • Loading branch information
slevenick authored and modular-magician committed Nov 22, 2019
1 parent a6681b9 commit 79f8532
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 3 deletions.
2 changes: 1 addition & 1 deletion build/terraform
2 changes: 1 addition & 1 deletion build/terraform-beta
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@ package google

import (
"encoding/json"
"regexp"
"sort"
"strconv"

"github.com/hashicorp/terraform-plugin-sdk/helper/hashcode"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/helper/validation"
"google.golang.org/api/cloudresourcemanager/v1"
)

Expand Down Expand Up @@ -39,7 +41,10 @@ func dataSourceGoogleIamPolicy() *schema.Resource {
"members": {
Type: schema.TypeSet,
Required: true,
Elem: &schema.Schema{Type: schema.TypeString},
Elem: &schema.Schema{
Type: schema.TypeString,
ValidateFunc: validation.StringDoesNotMatch(regexp.MustCompile("^deleted:"), "Terraform does not support IAM policies for deleted principals"),
},
Set: schema.HashString,
},
<% unless version == 'ga' -%>
Expand Down
3 changes: 3 additions & 0 deletions third_party/terraform/resources/resource_iam_binding.go.erb
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ import (
"errors"
"fmt"
"log"
"regexp"
"strings"

"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/helper/validation"
"google.golang.org/api/cloudresourcemanager/v1"
)

Expand All @@ -23,6 +25,7 @@ var iamBindingSchema = map[string]*schema.Schema{
Elem: &schema.Schema{
Type: schema.TypeString,
DiffSuppressFunc: caseDiffSuppress,
ValidateFunc: validation.StringDoesNotMatch(regexp.MustCompile("^deleted:"), "Terraform does not support IAM bindings for deleted principals"),
},
Set: func(v interface{}) int {
return schema.HashString(strings.ToLower(v.(string)))
Expand Down
2 changes: 2 additions & 0 deletions third_party/terraform/resources/resource_iam_member.go.erb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"strings"

"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/helper/validation"
"google.golang.org/api/cloudresourcemanager/v1"
)

Expand All @@ -22,6 +23,7 @@ var IamMemberBaseSchema = map[string]*schema.Schema{
Required: true,
ForceNew: true,
DiffSuppressFunc: caseDiffSuppress,
ValidateFunc: validation.StringDoesNotMatch(regexp.MustCompile("^deleted:"), "Terraform does not support IAM members for deleted principals"),
},
<% unless version == 'ga' -%>
"condition": {
Expand Down

0 comments on commit 79f8532

Please sign in to comment.