Skip to content

Commit

Permalink
Validate on deleted IAM members
Browse files Browse the repository at this point in the history
Signed-off-by: Modular Magician <[email protected]>
  • Loading branch information
slevenick authored and modular-magician committed Nov 22, 2019
1 parent ba20557 commit b88f60a
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 13 deletions.
9 changes: 7 additions & 2 deletions google-beta/data_source_google_iam_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,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 @@ -38,8 +40,11 @@ func dataSourceGoogleIamPolicy() *schema.Resource {
"members": {
Type: schema.TypeSet,
Required: true,
Elem: &schema.Schema{Type: schema.TypeString},
Set: schema.HashString,
Elem: &schema.Schema{
Type: schema.TypeString,
ValidateFunc: validation.StringDoesNotMatch(regexp.MustCompile("^deleted:"), "Terraform does not support IAM policies for deleted principals"),
},
Set: schema.HashString,
},
"condition": {
Type: schema.TypeList,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,24 +33,23 @@ func TestAccDataprocAutoscalingPolicy_dataprocAutoscalingPolicyExample(t *testin

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
Providers: testAccProvidersOiCS,
CheckDestroy: testAccCheckDataprocAutoscalingPolicyDestroy,
Steps: []resource.TestStep{
{
Config: testAccDataprocAutoscalingPolicy_dataprocAutoscalingPolicyExample(context),
},
{
ResourceName: "google_dataproc_autoscaling_policy.asp",
ImportState: true,
ImportStateVerify: true,
},
},
})
}

func testAccDataprocAutoscalingPolicy_dataprocAutoscalingPolicyExample(context map[string]interface{}) string {
return Nprintf(`
provider "google-beta" {
}
resource "google_dataproc_cluster" "basic" {
provider = google-beta
name = "tf-dataproc-test-%{random_suffix}"
region = "us-central1"
Expand All @@ -62,6 +61,7 @@ resource "google_dataproc_cluster" "basic" {
}
resource "google_dataproc_autoscaling_policy" "asp" {
provider = google-beta
policy_id = "tf-dataproc-test-%{random_suffix}"
location = "us-central1"
Expand Down
3 changes: 3 additions & 0 deletions google-beta/resource_iam_binding.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,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 @@ -22,6 +24,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
3 changes: 3 additions & 0 deletions google-beta/resource_iam_member.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,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 @@ -21,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"),
},
"condition": {
Type: schema.TypeList,
Expand Down
2 changes: 1 addition & 1 deletion google-beta/resource_monitoring_group_generated_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ func TestAccMonitoringGroup_monitoringGroupSubgroupExample(t *testing.T) {
func testAccMonitoringGroup_monitoringGroupSubgroupExample(context map[string]interface{}) string {
return Nprintf(`
resource "google_monitoring_group" "parent" {
display_name = "tf-test MonitoringParentGroup%{random_suffix}"
display_name = "tf-test MonitoringSubGroup%{random_suffix}"
filter = "resource.metadata.region=\"europe-west2\""
}
Expand Down
13 changes: 10 additions & 3 deletions website/docs/r/dataproc_autoscaling_policy.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ description: |-

Describes an autoscaling policy for Dataproc cluster autoscaler.

~> **Warning:** This resource is in beta, and should be used with the terraform-provider-google-beta provider.
See [Provider Versions](https://terraform.io/docs/providers/google/guides/provider_versions.html) for more details on beta resources.


<div class = "oics-button" style="float: right; margin: 0 0 -15px">
Expand All @@ -35,7 +37,11 @@ Describes an autoscaling policy for Dataproc cluster autoscaler.


```hcl
provider "google-beta" {
}
resource "google_dataproc_cluster" "basic" {
provider = google-beta
name = "tf-dataproc-test-"
region = "us-central1"
Expand All @@ -47,6 +53,7 @@ resource "google_dataproc_cluster" "basic" {
}
resource "google_dataproc_autoscaling_policy" "asp" {
provider = google-beta
policy_id = "tf-dataproc-test-"
location = "us-central1"
Expand Down Expand Up @@ -232,9 +239,9 @@ This resource provides the following
AutoscalingPolicy can be imported using any of these accepted formats:

```
$ terraform import google_dataproc_autoscaling_policy.default projects/{{project}}/locations/{{location}}/autoscalingPolicies/{{policy_id}}
$ terraform import google_dataproc_autoscaling_policy.default {{project}}/{{location}}/{{policy_id}}
$ terraform import google_dataproc_autoscaling_policy.default {{location}}/{{policy_id}}
$ terraform import -provider=google-beta google_dataproc_autoscaling_policy.default projects/{{project}}/locations/{{location}}/autoscalingPolicies/{{policy_id}}
$ terraform import -provider=google-beta google_dataproc_autoscaling_policy.default {{project}}/{{location}}/{{policy_id}}
$ terraform import -provider=google-beta google_dataproc_autoscaling_policy.default {{location}}/{{policy_id}}
```

-> If you're importing a resource with beta features, make sure to include `-provider=google-beta`
Expand Down
2 changes: 1 addition & 1 deletion website/docs/r/monitoring_group.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ resource "google_monitoring_group" "basic" {

```hcl
resource "google_monitoring_group" "parent" {
display_name = "tf-test MonitoringParentGroup"
display_name = "tf-test MonitoringSubGroup"
filter = "resource.metadata.region=\"europe-west2\""
}
Expand Down
1 change: 1 addition & 0 deletions website/google.erb
Original file line number Diff line number Diff line change
Expand Up @@ -824,6 +824,7 @@
<li<%= sidebar_current("docs-google-dataproc") %>>
<a href="#">Google Dataproc Resources</a>
<ul class="nav nav-visible">

<li<%= sidebar_current("docs-google-dataproc-autoscaling-policy") %>>
<a href="/docs/providers/google/r/dataproc_autoscaling_policy.html">google_dataproc_autoscaling_policy</a>
</li>
Expand Down

0 comments on commit b88f60a

Please sign in to comment.