diff --git a/google-beta/iam_iap_tunnel_instance.go b/google-beta/iam_iap_tunnel_instance.go index 8e7c58f8e2..3db67bc126 100644 --- a/google-beta/iam_iap_tunnel_instance.go +++ b/google-beta/iam_iap_tunnel_instance.go @@ -1,156 +1,182 @@ +// ---------------------------------------------------------------------------- +// +// *** AUTO GENERATED CODE *** AUTO GENERATED CODE *** +// +// ---------------------------------------------------------------------------- +// +// This file is automatically generated by Magic Modules and manual +// changes will be clobbered when the file is regenerated. +// +// Please read more about how to change this file in +// .github/CONTRIBUTING.md. +// +// ---------------------------------------------------------------------------- package google import ( "fmt" - "strconv" - "strings" "github.com/hashicorp/errwrap" "github.com/hashicorp/terraform-plugin-sdk/helper/schema" "google.golang.org/api/cloudresourcemanager/v1" - iap "google.golang.org/api/iap/v1beta1" ) -var IamIapTunnelInstanceSchema = map[string]*schema.Schema{ - "instance": { - Type: schema.TypeString, - Required: true, - ForceNew: true, - }, - +var IapTunnelInstanceIamSchema = map[string]*schema.Schema{ "project": { Type: schema.TypeString, - Optional: true, Computed: true, + Optional: true, ForceNew: true, }, - "zone": { Type: schema.TypeString, - Optional: true, Computed: true, + Optional: true, ForceNew: true, }, + "instance": { + Type: schema.TypeString, + Required: true, + ForceNew: true, + DiffSuppressFunc: compareSelfLinkOrResourceName, + }, } type IapTunnelInstanceIamUpdater struct { - project string - zone string - instance string - projectNumber string - Config *Config + project string + zone string + instance string + d *schema.ResourceData + Config *Config } -func NewIapTunnelInstanceIamUpdater(d *schema.ResourceData, config *Config) (ResourceIamUpdater, error) { +func IapTunnelInstanceIamUpdaterProducer(d *schema.ResourceData, config *Config) (ResourceIamUpdater, error) { + values := make(map[string]string) + project, err := getProject(d, config) if err != nil { return nil, err } - - res, err := config.clientResourceManager.Projects.Get(project).Do() + values["project"] = project + zone, err := getZone(d, config) if err != nil { return nil, err } + values["zone"] = zone + if v, ok := d.GetOk("instance"); ok { + values["instance"] = v.(string) + } - //The IAP API currently doesn't work when using a projectId. When hitting the endpoint with a projectId instead - //of a projectNumber, the backend returns a 400 error, saying that it is an invalid argument. We abstract away - //this implementation detail from the consumer, and allow consumers to work with projectIds, which is consistent - //with other resources. However, that means we have to maintain/lookup the projectNumber from the projectID - //inside this provider plugin. - projectNumber := strconv.FormatInt(res.ProjectNumber, 10) - - zone, err := getZone(d, config) + // We may have gotten either a long or short name, so attempt to parse long name if possible + m, err := getImportIdQualifiers([]string{"projects/(?P[^/]+)/iap_tunnel/zones/(?P[^/]+)/instances/(?P[^/]+)", "projects/(?P[^/]+)/zones/(?P[^/]+)/instances/(?P[^/]+)", "(?P[^/]+)/(?P[^/]+)/(?P[^/]+)", "(?P[^/]+)/(?P[^/]+)", "(?P[^/]+)"}, d, config, d.Get("instance").(string)) if err != nil { return nil, err } - return &IapTunnelInstanceIamUpdater{ - project: project, - projectNumber: projectNumber, - zone: zone, - instance: d.Get("instance").(string), - Config: config, - }, nil + for k, v := range m { + values[k] = v + } + + u := &IapTunnelInstanceIamUpdater{ + project: values["project"], + zone: values["zone"], + instance: values["instance"], + d: d, + Config: config, + } + + d.Set("project", u.project) + d.Set("zone", u.zone) + d.Set("instance", u.GetResourceId()) + + return u, nil } func IapTunnelInstanceIdParseFunc(d *schema.ResourceData, config *Config) error { - parts := strings.Split(d.Id(), "/") - var fv *ZonalFieldValue - if len(parts) == 3 { - // {project}/{zone}/{name} syntax - fv = &ZonalFieldValue{ - Project: parts[0], - Zone: parts[1], - Name: parts[2], - resourceType: "instances", - } - } else if len(parts) == 2 { - // /{zone}/{name} syntax - project, err := getProject(d, config) - if err != nil { - return err - } - fv = &ZonalFieldValue{ - Project: project, - Zone: parts[0], - Name: parts[1], - resourceType: "instances", - } - } else { - // We either have a name or a full self link, so use the field helper - var err error - fv, err = ParseInstanceFieldValue(d.Id(), d, config) - if err != nil { - return err - } - } - - d.Set("project", fv.Project) - d.Set("zone", fv.Zone) - d.Set("instance", fv.Name) - - res, err := config.clientResourceManager.Projects.Get(fv.Project).Do() + values := make(map[string]string) + + project, err := getProject(d, config) + if err != nil { + return err + } + values["project"] = project + zone, err := getZone(d, config) + if err != nil { + return err + } + values["zone"] = zone + + m, err := getImportIdQualifiers([]string{"projects/(?P[^/]+)/iap_tunnel/zones/(?P[^/]+)/instances/(?P[^/]+)", "projects/(?P[^/]+)/zones/(?P[^/]+)/instances/(?P[^/]+)", "(?P[^/]+)/(?P[^/]+)/(?P[^/]+)", "(?P[^/]+)/(?P[^/]+)", "(?P[^/]+)"}, d, config, d.Id()) if err != nil { return err } - projectNumber := strconv.FormatInt(res.ProjectNumber, 10) + for k, v := range m { + values[k] = v + } - // Explicitly set the id so imported resources have the same ID format as non-imported ones. - d.SetId(fmt.Sprintf("projects/%s/iap_tunnel/zones/%s/instances/%s", projectNumber, fv.Zone, fv.Name)) + u := &IapTunnelInstanceIamUpdater{ + project: values["project"], + zone: values["zone"], + instance: values["instance"], + d: d, + Config: config, + } + d.Set("instance", u.GetResourceId()) + d.SetId(u.GetResourceId()) return nil } func (u *IapTunnelInstanceIamUpdater) GetResourceIamPolicy() (*cloudresourcemanager.Policy, error) { - req := &iap.GetIamPolicyRequest{} + url, err := u.qualifyTunnelInstanceUrl("getIamPolicy") + if err != nil { + return nil, err + } - p, err := u.Config.clientIAP.V1beta1.GetIamPolicy(fmt.Sprintf("projects/%s/iap_tunnel/zones/%s/instances/%s", u.projectNumber, u.zone, u.instance), req).Do() + project, err := getProject(u.d, u.Config) + if err != nil { + return nil, err + } + var obj map[string]interface{} + obj = map[string]interface{}{ + "options": map[string]interface{}{ + "requestedPolicyVersion": iamPolicyVersion, + }, + } + policy, err := sendRequest(u.Config, "POST", project, url, obj) if err != nil { return nil, errwrap.Wrapf(fmt.Sprintf("Error retrieving IAM policy for %s: {{err}}", u.DescribeResource()), err) } - cloudResourcePolicy, err := iapToResourceManagerPolicy(p) - + out := &cloudresourcemanager.Policy{} + err = Convert(policy, out) if err != nil { - return nil, errwrap.Wrapf(fmt.Sprintf("Invalid IAM policy for %s: {{err}}", u.DescribeResource()), err) + return nil, errwrap.Wrapf("Cannot convert a policy to a resource manager policy: {{err}}", err) } - return cloudResourcePolicy, nil + return out, nil } func (u *IapTunnelInstanceIamUpdater) SetResourceIamPolicy(policy *cloudresourcemanager.Policy) error { - iapPolicy, err := resourceManagerToIapPolicy(policy) - + json, err := ConvertToMap(policy) if err != nil { - return errwrap.Wrapf(fmt.Sprintf("Invalid IAM policy for %s: {{err}}", u.DescribeResource()), err) + return err } - req := &iap.SetIamPolicyRequest{ - Policy: iapPolicy, + obj := make(map[string]interface{}) + obj["policy"] = json + + url, err := u.qualifyTunnelInstanceUrl("setIamPolicy") + if err != nil { + return err + } + project, err := getProject(u.d, u.Config) + if err != nil { + return err } - _, err = u.Config.clientIAP.V1beta1.SetIamPolicy(fmt.Sprintf("projects/%s/iap_tunnel/zones/%s/instances/%s", u.projectNumber, u.zone, u.instance), req).Do() + _, err = sendRequestWithTimeout(u.Config, "POST", project, url, obj, u.d.Timeout(schema.TimeoutCreate)) if err != nil { return errwrap.Wrapf(fmt.Sprintf("Error setting IAM policy for %s: {{err}}", u.DescribeResource()), err) } @@ -158,32 +184,23 @@ func (u *IapTunnelInstanceIamUpdater) SetResourceIamPolicy(policy *cloudresource return nil } +func (u *IapTunnelInstanceIamUpdater) qualifyTunnelInstanceUrl(methodIdentifier string) (string, error) { + urlTemplate := fmt.Sprintf("{{IapBasePath}}%s:%s", fmt.Sprintf("projects/%s/iap_tunnel/zones/%s/instances/%s", u.project, u.zone, u.instance), methodIdentifier) + url, err := replaceVars(u.d, u.Config, urlTemplate) + if err != nil { + return "", err + } + return url, nil +} + func (u *IapTunnelInstanceIamUpdater) GetResourceId() string { - return fmt.Sprintf("projects/%s/iap_tunnel/zones/%s/instances/%s", u.projectNumber, u.zone, u.instance) + return fmt.Sprintf("projects/%s/iap_tunnel/zones/%s/instances/%s", u.project, u.zone, u.instance) } func (u *IapTunnelInstanceIamUpdater) GetMutexKey() string { - return fmt.Sprintf("iap-tunnel-instance-%s-%s-%s", u.projectNumber, u.zone, u.instance) + return fmt.Sprintf("iam-iap-tunnelinstance-%s", u.GetResourceId()) } func (u *IapTunnelInstanceIamUpdater) DescribeResource() string { - return fmt.Sprintf("IAP Tunnel Instance %s/%s/%s", u.projectNumber, u.zone, u.instance) -} - -func resourceManagerToIapPolicy(p *cloudresourcemanager.Policy) (*iap.Policy, error) { - out := &iap.Policy{} - err := Convert(p, out) - if err != nil { - return nil, errwrap.Wrapf("Cannot convert a resourcemanager policy to am IAP policy: {{err}}", err) - } - return out, nil -} - -func iapToResourceManagerPolicy(p *iap.Policy) (*cloudresourcemanager.Policy, error) { - out := &cloudresourcemanager.Policy{} - err := Convert(p, out) - if err != nil { - return nil, errwrap.Wrapf("Cannot convert an IAP policy to a resourcemanager policy: {{err}}", err) - } - return out, nil + return fmt.Sprintf("iap tunnelinstance %q", u.GetResourceId()) } diff --git a/google-beta/iam_iap_tunnel_instance_generated_test.go b/google-beta/iam_iap_tunnel_instance_generated_test.go new file mode 100644 index 0000000000..af8f8340fe --- /dev/null +++ b/google-beta/iam_iap_tunnel_instance_generated_test.go @@ -0,0 +1,606 @@ +// ---------------------------------------------------------------------------- +// +// *** AUTO GENERATED CODE *** AUTO GENERATED CODE *** +// +// ---------------------------------------------------------------------------- +// +// This file is automatically generated by Magic Modules and manual +// changes will be clobbered when the file is regenerated. +// +// Please read more about how to change this file in +// .github/CONTRIBUTING.md. +// +// ---------------------------------------------------------------------------- + +package google + +import ( + "fmt" + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/helper/acctest" + "github.com/hashicorp/terraform-plugin-sdk/helper/resource" +) + +func TestAccIapTunnelInstanceIamBindingGenerated(t *testing.T) { + t.Parallel() + + context := map[string]interface{}{ + "random_suffix": acctest.RandString(10), + "role": "roles/iap.tunnelResourceAccessor", + "condition_title": "expires_after_2019_12_31", + "condition_expr": `request.time < timestamp(\"2020-01-01T00:00:00Z\")`, + } + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + Steps: []resource.TestStep{ + { + Config: testAccIapTunnelInstanceIamBinding_basicGenerated(context), + }, + { + ResourceName: "google_iap_tunnel_instance_iam_binding.foo", + ImportStateId: fmt.Sprintf("projects/%s/iap_tunnel/zones/%s/instances/%s roles/iap.tunnelResourceAccessor", getTestProjectFromEnv(), getTestZoneFromEnv(), fmt.Sprintf("tf-test-tunnel%s", context["random_suffix"])), + ImportState: true, + ImportStateVerify: true, + }, + { + // Test Iam Binding update + Config: testAccIapTunnelInstanceIamBinding_updateGenerated(context), + }, + { + ResourceName: "google_iap_tunnel_instance_iam_binding.foo", + ImportStateId: fmt.Sprintf("projects/%s/iap_tunnel/zones/%s/instances/%s roles/iap.tunnelResourceAccessor", getTestProjectFromEnv(), getTestZoneFromEnv(), fmt.Sprintf("tf-test-tunnel%s", context["random_suffix"])), + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +func TestAccIapTunnelInstanceIamMemberGenerated(t *testing.T) { + t.Parallel() + + context := map[string]interface{}{ + "random_suffix": acctest.RandString(10), + "role": "roles/iap.tunnelResourceAccessor", + "condition_title": "expires_after_2019_12_31", + "condition_expr": `request.time < timestamp(\"2020-01-01T00:00:00Z\")`, + } + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + Steps: []resource.TestStep{ + { + // Test Iam Member creation (no update for member, no need to test) + Config: testAccIapTunnelInstanceIamMember_basicGenerated(context), + }, + { + ResourceName: "google_iap_tunnel_instance_iam_member.foo", + ImportStateId: fmt.Sprintf("projects/%s/iap_tunnel/zones/%s/instances/%s roles/iap.tunnelResourceAccessor user:admin@hashicorptest.com", getTestProjectFromEnv(), getTestZoneFromEnv(), fmt.Sprintf("tf-test-tunnel%s", context["random_suffix"])), + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +func TestAccIapTunnelInstanceIamPolicyGenerated(t *testing.T) { + t.Parallel() + + context := map[string]interface{}{ + "random_suffix": acctest.RandString(10), + "role": "roles/iap.tunnelResourceAccessor", + "condition_title": "expires_after_2019_12_31", + "condition_expr": `request.time < timestamp(\"2020-01-01T00:00:00Z\")`, + } + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + Steps: []resource.TestStep{ + { + Config: testAccIapTunnelInstanceIamPolicy_basicGenerated(context), + }, + { + ResourceName: "google_iap_tunnel_instance_iam_policy.foo", + ImportStateId: fmt.Sprintf("projects/%s/iap_tunnel/zones/%s/instances/%s", getTestProjectFromEnv(), getTestZoneFromEnv(), fmt.Sprintf("tf-test-tunnel%s", context["random_suffix"])), + ImportState: true, + ImportStateVerify: true, + }, + { + Config: testAccIapTunnelInstanceIamPolicy_emptyBinding(context), + }, + { + ResourceName: "google_iap_tunnel_instance_iam_policy.foo", + ImportStateId: fmt.Sprintf("projects/%s/iap_tunnel/zones/%s/instances/%s", getTestProjectFromEnv(), getTestZoneFromEnv(), fmt.Sprintf("tf-test-tunnel%s", context["random_suffix"])), + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +func TestAccIapTunnelInstanceIamBindingGenerated_withCondition(t *testing.T) { + t.Parallel() + + context := map[string]interface{}{ + "random_suffix": acctest.RandString(10), + "role": "roles/iap.tunnelResourceAccessor", + "condition_title": "expires_after_2019_12_31", + "condition_expr": `request.time < timestamp(\"2020-01-01T00:00:00Z\")`, + } + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + Steps: []resource.TestStep{ + { + Config: testAccIapTunnelInstanceIamBinding_withConditionGenerated(context), + }, + { + ResourceName: "google_iap_tunnel_instance_iam_binding.foo", + ImportStateId: fmt.Sprintf("projects/%s/iap_tunnel/zones/%s/instances/%s roles/iap.tunnelResourceAccessor %s", getTestProjectFromEnv(), getTestZoneFromEnv(), fmt.Sprintf("tf-test-tunnel%s", context["random_suffix"]), context["condition_title"]), + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +func TestAccIapTunnelInstanceIamBindingGenerated_withAndWithoutCondition(t *testing.T) { + t.Parallel() + + context := map[string]interface{}{ + "random_suffix": acctest.RandString(10), + "role": "roles/iap.tunnelResourceAccessor", + "condition_title": "expires_after_2019_12_31", + "condition_expr": `request.time < timestamp(\"2020-01-01T00:00:00Z\")`, + } + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + Steps: []resource.TestStep{ + { + Config: testAccIapTunnelInstanceIamBinding_withAndWithoutConditionGenerated(context), + }, + { + ResourceName: "google_iap_tunnel_instance_iam_binding.foo", + ImportStateId: fmt.Sprintf("projects/%s/iap_tunnel/zones/%s/instances/%s roles/iap.tunnelResourceAccessor", getTestProjectFromEnv(), getTestZoneFromEnv(), fmt.Sprintf("tf-test-tunnel%s", context["random_suffix"])), + ImportState: true, + ImportStateVerify: true, + }, + { + ResourceName: "google_iap_tunnel_instance_iam_binding.foo2", + ImportStateId: fmt.Sprintf("projects/%s/iap_tunnel/zones/%s/instances/%s roles/iap.tunnelResourceAccessor %s", getTestProjectFromEnv(), getTestZoneFromEnv(), fmt.Sprintf("tf-test-tunnel%s", context["random_suffix"]), context["condition_title"]), + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +func TestAccIapTunnelInstanceIamMemberGenerated_withCondition(t *testing.T) { + t.Parallel() + + context := map[string]interface{}{ + "random_suffix": acctest.RandString(10), + "role": "roles/iap.tunnelResourceAccessor", + "condition_title": "expires_after_2019_12_31", + "condition_expr": `request.time < timestamp(\"2020-01-01T00:00:00Z\")`, + } + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + Steps: []resource.TestStep{ + { + Config: testAccIapTunnelInstanceIamMember_withConditionGenerated(context), + }, + { + ResourceName: "google_iap_tunnel_instance_iam_member.foo", + ImportStateId: fmt.Sprintf("projects/%s/iap_tunnel/zones/%s/instances/%s roles/iap.tunnelResourceAccessor user:admin@hashicorptest.com %s", getTestProjectFromEnv(), getTestZoneFromEnv(), fmt.Sprintf("tf-test-tunnel%s", context["random_suffix"]), context["condition_title"]), + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +func TestAccIapTunnelInstanceIamMemberGenerated_withAndWithoutCondition(t *testing.T) { + t.Parallel() + + context := map[string]interface{}{ + "random_suffix": acctest.RandString(10), + "role": "roles/iap.tunnelResourceAccessor", + "condition_title": "expires_after_2019_12_31", + "condition_expr": `request.time < timestamp(\"2020-01-01T00:00:00Z\")`, + } + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + Steps: []resource.TestStep{ + { + Config: testAccIapTunnelInstanceIamMember_withAndWithoutConditionGenerated(context), + }, + { + ResourceName: "google_iap_tunnel_instance_iam_member.foo", + ImportStateId: fmt.Sprintf("projects/%s/iap_tunnel/zones/%s/instances/%s roles/iap.tunnelResourceAccessor user:admin@hashicorptest.com", getTestProjectFromEnv(), getTestZoneFromEnv(), fmt.Sprintf("tf-test-tunnel%s", context["random_suffix"])), + ImportState: true, + ImportStateVerify: true, + }, + { + ResourceName: "google_iap_tunnel_instance_iam_member.foo2", + ImportStateId: fmt.Sprintf("projects/%s/iap_tunnel/zones/%s/instances/%s roles/iap.tunnelResourceAccessor user:admin@hashicorptest.com %s", getTestProjectFromEnv(), getTestZoneFromEnv(), fmt.Sprintf("tf-test-tunnel%s", context["random_suffix"]), context["condition_title"]), + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +func TestAccIapTunnelInstanceIamPolicyGenerated_withCondition(t *testing.T) { + t.Parallel() + + context := map[string]interface{}{ + "random_suffix": acctest.RandString(10), + "role": "roles/iap.tunnelResourceAccessor", + "condition_title": "expires_after_2019_12_31", + "condition_expr": `request.time < timestamp(\"2020-01-01T00:00:00Z\")`, + } + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + Steps: []resource.TestStep{ + { + Config: testAccIapTunnelInstanceIamPolicy_withConditionGenerated(context), + }, + { + ResourceName: "google_iap_tunnel_instance_iam_policy.foo", + ImportStateId: fmt.Sprintf("projects/%s/iap_tunnel/zones/%s/instances/%s", getTestProjectFromEnv(), getTestZoneFromEnv(), fmt.Sprintf("tf-test-tunnel%s", context["random_suffix"])), + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +func testAccIapTunnelInstanceIamMember_basicGenerated(context map[string]interface{}) string { + return Nprintf(` +resource "google_compute_instance" "tunnelvm" { + name = "tf-test-tunnel%{random_suffix}" + zone = "" + machine_type = "n1-standard-1" + + boot_disk { + initialize_params { + image = "debian-cloud/debian-9" + } + } + + network_interface { + network = "default" + } +} + +resource "google_iap_tunnel_instance_iam_member" "foo" { + project = "${google_compute_instance.tunnelvm.project}" + zone = "${google_compute_instance.tunnelvm.zone}" + instance = "${google_compute_instance.tunnelvm.name}" + role = "%{role}" + member = "user:admin@hashicorptest.com" +} +`, context) +} + +func testAccIapTunnelInstanceIamPolicy_basicGenerated(context map[string]interface{}) string { + return Nprintf(` +resource "google_compute_instance" "tunnelvm" { + name = "tf-test-tunnel%{random_suffix}" + zone = "" + machine_type = "n1-standard-1" + + boot_disk { + initialize_params { + image = "debian-cloud/debian-9" + } + } + + network_interface { + network = "default" + } +} + +data "google_iam_policy" "foo" { + binding { + role = "%{role}" + members = ["user:admin@hashicorptest.com"] + } +} + +resource "google_iap_tunnel_instance_iam_policy" "foo" { + project = "${google_compute_instance.tunnelvm.project}" + zone = "${google_compute_instance.tunnelvm.zone}" + instance = "${google_compute_instance.tunnelvm.name}" + policy_data = "${data.google_iam_policy.foo.policy_data}" +} +`, context) +} + +func testAccIapTunnelInstanceIamPolicy_emptyBinding(context map[string]interface{}) string { + return Nprintf(` +resource "google_compute_instance" "tunnelvm" { + name = "tf-test-tunnel%{random_suffix}" + zone = "" + machine_type = "n1-standard-1" + + boot_disk { + initialize_params { + image = "debian-cloud/debian-9" + } + } + + network_interface { + network = "default" + } +} + +data "google_iam_policy" "foo" { +} + +resource "google_iap_tunnel_instance_iam_policy" "foo" { + project = "${google_compute_instance.tunnelvm.project}" + zone = "${google_compute_instance.tunnelvm.zone}" + instance = "${google_compute_instance.tunnelvm.name}" + policy_data = "${data.google_iam_policy.foo.policy_data}" +} +`, context) +} + +func testAccIapTunnelInstanceIamBinding_basicGenerated(context map[string]interface{}) string { + return Nprintf(` +resource "google_compute_instance" "tunnelvm" { + name = "tf-test-tunnel%{random_suffix}" + zone = "" + machine_type = "n1-standard-1" + + boot_disk { + initialize_params { + image = "debian-cloud/debian-9" + } + } + + network_interface { + network = "default" + } +} + +resource "google_iap_tunnel_instance_iam_binding" "foo" { + project = "${google_compute_instance.tunnelvm.project}" + zone = "${google_compute_instance.tunnelvm.zone}" + instance = "${google_compute_instance.tunnelvm.name}" + role = "%{role}" + members = ["user:admin@hashicorptest.com"] +} +`, context) +} + +func testAccIapTunnelInstanceIamBinding_updateGenerated(context map[string]interface{}) string { + return Nprintf(` +resource "google_compute_instance" "tunnelvm" { + name = "tf-test-tunnel%{random_suffix}" + zone = "" + machine_type = "n1-standard-1" + + boot_disk { + initialize_params { + image = "debian-cloud/debian-9" + } + } + + network_interface { + network = "default" + } +} + +resource "google_iap_tunnel_instance_iam_binding" "foo" { + project = "${google_compute_instance.tunnelvm.project}" + zone = "${google_compute_instance.tunnelvm.zone}" + instance = "${google_compute_instance.tunnelvm.name}" + role = "%{role}" + members = ["user:admin@hashicorptest.com", "user:paddy@hashicorp.com"] +} +`, context) +} + +func testAccIapTunnelInstanceIamBinding_withConditionGenerated(context map[string]interface{}) string { + return Nprintf(` +resource "google_compute_instance" "tunnelvm" { + name = "tf-test-tunnel%{random_suffix}" + zone = "" + machine_type = "n1-standard-1" + + boot_disk { + initialize_params { + image = "debian-cloud/debian-9" + } + } + + network_interface { + network = "default" + } +} + +resource "google_iap_tunnel_instance_iam_binding" "foo" { + project = "${google_compute_instance.tunnelvm.project}" + zone = "${google_compute_instance.tunnelvm.zone}" + instance = "${google_compute_instance.tunnelvm.name}" + role = "%{role}" + members = ["user:admin@hashicorptest.com"] + condition { + title = "%{condition_title}" + description = "Expiring at midnight of 2019-12-31" + expression = "%{condition_expr}" + } +} +`, context) +} + +func testAccIapTunnelInstanceIamBinding_withAndWithoutConditionGenerated(context map[string]interface{}) string { + return Nprintf(` +resource "google_compute_instance" "tunnelvm" { + name = "tf-test-tunnel%{random_suffix}" + zone = "" + machine_type = "n1-standard-1" + + boot_disk { + initialize_params { + image = "debian-cloud/debian-9" + } + } + + network_interface { + network = "default" + } +} + +resource "google_iap_tunnel_instance_iam_binding" "foo" { + project = "${google_compute_instance.tunnelvm.project}" + zone = "${google_compute_instance.tunnelvm.zone}" + instance = "${google_compute_instance.tunnelvm.name}" + role = "%{role}" + members = ["user:admin@hashicorptest.com"] +} + +resource "google_iap_tunnel_instance_iam_binding" "foo2" { + project = "${google_compute_instance.tunnelvm.project}" + zone = "${google_compute_instance.tunnelvm.zone}" + instance = "${google_compute_instance.tunnelvm.name}" + role = "%{role}" + members = ["user:admin@hashicorptest.com"] + condition { + title = "%{condition_title}" + description = "Expiring at midnight of 2019-12-31" + expression = "%{condition_expr}" + } +} +`, context) +} + +func testAccIapTunnelInstanceIamMember_withConditionGenerated(context map[string]interface{}) string { + return Nprintf(` +resource "google_compute_instance" "tunnelvm" { + name = "tf-test-tunnel%{random_suffix}" + zone = "" + machine_type = "n1-standard-1" + + boot_disk { + initialize_params { + image = "debian-cloud/debian-9" + } + } + + network_interface { + network = "default" + } +} + +resource "google_iap_tunnel_instance_iam_member" "foo" { + project = "${google_compute_instance.tunnelvm.project}" + zone = "${google_compute_instance.tunnelvm.zone}" + instance = "${google_compute_instance.tunnelvm.name}" + role = "%{role}" + member = "user:admin@hashicorptest.com" + condition { + title = "%{condition_title}" + description = "Expiring at midnight of 2019-12-31" + expression = "%{condition_expr}" + } +} +`, context) +} + +func testAccIapTunnelInstanceIamMember_withAndWithoutConditionGenerated(context map[string]interface{}) string { + return Nprintf(` +resource "google_compute_instance" "tunnelvm" { + name = "tf-test-tunnel%{random_suffix}" + zone = "" + machine_type = "n1-standard-1" + + boot_disk { + initialize_params { + image = "debian-cloud/debian-9" + } + } + + network_interface { + network = "default" + } +} + +resource "google_iap_tunnel_instance_iam_member" "foo" { + project = "${google_compute_instance.tunnelvm.project}" + zone = "${google_compute_instance.tunnelvm.zone}" + instance = "${google_compute_instance.tunnelvm.name}" + role = "%{role}" + member = "user:admin@hashicorptest.com" +} + +resource "google_iap_tunnel_instance_iam_member" "foo2" { + project = "${google_compute_instance.tunnelvm.project}" + zone = "${google_compute_instance.tunnelvm.zone}" + instance = "${google_compute_instance.tunnelvm.name}" + role = "%{role}" + member = "user:admin@hashicorptest.com" + condition { + title = "%{condition_title}" + description = "Expiring at midnight of 2019-12-31" + expression = "%{condition_expr}" + } +} +`, context) +} + +func testAccIapTunnelInstanceIamPolicy_withConditionGenerated(context map[string]interface{}) string { + return Nprintf(` +resource "google_compute_instance" "tunnelvm" { + name = "tf-test-tunnel%{random_suffix}" + zone = "" + machine_type = "n1-standard-1" + + boot_disk { + initialize_params { + image = "debian-cloud/debian-9" + } + } + + network_interface { + network = "default" + } +} + +data "google_iam_policy" "foo" { + binding { + role = "%{role}" + members = ["user:admin@hashicorptest.com"] + condition { + title = "%{condition_title}" + description = "Expiring at midnight of 2019-12-31" + expression = "%{condition_expr}" + } + } +} + +resource "google_iap_tunnel_instance_iam_policy" "foo" { + project = "${google_compute_instance.tunnelvm.project}" + zone = "${google_compute_instance.tunnelvm.zone}" + instance = "${google_compute_instance.tunnelvm.name}" + policy_data = "${data.google_iam_policy.foo.policy_data}" +} +`, context) +} diff --git a/google-beta/provider.go b/google-beta/provider.go index 03ec8924d2..5e8c6133cf 100644 --- a/google-beta/provider.go +++ b/google-beta/provider.go @@ -523,8 +523,8 @@ func Provider() terraform.ResourceProvider { } // Generated resources: 113 -// Generated IAM resources: 45 -// Total generated resources: 158 +// Generated IAM resources: 48 +// Total generated resources: 161 func ResourceMap() map[string]*schema.Resource { resourceMap, _ := ResourceMapWithErrors() return resourceMap @@ -648,6 +648,9 @@ func ResourceMapWithErrors() (map[string]*schema.Resource, error) { "google_iap_web_backend_service_iam_binding": ResourceIamBinding(IapWebBackendServiceIamSchema, IapWebBackendServiceIamUpdaterProducer, IapWebBackendServiceIdParseFunc), "google_iap_web_backend_service_iam_member": ResourceIamMember(IapWebBackendServiceIamSchema, IapWebBackendServiceIamUpdaterProducer, IapWebBackendServiceIdParseFunc), "google_iap_web_backend_service_iam_policy": ResourceIamPolicy(IapWebBackendServiceIamSchema, IapWebBackendServiceIamUpdaterProducer, IapWebBackendServiceIdParseFunc), + "google_iap_tunnel_instance_iam_binding": ResourceIamBinding(IapTunnelInstanceIamSchema, IapTunnelInstanceIamUpdaterProducer, IapTunnelInstanceIdParseFunc), + "google_iap_tunnel_instance_iam_member": ResourceIamMember(IapTunnelInstanceIamSchema, IapTunnelInstanceIamUpdaterProducer, IapTunnelInstanceIdParseFunc), + "google_iap_tunnel_instance_iam_policy": ResourceIamPolicy(IapTunnelInstanceIamSchema, IapTunnelInstanceIamUpdaterProducer, IapTunnelInstanceIdParseFunc), "google_identity_platform_default_supported_idp_config": resourceIdentityPlatformDefaultSupportedIdpConfig(), "google_identity_platform_tenant_default_supported_idp_config": resourceIdentityPlatformTenantDefaultSupportedIdpConfig(), "google_identity_platform_inbound_saml_config": resourceIdentityPlatformInboundSamlConfig(), @@ -753,9 +756,6 @@ func ResourceMapWithErrors() (map[string]*schema.Resource, error) { "google_healthcare_hl7_v2_store_iam_binding": ResourceIamBindingWithBatching(IamHealthcareHl7V2StoreSchema, NewHealthcareHl7V2StoreIamUpdater, Hl7V2StoreIdParseFunc, IamBatchingEnabled), "google_healthcare_hl7_v2_store_iam_member": ResourceIamMemberWithBatching(IamHealthcareHl7V2StoreSchema, NewHealthcareHl7V2StoreIamUpdater, Hl7V2StoreIdParseFunc, IamBatchingEnabled), "google_healthcare_hl7_v2_store_iam_policy": ResourceIamPolicy(IamHealthcareHl7V2StoreSchema, NewHealthcareHl7V2StoreIamUpdater, Hl7V2StoreIdParseFunc), - "google_iap_tunnel_instance_iam_binding": ResourceIamBinding(IamIapTunnelInstanceSchema, NewIapTunnelInstanceIamUpdater, IapTunnelInstanceIdParseFunc), - "google_iap_tunnel_instance_iam_member": ResourceIamMember(IamIapTunnelInstanceSchema, NewIapTunnelInstanceIamUpdater, IapTunnelInstanceIdParseFunc), - "google_iap_tunnel_instance_iam_policy": ResourceIamPolicy(IamIapTunnelInstanceSchema, NewIapTunnelInstanceIamUpdater, IapTunnelInstanceIdParseFunc), "google_logging_billing_account_sink": resourceLoggingBillingAccountSink(), "google_logging_billing_account_exclusion": ResourceLoggingExclusion(BillingAccountLoggingExclusionSchema, NewBillingAccountLoggingExclusionUpdater, billingAccountLoggingExclusionIdParseFunc), "google_logging_organization_sink": resourceLoggingOrganizationSink(), diff --git a/google-beta/resource_iap_tunnel_instance_iam_test.go b/google-beta/resource_iap_tunnel_instance_iam_test.go deleted file mode 100644 index e659545f97..0000000000 --- a/google-beta/resource_iap_tunnel_instance_iam_test.go +++ /dev/null @@ -1,218 +0,0 @@ -package google - -import ( - "fmt" - "testing" - - "github.com/hashicorp/terraform-plugin-sdk/helper/acctest" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" -) - -func TestAccIapTunnelInstanceIamBinding(t *testing.T) { - t.Parallel() - - project := getTestProjectFromEnv() - zone := getTestZoneFromEnv() - instanceName := fmt.Sprintf("tf-test-instance-%s", acctest.RandString(10)) - - resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - Steps: []resource.TestStep{ - { - Config: testAccIapTunnelInstanceIamBinding_basic(zone, instanceName), - }, - { - ResourceName: "google_iap_tunnel_instance_iam_binding.foo", - ImportStateId: fmt.Sprintf("%s/%s/%s roles/iap.tunnelResourceAccessor", project, zone, instanceName), - ImportState: true, - ImportStateVerify: true, - }, - { - // Test Iam Binding update - Config: testAccIapTunnelInstanceIamBinding_update(zone, instanceName), - }, - { - ResourceName: "google_iap_tunnel_instance_iam_binding.foo", - ImportStateId: fmt.Sprintf("%s/%s/%s roles/iap.tunnelResourceAccessor", project, zone, instanceName), - ImportState: true, - ImportStateVerify: true, - }, - }, - }) -} - -func TestAccIapTunnelInstanceIamMember(t *testing.T) { - t.Parallel() - - project := getTestProjectFromEnv() - zone := getTestZoneFromEnv() - instanceName := fmt.Sprintf("tf-test-instance-%s", acctest.RandString(10)) - - resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - Steps: []resource.TestStep{ - { - // Test Iam Member creation (no update for member, no need to test) - Config: testAccIapTunnelInstanceIamMember_basic(zone, instanceName), - }, - { - ResourceName: "google_iap_tunnel_instance_iam_member.foo", - ImportStateId: fmt.Sprintf("%s/%s/%s roles/iap.tunnelResourceAccessor user:admin@hashicorptest.com", project, zone, instanceName), - ImportState: true, - ImportStateVerify: true, - }, - }, - }) -} - -func TestAccIapTunnelInstanceIamPolicy(t *testing.T) { - t.Parallel() - - project := getTestProjectFromEnv() - zone := getTestZoneFromEnv() - instanceName := fmt.Sprintf("tf-test-instance-%s", acctest.RandString(10)) - - resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - Steps: []resource.TestStep{ - { - Config: testAccIapTunnelInstanceIamPolicy_basic(zone, instanceName), - }, - // Test a few import formats - { - ResourceName: "google_iap_tunnel_instance_iam_policy.foo", - ImportStateId: fmt.Sprintf("projects/%s/zones/%s/instances/%s", project, zone, instanceName), - ImportState: true, - ImportStateVerify: true, - }, - { - ResourceName: "google_iap_tunnel_instance_iam_policy.foo", - ImportStateId: fmt.Sprintf("%s/%s/%s", project, zone, instanceName), - ImportState: true, - ImportStateVerify: true, - }, - { - ResourceName: "google_iap_tunnel_instance_iam_policy.foo", - ImportStateId: fmt.Sprintf("%s/%s", zone, instanceName), - ImportState: true, - ImportStateVerify: true, - }, - }, - }) -} - -func testAccIapTunnelInstanceIamBinding_basic(zone, instanceName string) string { - return fmt.Sprintf(` -resource "google_compute_instance" "test_vm" { - zone = "%s" - name = "%s" - machine_type = "n1-standard-1" - boot_disk { - initialize_params { - image = "debian-cloud/debian-9" - } - } - network_interface { - network = "default" - } -} - -resource "google_iap_tunnel_instance_iam_binding" "foo" { - project = google_compute_instance.test_vm.project - zone = google_compute_instance.test_vm.zone - instance = google_compute_instance.test_vm.name - role = "roles/iap.tunnelResourceAccessor" - members = ["user:admin@hashicorptest.com"] -} -`, zone, instanceName) -} - -func testAccIapTunnelInstanceIamBinding_update(zone, instanceName string) string { - return fmt.Sprintf(` -resource "google_compute_instance" "test_vm" { - zone = "%s" - name = "%s" - machine_type = "n1-standard-1" - boot_disk { - initialize_params { - image = "debian-cloud/debian-9" - } - } - network_interface { - network = "default" - } -} - -resource "google_iap_tunnel_instance_iam_binding" "foo" { - project = google_compute_instance.test_vm.project - zone = google_compute_instance.test_vm.zone - instance = google_compute_instance.test_vm.name - role = "roles/iap.tunnelResourceAccessor" - members = [ - "user:admin@hashicorptest.com", - "user:paddy@hashicorp.com", - ] -} -`, zone, instanceName) -} - -func testAccIapTunnelInstanceIamMember_basic(zone, instanceName string) string { - return fmt.Sprintf(` -resource "google_compute_instance" "test_vm" { - zone = "%s" - name = "%s" - machine_type = "n1-standard-1" - boot_disk { - initialize_params { - image = "debian-cloud/debian-9" - } - } - network_interface { - network = "default" - } -} - -resource "google_iap_tunnel_instance_iam_member" "foo" { - project = google_compute_instance.test_vm.project - zone = google_compute_instance.test_vm.zone - instance = google_compute_instance.test_vm.name - role = "roles/iap.tunnelResourceAccessor" - member = "user:admin@hashicorptest.com" -} -`, zone, instanceName) -} - -func testAccIapTunnelInstanceIamPolicy_basic(zone, instanceName string) string { - return fmt.Sprintf(` -resource "google_compute_instance" "test_vm" { - zone = "%s" - name = "%s" - machine_type = "n1-standard-1" - boot_disk { - initialize_params { - image = "debian-cloud/debian-9" - } - } - network_interface { - network = "default" - } -} - -data "google_iam_policy" "foo" { - binding { - role = "roles/iap.tunnelResourceAccessor" - members = ["user:admin@hashicorptest.com"] - } -} - -resource "google_iap_tunnel_instance_iam_policy" "foo" { - project = google_compute_instance.test_vm.project - zone = google_compute_instance.test_vm.zone - instance = google_compute_instance.test_vm.name - policy_data = data.google_iam_policy.foo.policy_data -} -`, zone, instanceName) -} diff --git a/google-beta/resource_storage_bucket_test.go b/google-beta/resource_storage_bucket_test.go index ce3a62c1e1..b3140f2042 100644 --- a/google-beta/resource_storage_bucket_test.go +++ b/google-beta/resource_storage_bucket_test.go @@ -5,6 +5,7 @@ import ( "fmt" "log" "regexp" + "strings" "testing" "time" @@ -850,7 +851,10 @@ func TestAccStorageBucket_website(t *testing.T) { t.Parallel() bucketSuffix := acctest.RandomWithPrefix("tf-website-test") - errRe := regexp.MustCompile("one of `((website.0.main_page_suffix,website.0.not_found_page)|(website.0.not_found_page,website.0.main_page_suffix))` must be specified") + + websiteKeys := []string{"website.0.main_page_suffix", "website.0.not_found_page"} + errMsg := fmt.Sprintf("one of `%s` must be specified", strings.Join(websiteKeys, ",")) + fullErr := fmt.Sprintf("config is invalid: 2 problems:\n\n- \"%s\": %s\n- \"%s\": %s", websiteKeys[0], errMsg, websiteKeys[1], errMsg) resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, @@ -859,7 +863,7 @@ func TestAccStorageBucket_website(t *testing.T) { Steps: []resource.TestStep{ { Config: testAccStorageBucket_websiteNoAttributes(bucketSuffix), - ExpectError: errRe, + ExpectError: regexp.MustCompile(fullErr), }, { Config: testAccStorageBucket_websiteOneAttribute(bucketSuffix), diff --git a/website/docs/r/google_iap_tunnel_instance_iam.html.markdown b/website/docs/r/google_iap_tunnel_instance_iam.html.markdown deleted file mode 100644 index d4fa33c284..0000000000 --- a/website/docs/r/google_iap_tunnel_instance_iam.html.markdown +++ /dev/null @@ -1,127 +0,0 @@ ---- -layout: "google" -subcategory: "Identity-Aware Proxy" -page_title: "Google: google_iap_tunnel_instance_iam" -sidebar_current: "docs-google-iap-tunnel-instance-iam" -description: |- - Collection of resources to manage IAM policy for a IAP Tunnel Instance. ---- - -# IAM policy for IAP Tunnel Instance - -~> **Warning:** These resources are 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. - -Three different resources help you manage your IAM policy for IAP Tunnel Instance. Each of these resources serves a different use case: - -* `google_iap_tunnel_instance_iam_policy`: Authoritative. Sets the IAM policy for the instance and replaces any existing policy already attached. -* `google_iap_tunnel_instance_iam_binding`: Authoritative for a given role. Updates the IAM policy to grant a role to a list of members. Other roles within the IAM policy for the instance are preserved. -* `google_iap_tunnel_instance_iam_member`: Non-authoritative. Updates the IAM policy to grant a role to a new member. Other members for the role for the instance are preserved. - -~> **Note:** `google_iap_tunnel_instance_iam_policy` **cannot** be used in conjunction with `google_iap_tunnel_instance_iam_binding` and `google_iap_tunnel_instance_iam_member` or they will fight over what your policy should be. - -~> **Note:** `google_iap_tunnel_instance_iam_binding` resources **can be** used in conjunction with `google_iap_tunnel_instance_iam_member` resources **only if** they do not grant privilege to the same role. - -## google\_iap\_tunnel\_instance\_iam\_policy - -```hcl -data "google_iam_policy" "admin" { - binding { - role = "roles/editor" - - members = [ - "user:jane@example.com", - ] - } -} - -resource "google_iap_tunnel_instance_iam_policy" "instance" { - instance = "your-instance-name" - policy_data = "${data.google_iam_policy.admin.policy_data}" -} -``` - -## google\_iap\_tunnel\_instance\_iam\_binding - -```hcl -resource "google_iap_tunnel_instance_iam_binding" "instance" { - instance = "your-instance-name" - role = "roles/compute.networkUser" - - members = [ - "user:jane@example.com", - ] -} -``` - -## google\_iap\_tunnel\_instance\_iam\_member - -```hcl -resource "google_iap_tunnel_instance_iam_member" "instance" { - instance = "your-instance-name" - role = "roles/compute.networkUser" - member = "user:jane@example.com" -} -``` - -## Argument Reference - -The following arguments are supported: - -* `instance` - (Required) The name of the instance. - -* `member/members` - (Required) Identities that will be granted the privilege in `role`. - Each entry can have one of the following values: - * **allUsers**: A special identifier that represents anyone who is on the internet; with or without a Google account. - * **allAuthenticatedUsers**: A special identifier that represents anyone who is authenticated with a Google account or a service account. - * **user:{emailid}**: An email address that represents a specific Google account. For example, alice@gmail.com or joe@example.com. - * **serviceAccount:{emailid}**: An email address that represents a service account. For example, my-other-app@appspot.gserviceaccount.com. - * **group:{emailid}**: An email address that represents a Google group. For example, admins@example.com. - * **domain:{domain}**: A G Suite domain (primary, instead of alias) name that represents all the users of that domain. For example, google.com or example.com. - -* `role` - (Required) The role that should be applied. Only one - `google_iap_tunnel_instance_iam_binding` can be used per role. Note that custom roles must be of the format - `[projects|organizations]/{parent-name}/roles/{role-name}`. - -* `policy_data` - (Required only by `google_iap_tunnel_instance_iam_policy`) The policy data generated by - a `google_iam_policy` data source. - -* `project` - (Optional) The ID of the project in which the resource belongs. If it - is not provided, the provider project is used. - -* `zone` - (Optional) The zone of the instance. If - unspecified, this defaults to the zone configured in the provider. - -## Attributes Reference - -In addition to the arguments listed above, the following computed attributes are -exported: - -* `etag` - (Computed) The etag of the instance's IAM policy. - -## Import - -For all import syntaxes, the "resource in question" can take any of the following forms: - -* full self link or relative link (projects/{{project}}/zones/{{zone}}/instances/{{name}}) -* {{project}}/{{zone}}/{{name}} -* {{zone}}/{{name}} (project is taken from provider project) -* {{name}} (project and zone are taken from provider project) - -IAM member imports use space-delimited identifiers; the resource in question, the role, and the member identity, e.g. - -``` -$ terraform import google_iap_tunnel_instance_iam_member.instance "project-name/zone-name/instance-name roles/compute.networkUser user:foo@example.com" -``` - -IAM binding imports use space-delimited identifiers; the resource in question and the role, e.g. - -``` -$ terraform import google_iap_tunnel_instance_iam_binding.instance "project-name/zone-name/instance-name roles/compute.networkUser" -``` - -IAM policy imports use the identifier of the resource in question, e.g. - -``` -$ terraform import google_iap_tunnel_instance_iam_policy.instance project-name/zone-name/instance-name -``` diff --git a/website/docs/r/iap_tunnel_instance_iam.html.markdown b/website/docs/r/iap_tunnel_instance_iam.html.markdown new file mode 100644 index 0000000000..8f7680d2c1 --- /dev/null +++ b/website/docs/r/iap_tunnel_instance_iam.html.markdown @@ -0,0 +1,228 @@ +--- +# ---------------------------------------------------------------------------- +# +# *** AUTO GENERATED CODE *** AUTO GENERATED CODE *** +# +# ---------------------------------------------------------------------------- +# +# This file is automatically generated by Magic Modules and manual +# changes will be clobbered when the file is regenerated. +# +# Please read more about how to change this file in +# .github/CONTRIBUTING.md. +# +# ---------------------------------------------------------------------------- +subcategory: "Identity-Aware Proxy" +layout: "google" +page_title: "Google: google_iap_tunnel_instance_iam" +sidebar_current: "docs-google-iap-tunnel-instance-iam" +description: |- + Collection of resources to manage IAM policy for IapTunnelInstance +--- + +# IAM policy for IapTunnelInstance +Three different resources help you manage your IAM policy for Iap TunnelInstance. Each of these resources serves a different use case: + +* `google_iap_tunnel_instance_iam_policy`: Authoritative. Sets the IAM policy for the tunnelinstance and replaces any existing policy already attached. +* `google_iap_tunnel_instance_iam_binding`: Authoritative for a given role. Updates the IAM policy to grant a role to a list of members. Other roles within the IAM policy for the tunnelinstance are preserved. +* `google_iap_tunnel_instance_iam_member`: Non-authoritative. Updates the IAM policy to grant a role to a new member. Other members for the role for the tunnelinstance are preserved. + +~> **Note:** `google_iap_tunnel_instance_iam_policy` **cannot** be used in conjunction with `google_iap_tunnel_instance_iam_binding` and `google_iap_tunnel_instance_iam_member` or they will fight over what your policy should be. + +~> **Note:** `google_iap_tunnel_instance_iam_binding` resources **can be** used in conjunction with `google_iap_tunnel_instance_iam_member` resources **only if** they do not grant privilege to the same role. + + + +## google\_iap\_tunnel\_instance\_iam\_policy + +```hcl +data "google_iam_policy" "admin" { + binding { + role = "roles/iap.tunnelResourceAccessor" + members = [ + "user:jane@example.com", + ] + } +} + +resource "google_iap_tunnel_instance_iam_policy" "editor" { + project = "${google_compute_instance.tunnelvm.project}" + zone = "${google_compute_instance.tunnelvm.zone}" + instance = "${google_compute_instance.tunnelvm.name}" + policy_data = "${data.google_iam_policy.admin.policy_data}" +} +``` + +With IAM Conditions ([beta](https://terraform.io/docs/providers/google/provider_versions.html)): + +```hcl +data "google_iam_policy" "admin" { + binding { + role = "roles/iap.tunnelResourceAccessor" + members = [ + "user:jane@example.com", + ] + + condition { + title = "expires_after_2019_12_31" + description = "Expiring at midnight of 2019-12-31" + expression = "request.time < timestamp(\"2020-01-01T00:00:00Z\")" + } + } +} + +resource "google_iap_tunnel_instance_iam_policy" "editor" { + project = "${google_compute_instance.tunnelvm.project}" + zone = "${google_compute_instance.tunnelvm.zone}" + instance = "${google_compute_instance.tunnelvm.name}" + policy_data = "${data.google_iam_policy.admin.policy_data}" +} +``` +## google\_iap\_tunnel\_instance\_iam\_binding + +```hcl +resource "google_iap_tunnel_instance_iam_binding" "editor" { + project = "${google_compute_instance.tunnelvm.project}" + zone = "${google_compute_instance.tunnelvm.zone}" + instance = "${google_compute_instance.tunnelvm.name}" + role = "roles/iap.tunnelResourceAccessor" + members = [ + "user:jane@example.com", + ] +} +``` + +With IAM Conditions ([beta](https://terraform.io/docs/providers/google/provider_versions.html)): + +```hcl +resource "google_iap_tunnel_instance_iam_binding" "editor" { + project = "${google_compute_instance.tunnelvm.project}" + zone = "${google_compute_instance.tunnelvm.zone}" + instance = "${google_compute_instance.tunnelvm.name}" + role = "roles/iap.tunnelResourceAccessor" + members = [ + "user:jane@example.com", + ] + + condition { + title = "expires_after_2019_12_31" + description = "Expiring at midnight of 2019-12-31" + expression = "request.time < timestamp(\"2020-01-01T00:00:00Z\")" + } +} +``` +## google\_iap\_tunnel\_instance\_iam\_member + +```hcl +resource "google_iap_tunnel_instance_iam_member" "editor" { + project = "${google_compute_instance.tunnelvm.project}" + zone = "${google_compute_instance.tunnelvm.zone}" + instance = "${google_compute_instance.tunnelvm.name}" + role = "roles/iap.tunnelResourceAccessor" + member = "user:jane@example.com" +} +``` + +With IAM Conditions ([beta](https://terraform.io/docs/providers/google/provider_versions.html)): + +```hcl +resource "google_iap_tunnel_instance_iam_member" "editor" { + project = "${google_compute_instance.tunnelvm.project}" + zone = "${google_compute_instance.tunnelvm.zone}" + instance = "${google_compute_instance.tunnelvm.name}" + role = "roles/iap.tunnelResourceAccessor" + member = "user:jane@example.com" + + condition { + title = "expires_after_2019_12_31" + description = "Expiring at midnight of 2019-12-31" + expression = "request.time < timestamp(\"2020-01-01T00:00:00Z\")" + } +} +``` +## Argument Reference + +The following arguments are supported: + +* `instance` - (Required) Used to find the parent resource to bind the IAM policy to + +* `project` - (Optional) The ID of the project in which the resource belongs. + If it is not provided, the project will be parsed from the identifier of the parent resource. If no project is provided in the parent identifier and no project is specified, the provider project is used. + +* `member/members` - (Required) Identities that will be granted the privilege in `role`. + Each entry can have one of the following values: + * **allUsers**: A special identifier that represents anyone who is on the internet; with or without a Google account. + * **allAuthenticatedUsers**: A special identifier that represents anyone who is authenticated with a Google account or a service account. + * **user:{emailid}**: An email address that represents a specific Google account. For example, alice@gmail.com or joe@example.com. + * **serviceAccount:{emailid}**: An email address that represents a service account. For example, my-other-app@appspot.gserviceaccount.com. + * **group:{emailid}**: An email address that represents a Google group. For example, admins@example.com. + * **domain:{domain}**: A G Suite domain (primary, instead of alias) name that represents all the users of that domain. For example, google.com or example.com. + +* `role` - (Required) The role that should be applied. Only one + `google_iap_tunnel_instance_iam_binding` can be used per role. Note that custom roles must be of the format + `[projects|organizations]/{parent-name}/roles/{role-name}`. + +* `policy_data` - (Required only by `google_iap_tunnel_instance_iam_policy`) The policy data generated by + a `google_iam_policy` data source. + +* `condition` - (Optional, [Beta](https://terraform.io/docs/providers/google/provider_versions.html)) An [IAM Condition](https://cloud.google.com/iam/docs/conditions-overview) for a given binding. + Structure is documented below. + +--- + +The `condition` block supports: + +* `expression` - (Required) Textual representation of an expression in Common Expression Language syntax. + +* `title` - (Required) A title for the expression, i.e. a short string describing its purpose. + +* `description` - (Optional) An optional description of the expression. This is a longer text which describes the expression, e.g. when hovered over it in a UI. + +~> **Warning:** Terraform considers the `role` and condition contents (`title`+`description`+`expression`) as the + identifier for the binding. This means that if any part of the condition is changed out-of-band, Terraform will + consider it to be an entirely different resource and will treat it as such. +## Attributes Reference + +In addition to the arguments listed above, the following computed attributes are +exported: + +* `etag` - (Computed) The etag of the IAM policy. + +## Import + +For all import syntaxes, the "resource in question" can take any of the following forms: + +* projects/{{project}}/iap_tunnel/zones/{{zone}}/instances/{{name}} +* projects/{{project}}/zones/{{zone}}/instances/{{name}} +* {{project}}/{{zone}}/{{name}} +* {{zone}}/{{name}} +* {{name}} + +Any variables not passed in the import command will be taken from the provider configuration. + +Iap tunnelinstance IAM resources can be imported using the resource identifiers, role, and member. + +IAM member imports use space-delimited identifiers: the resource in question, the role, and the member identity, e.g. +``` +$ terraform import google_iap_tunnel_instance_iam_member.editor "projects/{{project}}/iap_tunnel/zones/{{zone}}/instances/{{tunnel_instance}} roles/iap.tunnelResourceAccessor jane@example.com" +``` + +IAM binding imports use space-delimited identifiers: the resource in question and the role, e.g. +``` +$ terraform import google_iap_tunnel_instance_iam_binding.editor "projects/{{project}}/iap_tunnel/zones/{{zone}}/instances/{{tunnel_instance}} roles/iap.tunnelResourceAccessor" +``` + +IAM policy imports use the identifier of the resource in question, e.g. +``` +$ terraform import google_iap_tunnel_instance_iam_policy.editor projects/{{project}}/iap_tunnel/zones/{{zone}}/instances/{{tunnel_instance}} +``` + +-> If you're importing a resource with beta features, make sure to include `-provider=google-beta` +as an argument so that Terraform uses the correct provider to import your resource. + +-> **Custom Roles**: If you're importing a IAM resource with a custom role, make sure to use the + full name of the custom role, e.g. `[projects/my-project|organizations/my-org]/roles/my-custom-role`. + +## User Project Overrides + +This resource supports [User Project Overrides](https://www.terraform.io/docs/providers/google/guides/provider_reference.html#user_project_override).