diff --git a/go.mod b/go.mod index c5b8b3818..17c03e8f9 100644 --- a/go.mod +++ b/go.mod @@ -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 diff --git a/go.sum b/go.sum index e4704dccd..3ccc7d1fc 100644 --- a/go.sum +++ b/go.sum @@ -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= diff --git a/tfplan2cai/converters/google/resources/services/compute/compute_backend_service.go b/tfplan2cai/converters/google/resources/services/compute/compute_backend_service.go index 0b0fc5848..ce05ea0b7 100644 --- a/tfplan2cai/converters/google/resources/services/compute/compute_backend_service.go +++ b/tfplan2cai/converters/google/resources/services/compute/compute_backend_service.go @@ -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 @@ -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 @@ -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 } diff --git a/tfplan2cai/converters/google/resources/services/compute/compute_region_backend_service.go b/tfplan2cai/converters/google/resources/services/compute/compute_region_backend_service.go index 236657c08..2d2350d38 100644 --- a/tfplan2cai/converters/google/resources/services/compute/compute_region_backend_service.go +++ b/tfplan2cai/converters/google/resources/services/compute/compute_region_backend_service.go @@ -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 @@ -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 @@ -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 }