Skip to content

Added IAP Enable/Disable flag in cloudrunv2 service. #9758

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changelog/13575.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
cloudrunv2: added `iapEnabled` field to `mmv1/products/cloudrunv2/Service.yaml` resource
```
Original file line number Diff line number Diff line change
Expand Up @@ -924,6 +924,11 @@ For more information, see https://cloud.google.com/run/docs/configuring/custom-a
Optional: true,
Description: `User-provided description of the Service. This field currently has a 512-character limit.`,
},
"iap_enabled": {
Type: schema.TypeBool,
Optional: true,
Description: `Used to enable/disable IAP for the service.`,
},
"ingress": {
Type: schema.TypeString,
Computed: true,
Expand Down Expand Up @@ -1399,6 +1404,12 @@ func resourceCloudRunV2ServiceCreate(d *schema.ResourceData, meta interface{}) e
} else if v, ok := d.GetOkExists("build_config"); !tpgresource.IsEmptyValue(reflect.ValueOf(buildConfigProp)) && (ok || !reflect.DeepEqual(v, buildConfigProp)) {
obj["buildConfig"] = buildConfigProp
}
iapEnabledProp, err := expandCloudRunV2ServiceIapEnabled(d.Get("iap_enabled"), d, config)
if err != nil {
return err
} else if v, ok := d.GetOkExists("iap_enabled"); !tpgresource.IsEmptyValue(reflect.ValueOf(iapEnabledProp)) && (ok || !reflect.DeepEqual(v, iapEnabledProp)) {
obj["iapEnabled"] = iapEnabledProp
}
labelsProp, err := expandCloudRunV2ServiceEffectiveLabels(d.Get("effective_labels"), d, config)
if err != nil {
return err
Expand Down Expand Up @@ -1622,6 +1633,9 @@ func resourceCloudRunV2ServiceRead(d *schema.ResourceData, meta interface{}) err
if err := d.Set("etag", flattenCloudRunV2ServiceEtag(res["etag"], d, config)); err != nil {
return fmt.Errorf("Error reading Service: %s", err)
}
if err := d.Set("iap_enabled", flattenCloudRunV2ServiceIapEnabled(res["iapEnabled"], d, config)); err != nil {
return fmt.Errorf("Error reading Service: %s", err)
}
if err := d.Set("terraform_labels", flattenCloudRunV2ServiceTerraformLabels(res["labels"], d, config)); err != nil {
return fmt.Errorf("Error reading Service: %s", err)
}
Expand Down Expand Up @@ -1729,6 +1743,12 @@ func resourceCloudRunV2ServiceUpdate(d *schema.ResourceData, meta interface{}) e
} else if v, ok := d.GetOkExists("build_config"); !tpgresource.IsEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, buildConfigProp)) {
obj["buildConfig"] = buildConfigProp
}
iapEnabledProp, err := expandCloudRunV2ServiceIapEnabled(d.Get("iap_enabled"), d, config)
if err != nil {
return err
} else if v, ok := d.GetOkExists("iap_enabled"); !tpgresource.IsEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, iapEnabledProp)) {
obj["iapEnabled"] = iapEnabledProp
}
labelsProp, err := expandCloudRunV2ServiceEffectiveLabels(d.Get("effective_labels"), d, config)
if err != nil {
return err
Expand Down Expand Up @@ -3456,6 +3476,10 @@ func flattenCloudRunV2ServiceEtag(v interface{}, d *schema.ResourceData, config
return v
}

func flattenCloudRunV2ServiceIapEnabled(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
return v
}

func flattenCloudRunV2ServiceTerraformLabels(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
if v == nil {
return v
Expand Down Expand Up @@ -5249,6 +5273,10 @@ func expandCloudRunV2ServiceBuildConfigServiceAccount(v interface{}, d tpgresour
return v, nil
}

func expandCloudRunV2ServiceIapEnabled(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
return v, nil
}

func expandCloudRunV2ServiceEffectiveLabels(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (map[string]string, error) {
if v == nil {
return map[string]string{}, nil
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ fields:
- field: 'etag'
- field: 'expire_time'
- field: 'generation'
- field: 'iap_enabled'
- field: 'ingress'
- field: 'invoker_iam_disabled'
- field: 'labels'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -949,6 +949,51 @@ resource "google_project_iam_member" "logs_writer" {
`, context)
}

func TestAccCloudRunV2Service_cloudrunv2ServiceIapExample(t *testing.T) {
t.Parallel()

context := map[string]interface{}{
"random_suffix": acctest.RandString(t, 10),
}

acctest.VcrTest(t, resource.TestCase{
PreCheck: func() { acctest.AccTestPreCheck(t) },
ProtoV5ProviderFactories: acctest.ProtoV5ProviderBetaFactories(t),
CheckDestroy: testAccCheckCloudRunV2ServiceDestroyProducer(t),
Steps: []resource.TestStep{
{
Config: testAccCloudRunV2Service_cloudrunv2ServiceIapExample(context),
},
{
ResourceName: "google_cloud_run_v2_service.default",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"annotations", "deletion_protection", "labels", "location", "name", "terraform_labels"},
},
},
})
}

func testAccCloudRunV2Service_cloudrunv2ServiceIapExample(context map[string]interface{}) string {
return acctest.Nprintf(`
resource "google_cloud_run_v2_service" "default" {
provider = google-beta
name = "tf-test-cloudrun-iap-service%{random_suffix}"
location = "us-central1"
deletion_protection = false
ingress = "INGRESS_TRAFFIC_ALL"
launch_stage = "BETA"
iap_enabled = true

template {
containers {
image = "us-docker.pkg.dev/cloudrun/container/hello"
}
}
}
`, context)
}

func testAccCheckCloudRunV2ServiceDestroyProducer(t *testing.T) func(s *terraform.State) error {
return func(s *terraform.State) error {
for name, rs := range s.RootModule().Resources {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1548,3 +1548,76 @@ resource "google_project_iam_member" "logs_writer" {
}
`, context)
}

func TestAccCloudRunV2Service_cloudrunv2ServiceIapUpdate(t *testing.T) {
t.Parallel()

context := map[string]interface{}{
"random_suffix": acctest.RandString(t, 10),
}

acctest.VcrTest(t, resource.TestCase{
PreCheck: func() { acctest.AccTestPreCheck(t) },
ProtoV5ProviderFactories: acctest.ProtoV5ProviderBetaFactories(t),
CheckDestroy: testAccCheckCloudRunV2ServiceDestroyProducer(t),
Steps: []resource.TestStep{
{
Config: testAccCloudRunV2Service_cloudrunv2ServiceIap(context),
},
{
ResourceName: "google_cloud_run_v2_service.default",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"annotations", "deletion_protection", "labels", "location", "name", "terraform_labels"},
},
{
Config: testAccCloudRunV2Service_cloudrunv2ServiceIapUpdate(context),
},
{
ResourceName: "google_cloud_run_v2_service.default",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"annotations", "deletion_protection", "labels", "location", "name", "terraform_labels"},
},
},
})
}

func testAccCloudRunV2Service_cloudrunv2ServiceIap(context map[string]interface{}) string {
return acctest.Nprintf(`
resource "google_cloud_run_v2_service" "default" {
provider = google-beta
name = "tf-test-cloudrun-iap-service%{random_suffix}"
location = "us-central1"
deletion_protection = false
ingress = "INGRESS_TRAFFIC_ALL"
launch_stage = "BETA"
iap_enabled = true

template {
containers {
image = "us-docker.pkg.dev/cloudrun/container/hello"
}
}
}
`, context)
}

func testAccCloudRunV2Service_cloudrunv2ServiceIapUpdate(context map[string]interface{}) string {
return acctest.Nprintf(`
resource "google_cloud_run_v2_service" "default" {
provider = google-beta
name = "tf-test-cloudrun-iap-service%{random_suffix}"
location = "us-central1"
deletion_protection = false
ingress = "INGRESS_TRAFFIC_ALL"
iap_enabled = false

template {
containers {
image = "us-docker.pkg.dev/cloudrun/container/hello"
}
}
}
`, context)
}
29 changes: 29 additions & 0 deletions website/docs/r/cloud_run_v2_service.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -662,6 +662,31 @@ resource "google_project_iam_member" "logs_writer" {
member = "serviceAccount:${google_service_account.cloudbuild_service_account.email}"
}
```
<div class = "oics-button" style="float: right; margin: 0 0 -15px">
<a href="https://console.cloud.google.com/cloudshell/open?cloudshell_git_repo=https%3A%2F%2Fgithub.jpy.wang%2Fterraform-google-modules%2Fdocs-examples.git&cloudshell_image=gcr.io%2Fcloudshell-images%2Fcloudshell%3Alatest&cloudshell_print=.%2Fmotd&cloudshell_tutorial=.%2Ftutorial.md&cloudshell_working_dir=cloudrunv2_service_iap&open_in_editor=main.tf" target="_blank">
<img alt="Open in Cloud Shell" src="//gstatic.com/cloudssh/images/open-btn.svg" style="max-height: 44px; margin: 32px auto; max-width: 100%;">
</a>
</div>
## Example Usage - Cloudrunv2 Service Iap


```hcl
resource "google_cloud_run_v2_service" "default" {
provider = google-beta
name = "cloudrun-iap-service"
location = "us-central1"
deletion_protection = false
ingress = "INGRESS_TRAFFIC_ALL"
launch_stage = "BETA"
iap_enabled = true

template {
containers {
image = "us-docker.pkg.dev/cloudrun/container/hello"
}
}
}
```

## Argument Reference

Expand Down Expand Up @@ -1318,6 +1343,10 @@ The following arguments are supported:
Configuration for building a Cloud Run function.
Structure is [documented below](#nested_build_config).

* `iap_enabled` -
(Optional, [Beta](https://terraform.io/docs/providers/google/guides/provider_versions.html))
Used to enable/disable IAP for the service.

* `project` - (Optional) The ID of the project in which the resource belongs.
If it is not provided, the provider project is used.

Expand Down