Skip to content
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

Remove default addition of IAP message in encoder and decoder, add new required enabled field and remove the previous required tags under IAP message for resource google_compute_backend_service and resource google_compute_region_backend_service #2535

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
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ require (
github.com/hashicorp/hcl/v2 v2.19.1
github.com/hashicorp/terraform-json v0.21.0
github.com/hashicorp/terraform-plugin-sdk/v2 v2.33.0
github.com/hashicorp/terraform-provider-google-beta v1.20.1-0.20240717234108-c1cdf12e18b9
github.com/hashicorp/terraform-provider-google-beta v1.20.1-0.20240718174456-c6b8e947e73c
github.com/mitchellh/go-homedir v1.1.0 // indirect
github.com/pkg/errors v0.9.1
github.com/stretchr/testify v1.9.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -184,8 +184,8 @@ github.com/hashicorp/terraform-plugin-mux v0.15.0 h1:+/+lDx0WUsIOpkAmdwBIoFU8UP9
github.com/hashicorp/terraform-plugin-mux v0.15.0/go.mod h1:9ezplb1Dyq394zQ+ldB0nvy/qbNAz3mMoHHseMTMaKo=
github.com/hashicorp/terraform-plugin-sdk/v2 v2.33.0 h1:qHprzXy/As0rxedphECBEQAh3R4yp6pKksKHcqZx5G8=
github.com/hashicorp/terraform-plugin-sdk/v2 v2.33.0/go.mod h1:H+8tjs9TjV2w57QFVSMBQacf8k/E1XwLXGCARgViC6A=
github.com/hashicorp/terraform-provider-google-beta v1.20.1-0.20240717234108-c1cdf12e18b9 h1:ghg6RC9w62hH7WTNzINELE/Lec+w0gzTpMxD0ZJgN8g=
github.com/hashicorp/terraform-provider-google-beta v1.20.1-0.20240717234108-c1cdf12e18b9/go.mod h1:LtqLd41zCL9zNzjz4lld4q9wnK3+MWRvIdoNc/anTZ0=
github.com/hashicorp/terraform-provider-google-beta v1.20.1-0.20240718174456-c6b8e947e73c h1:oJ/DyLj6fY7FdwOiHzWyJ1ZUX5qC2D/tLZUi/2j1vKc=
github.com/hashicorp/terraform-provider-google-beta v1.20.1-0.20240718174456-c6b8e947e73c/go.mod h1:LtqLd41zCL9zNzjz4lld4q9wnK3+MWRvIdoNc/anTZ0=
github.com/hashicorp/terraform-registry-address v0.2.3 h1:2TAiKJ1A3MAkZlH1YI/aTVcLZRu7JseiXNRHbOAyoTI=
github.com/hashicorp/terraform-registry-address v0.2.3/go.mod h1:lFHA76T8jfQteVfT7caREqguFrW3c4MFSPhZB7HHgUM=
github.com/hashicorp/terraform-svchost v0.1.1 h1:EZZimZ1GxdqFRinZ1tpJwVxxt49xc/S52uzrw4x0jKQ=
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -380,24 +380,6 @@ func GetComputeBackendServiceApiObject(d tpgresource.TerraformResourceData, conf
}

func resourceComputeBackendServiceEncoder(d tpgresource.TerraformResourceData, meta interface{}, obj map[string]interface{}) (map[string]interface{}, error) {
// The BackendService API's Update / PUT API is badly formed and behaves like
// a PATCH field for at least IAP. When sent a `null` `iap` field, the API
// doesn't disable an existing field. To work around this, we need to emulate
// the old Terraform behaviour of always sending the block (at both update and
// create), and force sending each subfield as empty when the block isn't
// present in config.

iapVal := obj["iap"]
if iapVal == nil {
data := map[string]interface{}{}
data["enabled"] = false
obj["iap"] = data
} else {
iap := iapVal.(map[string]interface{})
iap["enabled"] = true
obj["iap"] = iap
}

backendsRaw, ok := obj["backends"]
if !ok {
return obj, nil
Expand Down Expand Up @@ -1140,6 +1122,13 @@ func expandComputeBackendServiceIap(v interface{}, d tpgresource.TerraformResour
original := raw.(map[string]interface{})
transformed := make(map[string]interface{})

transformedEnabled, err := expandComputeBackendServiceIapEnabled(original["enabled"], d, config)
if err != nil {
return nil, err
} else if val := reflect.ValueOf(transformedEnabled); val.IsValid() && !tpgresource.IsEmptyValue(val) {
transformed["enabled"] = transformedEnabled
}

transformedOauth2ClientId, err := expandComputeBackendServiceIapOauth2ClientId(original["oauth2_client_id"], d, config)
if err != nil {
return nil, err
Expand All @@ -1164,6 +1153,10 @@ func expandComputeBackendServiceIap(v interface{}, d tpgresource.TerraformResour
return transformed, nil
}

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

func expandComputeBackendServiceIapOauth2ClientId(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
return v, nil
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -309,23 +309,6 @@ func GetComputeRegionBackendServiceApiObject(d tpgresource.TerraformResourceData
}

func resourceComputeRegionBackendServiceEncoder(d tpgresource.TerraformResourceData, meta interface{}, obj map[string]interface{}) (map[string]interface{}, error) {
// The RegionBackendService API's Update / PUT API is badly formed and behaves like
// a PATCH field for at least IAP. When sent a `null` `iap` field, the API
// doesn't disable an existing field. To work around this, we need to emulate
// the old Terraform behaviour of always sending the block (at both update and
// create), and force sending each subfield as empty when the block isn't
// present in config.

iapVal := obj["iap"]
if iapVal == nil {
data := map[string]interface{}{}
data["enabled"] = false
obj["iap"] = data
} else {
iap := iapVal.(map[string]interface{})
iap["enabled"] = true
obj["iap"] = iap
}

if d.Get("load_balancing_scheme").(string) == "EXTERNAL_MANAGED" || d.Get("load_balancing_scheme").(string) == "INTERNAL_MANAGED" {
return obj, nil
Expand Down Expand Up @@ -1060,6 +1043,13 @@ func expandComputeRegionBackendServiceIap(v interface{}, d tpgresource.Terraform
original := raw.(map[string]interface{})
transformed := make(map[string]interface{})

transformedEnabled, err := expandComputeRegionBackendServiceIapEnabled(original["enabled"], d, config)
if err != nil {
return nil, err
} else if val := reflect.ValueOf(transformedEnabled); val.IsValid() && !tpgresource.IsEmptyValue(val) {
transformed["enabled"] = transformedEnabled
}

transformedOauth2ClientId, err := expandComputeRegionBackendServiceIapOauth2ClientId(original["oauth2_client_id"], d, config)
if err != nil {
return nil, err
Expand All @@ -1084,6 +1074,10 @@ func expandComputeRegionBackendServiceIap(v interface{}, d tpgresource.Terraform
return transformed, nil
}

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

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