Skip to content

Commit

Permalink
Remove sending empty oauth2ClientId and oauth2ClientSecret string for…
Browse files Browse the repository at this point in the history
… null IAP message in google_compute_region_backend_service (#9851) (#6886)

* Remove default addition of oauth2ClientId and oauth2ClientSecret in google_compute_region_backend_service

* Remove default addition of oauth2ClientId and oauth2ClientSecret in google_compute_backend_service
[upstream:682308da6494c7cd4b1a045615b2e37474ef303a]

Signed-off-by: Modular Magician <[email protected]>
  • Loading branch information
modular-magician authored Jan 22, 2024
1 parent ec99f1c commit d34625e
Show file tree
Hide file tree
Showing 7 changed files with 122 additions and 4 deletions.
4 changes: 4 additions & 0 deletions .changelog/9851.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
```release-note:bug
compute: remove sending empty oauth2ClientId and oauth2ClientSecret string for null IAP message in google_compute_region_backend_service as it triggers resource validation

```
Original file line number Diff line number Diff line change
Expand Up @@ -4398,8 +4398,6 @@ func resourceComputeBackendServiceEncoder(d *schema.ResourceData, meta interface
if iapVal == nil {
data := map[string]interface{}{}
data["enabled"] = false
data["oauth2ClientId"] = ""
data["oauth2ClientSecret"] = ""
obj["iap"] = data
} else {
iap := iapVal.(map[string]interface{})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,45 @@ resource "google_compute_http_health_check" "default" {
`, context)
}

func TestAccComputeBackendService_backendServiceExternalIapExample(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.ProtoV5ProviderFactories(t),
CheckDestroy: testAccCheckComputeBackendServiceDestroyProducer(t),
Steps: []resource.TestStep{
{
Config: testAccComputeBackendService_backendServiceExternalIapExample(context),
},
{
ResourceName: "google_compute_backend_service.default",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"iap.0.oauth2_client_secret"},
},
},
})
}

func testAccComputeBackendService_backendServiceExternalIapExample(context map[string]interface{}) string {
return acctest.Nprintf(`
resource "google_compute_backend_service" "default" {
name = "tf-test-tf-test-backend-service-external%{random_suffix}"
protocol = "HTTP"
load_balancing_scheme = "EXTERNAL"
iap {
oauth2_client_id = "abc"
oauth2_client_secret = "xyz"
}
}
`, context)
}

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4184,8 +4184,6 @@ func resourceComputeRegionBackendServiceEncoder(d *schema.ResourceData, meta int
if iapVal == nil {
data := map[string]interface{}{}
data["enabled"] = false
data["oauth2ClientId"] = ""
data["oauth2ClientSecret"] = ""
obj["iap"] = data
} else {
iap := iapVal.(map[string]interface{})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,46 @@ resource "google_compute_health_check" "default" {
`, context)
}

func TestAccComputeRegionBackendService_regionBackendServiceExternalIapExample(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.ProtoV5ProviderFactories(t),
CheckDestroy: testAccCheckComputeRegionBackendServiceDestroyProducer(t),
Steps: []resource.TestStep{
{
Config: testAccComputeRegionBackendService_regionBackendServiceExternalIapExample(context),
},
{
ResourceName: "google_compute_region_backend_service.default",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"network", "region", "iap.0.oauth2_client_secret"},
},
},
})
}

func testAccComputeRegionBackendService_regionBackendServiceExternalIapExample(context map[string]interface{}) string {
return acctest.Nprintf(`
resource "google_compute_region_backend_service" "default" {
name = "tf-test-tf-test-region-service-external%{random_suffix}"
region = "us-central1"
protocol = "HTTP"
load_balancing_scheme = "EXTERNAL"
iap {
oauth2_client_id = "abc"
oauth2_client_secret = "xyz"
}
}
`, context)
}

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

Expand Down
19 changes: 19 additions & 0 deletions website/docs/r/compute_backend_service.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,25 @@ resource "google_compute_http_health_check" "default" {
timeout_sec = 1
}
```
<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.com%2Fterraform-google-modules%2Fdocs-examples.git&cloudshell_working_dir=backend_service_external_iap&cloudshell_image=gcr.io%2Fcloudshell-images%2Fcloudshell%3Alatest&open_in_editor=main.tf&cloudshell_print=.%2Fmotd&cloudshell_tutorial=.%2Ftutorial.md" 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 - Backend Service External Iap


```hcl
resource "google_compute_backend_service" "default" {
name = "tf-test-backend-service-external"
protocol = "HTTP"
load_balancing_scheme = "EXTERNAL"
iap {
oauth2_client_id = "abc"
oauth2_client_secret = "xyz"
}
}
```
<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.com%2Fterraform-google-modules%2Fdocs-examples.git&cloudshell_working_dir=backend_service_cache_simple&cloudshell_image=gcr.io%2Fcloudshell-images%2Fcloudshell%3Alatest&open_in_editor=main.tf&cloudshell_print=.%2Fmotd&cloudshell_tutorial=.%2Ftutorial.md" 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%;">
Expand Down
20 changes: 20 additions & 0 deletions website/docs/r/compute_region_backend_service.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,26 @@ resource "google_compute_health_check" "default" {
}
}
```
<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.com%2Fterraform-google-modules%2Fdocs-examples.git&cloudshell_working_dir=region_backend_service_external_iap&cloudshell_image=gcr.io%2Fcloudshell-images%2Fcloudshell%3Alatest&open_in_editor=main.tf&cloudshell_print=.%2Fmotd&cloudshell_tutorial=.%2Ftutorial.md" 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 - Region Backend Service External Iap


```hcl
resource "google_compute_region_backend_service" "default" {
name = "tf-test-region-service-external"
region = "us-central1"
protocol = "HTTP"
load_balancing_scheme = "EXTERNAL"
iap {
oauth2_client_id = "abc"
oauth2_client_secret = "xyz"
}
}
```
<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.com%2Fterraform-google-modules%2Fdocs-examples.git&cloudshell_working_dir=region_backend_service_cache&cloudshell_image=gcr.io%2Fcloudshell-images%2Fcloudshell%3Alatest&open_in_editor=main.tf&cloudshell_print=.%2Fmotd&cloudshell_tutorial=.%2Ftutorial.md" 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%;">
Expand Down

0 comments on commit d34625e

Please sign in to comment.