Skip to content

Commit

Permalink
upgrade to sdkv2 (GoogleCloudPlatform#3971)
Browse files Browse the repository at this point in the history
* fixed imports, removed Removed, changed CustomizeDiffFuncs to include context

* more changes

* More SDK update changes.

* add more verbose logging to batcher

* only parse IAM policies if they're set

* add missing bracket

* fix StopContext

* fix use of configurefunc => configurecontextfunc

* ignore top-level % fields in state and fix errorf

* check for error before wrapping it in non-tryable error

* updates after rebase with master

* fix TestAccDataprocJob tests

* fix TestAccMonitoringAlertPolicy

* Fix AtLeastOneOf/ExactlyOneOf failures

* fix privateNetworkCustomizeDiff for sdkv2

* fix active directory domain trust imports for sdkv2

* Fix TestAccContainerCluster_withInvalidReleaseChannel

* add externalproviders: random

* fix TestAccComputeInstance_scratchDisk test

* check new not empty string, rather than length greater than 0

* remove set partial

* update data los prevention tests to v2

* switch compute_instance and project_service_identity to v2

* fix errors from beta run

* fix iam tests, update v2 imports

* fix customizediff after rebase

* fix node_config workload_metadata_config

* undo iam diff suppress changes, make nod_config.0.workload_metadata_config all ga

* fix iam tests

* Fix failing ProjectService_handleNotFound test.

Fix the TestAccProjectService_handleNotFound test to not fail by not
removing the service from state during the Create call, only during
subsequent reads.

* add random provider to all generated tests

* update region ssl cert datasource to v2

* update compute region ssl cert datasource test to use v2

* Update third_party/terraform/resources/resource_google_project_service.go

Co-authored-by: Riley Karson <[email protected]>

* spacing change, update compute_target_grpc_proxy_test to use v2

* update spanner db ddl custom diff to v2

* fix TestAccContainerNodePool_withInvalidUpgradeSettings

* move error check to isRetryableError

* add comment around check matches

* remove info message from bad merge

* remove comment

* return error if service is not enabled on create-read

* add comment for why we check for 404 in delete

* update tpuNodeCustomizeDiff to v2

* fix checkdestroy failures

* expect error for TestAccProjectService_disableDependentServices

Co-authored-by: Paddy Carver <[email protected]>
Co-authored-by: Riley Karson <[email protected]>
  • Loading branch information
3 people authored Sep 17, 2020
1 parent 3bc76aa commit 7048643
Show file tree
Hide file tree
Showing 571 changed files with 1,256 additions and 1,487 deletions.
2 changes: 1 addition & 1 deletion products/binaryauthorization/terraform.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ overrides: !ruby/object:Overrides::ResourceOverrides
}
var buf bytes.Buffer
schema.SerializeResourceForHash(&buf, copy, resourceBinaryAuthorizationPolicy().Schema["cluster_admission_rules"].Elem.(*schema.Resource))
return hashcode.String(buf.String())
return hashcode(buf.String())
}
clusterAdmissionRules.requireAttestationsBy: !ruby/object:Overrides::Terraform::PropertyOverride
is_set: true
Expand Down
2 changes: 0 additions & 2 deletions products/compute/terraform.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -627,7 +627,6 @@ overrides: !ruby/object:Overrides::ResourceOverrides
fw_name: "website-fw"
custom_code: !ruby/object:Provider::Terraform::CustomCode
post_create: templates/terraform/post_create/labels.erb
extra_schema_entry: templates/terraform/extra_schema_entry/forwarding_rule.erb
properties:
id: !ruby/object:Overrides::Terraform::PropertyOverride
exclude: true
Expand Down Expand Up @@ -1112,7 +1111,6 @@ overrides: !ruby/object:Overrides::ResourceOverrides
default_from_api: true
custom_code: !ruby/object:Provider::Terraform::CustomCode
post_create: templates/terraform/post_create/compute_network_delete_default_route.erb
extra_schema_entry: templates/terraform/extra_schema_entry/network.erb
NetworkEndpoint: !ruby/object:Overrides::Terraform::ResourceOverride
id_format: "{{project}}/{{zone}}/{{network_endpoint_group}}/{{instance}}/{{ip_address}}/{{port}}"
mutex: networkEndpoint/{{project}}/{{zone}}/{{network_endpoint_group}}
Expand Down
2 changes: 1 addition & 1 deletion products/datacatalog/terraform.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ overrides: !ruby/object:Overrides::ResourceOverrides
custom_flatten: 'templates/terraform/custom_flatten/json_schema.erb'
state_func: 'func(v interface{}) string { s, _ := structure.NormalizeJsonString(v); return s }'
validation: !ruby/object:Provider::Terraform::Validation
function: 'validation.ValidateJsonString'
function: 'validation.StringIsJSON'
userSpecifiedSystem: !ruby/object:Overrides::Terraform::PropertyOverride
validation: !ruby/object:Provider::Terraform::Validation
regex: '^[A-z_][A-z0-9_]{0,63}$'
Expand Down
12 changes: 6 additions & 6 deletions products/dns/terraform.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ overrides: !ruby/object:Overrides::ResourceOverrides
}
var buf bytes.Buffer
schema.SerializeResourceForHash(&buf, raw, dnsManagedZonePrivateVisibilityConfigNetworksSchema())
return hashcode.String(buf.String())
return hashcode(buf.String())
}
# TODO(drebes) Remove this description override once the Terraform 0.12 SDK is used.
description: |
Expand All @@ -102,11 +102,11 @@ overrides: !ruby/object:Overrides::ResourceOverrides
func(v interface{}) int {
raw := v.(map[string]interface{})
if address, ok := raw["ipv4_address"]; ok {
hashcode.String(address.(string))
hashcode(address.(string))
}
var buf bytes.Buffer
schema.SerializeResourceForHash(&buf, raw, dnsManagedZoneForwardingConfigTargetNameServersSchema())
return hashcode.String(buf.String())
return hashcode(buf.String())
}
serviceDirectoryConfig.namespace.namespaceUrl: !ruby/object:Overrides::Terraform::PropertyOverride
custom_expand: 'templates/terraform/custom_expand/sd_full_url.erb'
Expand Down Expand Up @@ -154,11 +154,11 @@ overrides: !ruby/object:Overrides::ResourceOverrides
func(v interface{}) int {
raw := v.(map[string]interface{})
if address, ok := raw["ipv4_address"]; ok {
hashcode.String(address.(string))
hashcode(address.(string))
}
var buf bytes.Buffer
schema.SerializeResourceForHash(&buf, raw, dnsPolicyAlternativeNameServerConfigTargetNameServersSchema())
return hashcode.String(buf.String())
return hashcode(buf.String())
}
description: !ruby/object:Overrides::Terraform::PropertyOverride
description: |
Expand All @@ -177,7 +177,7 @@ overrides: !ruby/object:Overrides::ResourceOverrides
}
var buf bytes.Buffer
schema.SerializeResourceForHash(&buf, raw, dnsPolicyNetworksSchema())
return hashcode.String(buf.String())
return hashcode(buf.String())
}
networks.networkUrl: !ruby/object:Overrides::Terraform::PropertyOverride
custom_expand: templates/terraform/custom_expand/network_full_url.erb
Expand Down
2 changes: 1 addition & 1 deletion products/healthcare/terraform.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ overrides: !ruby/object:Overrides::ResourceOverrides
custom_flatten: 'templates/terraform/custom_flatten/json_schema.erb'
state_func: 'func(v interface{}) string { s, _ := structure.NormalizeJsonString(v); return s }'
validation: !ruby/object:Provider::Terraform::Validation
function: 'validation.ValidateJsonString'
function: 'validation.StringIsJSON'
selfLink: !ruby/object:Overrides::Terraform::PropertyOverride
ignore_read: true
custom_code: !ruby/object:Provider::Terraform::CustomCode
Expand Down
3 changes: 0 additions & 3 deletions products/monitoring/terraform.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,7 @@ overrides: !ruby/object:Overrides::ResourceOverrides
alert_policy_display_name: "My Alert Policy"
custom_code: !ruby/object:Provider::Terraform::CustomCode
custom_import: templates/terraform/custom_import/self_link_as_name.erb
decoder: 'templates/terraform/decoders/alert_policy_removed_fields.go.erb'
post_create: templates/terraform/post_create/set_computed_name.erb
extra_schema_entry: templates/terraform/extra_schema_entry/alert_policy.erb

Group: !ruby/object:Overrides::Terraform::ResourceOverride
id_format: "{{name}}"
Expand Down Expand Up @@ -260,7 +258,6 @@ overrides: !ruby/object:Overrides::ResourceOverrides
group_display_name: "uptime-check-group"
custom_code: !ruby/object:Provider::Terraform::CustomCode
custom_import: templates/terraform/custom_import/self_link_as_name.erb
extra_schema_entry: 'templates/terraform/extra_schema_entry/monitoring_uptime_check_config_internal.go.erb'
post_create: templates/terraform/post_create/set_computed_name.erb
properties:
id: !ruby/object:Overrides::Terraform::PropertyOverride
Expand Down
4 changes: 2 additions & 2 deletions templates/terraform/constants/backend_service.go.erb
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,6 @@ func resourceGoogleComputeBackendServiceBackendHash(v interface{}) int {
buf.WriteString(fmt.Sprintf("%v-", v.(bool)))
}

log.Printf("[DEBUG] computed hash value of %v from %v", hashcode.String(buf.String()), buf.String())
return hashcode.String(buf.String())
log.Printf("[DEBUG] computed hash value of %v from %v", hashcode(buf.String()), buf.String())
return hashcode(buf.String())
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
var sensitiveParams = []string{"secret_access_key"}

func sensitiveParamCustomizeDiff(diff *schema.ResourceDiff, v interface{}) error {
func sensitiveParamCustomizeDiff(_ context.Context, diff *schema.ResourceDiff, v interface{}) error {
for _, sp := range sensitiveParams {
mapLabel := diff.Get("params." + sp).(string)
authLabel := diff.Get("sensitive_params.0." + sp).(string)
Expand Down
2 changes: 1 addition & 1 deletion templates/terraform/constants/cloud_run_service.go.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
func revisionNameCustomizeDiff(diff *schema.ResourceDiff, v interface{}) error {
func revisionNameCustomizeDiff(_ context.Context, diff *schema.ResourceDiff, v interface{}) error {
autogen := diff.Get("autogenerate_revision_name").(bool)
if autogen && diff.HasChange("template.0.metadata.0.name") {
return fmt.Errorf("google_cloud_run_service: `template.metadata.name` cannot be set while `autogenerate_revision_name` is true. Please remove the field or set `autogenerate_revision_name` to false.")
Expand Down
2 changes: 1 addition & 1 deletion templates/terraform/constants/cloudbuild_trigger.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
func stepTimeoutCustomizeDiff(diff *schema.ResourceDiff, v interface{}) error {
func stepTimeoutCustomizeDiff(_ context.Context, diff *schema.ResourceDiff, v interface{}) error {
buildList := diff.Get("build").([]interface{})
if len(buildList) == 0 || buildList[0] == nil {
return nil
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
func customDiffDeploymentManagerDeployment(d *schema.ResourceDiff, meta interface{}) error {
func customDiffDeploymentManagerDeployment(_ context.Context, d *schema.ResourceDiff, meta interface{}) error {
if preview := d.Get("preview").(bool); preview {
log.Printf("[WARN] Deployment preview set to true - Terraform will treat Deployment as recreate-only")

Expand Down
2 changes: 1 addition & 1 deletion templates/terraform/constants/disk.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Is the new disk size smaller than the old one?
func isDiskShrinkage(old, new, _ interface{}) bool {
func isDiskShrinkage(_ context.Context, old, new, _ interface{}) bool {
// It's okay to remove size entirely.
if old == nil || new == nil {
return false
Expand Down
4 changes: 2 additions & 2 deletions templates/terraform/constants/firewall.erb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func resourceComputeFirewallRuleHash(v interface{}) int {
}
}

return hashcode.String(buf.String())
return hashcode(buf.String())
}

func compareCaseInsensitive(k, old, new string, d *schema.ResourceData) bool {
Expand All @@ -45,7 +45,7 @@ func diffSuppressEnableLogging(k, old, new string, d *schema.ResourceData) bool
return false
}

func resourceComputeFirewallEnableLoggingCustomizeDiff(diff *schema.ResourceDiff, v interface{}) error {
func resourceComputeFirewallEnableLoggingCustomizeDiff(_ context.Context, diff *schema.ResourceDiff, v interface{}) error {
enableLogging, enableExists := diff.GetOkExists("enable_logging")
if !enableExists {
return nil
Expand Down
2 changes: 1 addition & 1 deletion templates/terraform/constants/health_check.erb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func validatePortSpec(diff *schema.ResourceDiff, blockName string) error {
return nil
}

func healthCheckCustomizeDiff(diff *schema.ResourceDiff, v interface{}) error {
func healthCheckCustomizeDiff(_ context.Context, diff *schema.ResourceDiff, v interface{}) error {
if diff.Get("http_health_check") != nil {
return validatePortSpec(diff, "http_health_check")
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

var sensitiveLabels = []string{"auth_token", "service_key", "password"}

func sensitiveLabelCustomizeDiff(diff *schema.ResourceDiff, v interface{}) error {
func sensitiveLabelCustomizeDiff(_ context.Context, diff *schema.ResourceDiff, v interface{}) error {
for _, sl := range sensitiveLabels {
mapLabel := diff.Get("labels." + sl).(string)
authLabel := diff.Get("sensitive_labels.0." + sl).(string)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func validateInternalBackendServiceBackends(backends []interface{}, d *schema.Re
return nil
}

func customDiffRegionBackendService(d *schema.ResourceDiff, meta interface{}) error {
func customDiffRegionBackendService(_ context.Context, d *schema.ResourceDiff, meta interface{}) error {
v, ok := d.GetOk("backend")
if !ok {
return nil
Expand Down
2 changes: 1 addition & 1 deletion templates/terraform/constants/router.go.erb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# limitations under the License.
-%>
// customizeDiff func for additional checks on google_compute_router properties:
func resourceComputeRouterCustomDiff(diff *schema.ResourceDiff, meta interface{}) error {
func resourceComputeRouterCustomDiff(_ context.Context, diff *schema.ResourceDiff, meta interface{}) error {

block := diff.Get("bgp.0").(map[string]interface{})
advertiseMode := block["advertise_mode"]
Expand Down
2 changes: 1 addition & 1 deletion templates/terraform/constants/router_nat.go.erb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func resourceNameSetFromSelfLinkSet(v interface{}) *schema.Set {
// so this customizeDiff func makes sure drainNatIps values:
// - aren't set at creation time
// - are in old value of nat_ips but not in new values
func resourceComputeRouterNatDrainNatIpsCustomDiff(diff *schema.ResourceDiff, meta interface{}) error {
func resourceComputeRouterNatDrainNatIpsCustomDiff(_ context.Context, diff *schema.ResourceDiff, meta interface{}) error {
o, n := diff.GetChange("drain_nat_ips")
oSet := resourceNameSetFromSelfLinkSet(o)
nSet := resourceNameSetFromSelfLinkSet(n)
Expand Down
2 changes: 1 addition & 1 deletion templates/terraform/constants/scheduler_auth.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Both oidc and oauth headers cannot be set
func validateAuthHeaders(diff *schema.ResourceDiff, v interface{}) error {
func validateAuthHeaders(_ context.Context, diff *schema.ResourceDiff, v interface{}) error {
httpBlock := diff.Get("http_target.0").(map[string]interface{})

if httpBlock != nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,5 @@ func resourceSourceRepoRepositoryPubSubConfigsHash(v interface{}) int {
buf.WriteString(fmt.Sprintf("%s-", v.(string)))
}

return hashcode.String(buf.String())
return hashcode(buf.String())
}
2 changes: 1 addition & 1 deletion templates/terraform/constants/spanner_database.go.erb
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func resourceSpannerDBDdlCustomDiffFunc(diff TerraformResourceDiff) error {
return nil
}

func resourceSpannerDBDdlCustomDiff(diff *schema.ResourceDiff, meta interface{}) error {
func resourceSpannerDBDdlCustomDiff(_ context.Context, diff *schema.ResourceDiff, meta interface{}) error {
// separate func to allow unit testing
return resourceSpannerDBDdlCustomDiffFunc(diff)
}
2 changes: 1 addition & 1 deletion templates/terraform/constants/ssl_policy.erb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-%>
func sslPolicyCustomizeDiff(diff *schema.ResourceDiff, v interface{}) error {
func sslPolicyCustomizeDiff(_ context.Context, diff *schema.ResourceDiff, v interface{}) error {
profile := diff.Get("profile")
customFeaturesCount := diff.Get("custom_features.#")

Expand Down
2 changes: 1 addition & 1 deletion templates/terraform/constants/subnetwork.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Whether the IP CIDR change shrinks the block.
func isShrinkageIpCidr(old, new, _ interface{}) bool {
func isShrinkageIpCidr(_ context.Context, old, new, _ interface{}) bool {
_, oldCidr, oldErr := net.ParseCIDR(old.(string))
_, newCidr, newErr := net.ParseCIDR(new.(string))

Expand Down
2 changes: 1 addition & 1 deletion templates/terraform/constants/tpu_node.erb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ func compareTpuNodeSchedulingConfig(k, old, new string, d *schema.ResourceData)
return false
}

func tpuNodeCustomizeDiff(diff *schema.ResourceDiff, meta interface{}) error {
func tpuNodeCustomizeDiff(_ context.Context, diff *schema.ResourceDiff, meta interface{}) error {
old, new := diff.GetChange("network")
config := meta.(*Config)

Expand Down
18 changes: 0 additions & 18 deletions templates/terraform/decoders/alert_policy_removed_fields.go.erb

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import (
"fmt"
"testing"

"github.com/hashicorp/terraform-plugin-sdk/helper/acctest"
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
)

<%# Since most resources define a "basic" config as their first example, we can reuse that config to create a resource to test IAM resources with. -%>
Expand Down
9 changes: 6 additions & 3 deletions templates/terraform/examples/base_configs/test_file.go.erb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"fmt"
"testing"

"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
)
<%
raise 'skip_test should be true if resource is not importable' \
Expand Down Expand Up @@ -58,10 +58,13 @@ func TestAcc<%= test_slug -%>(t *testing.T) {
vcrTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
<% unless versioned_provider -%>
Providers: testAccProviders,
Providers: testAccProviders,
<% else -%>
Providers: testAccProvidersOiCS,
Providers: testAccProvidersOiCS,
<% end -%>
ExternalProviders: map[string]resource.ExternalProvider{
"random": {},
},
<% unless object.skip_delete -%>
CheckDestroy: testAccCheck<%= "#{resource_name}" -%>DestroyProducer(t),
<% end -%>
Expand Down
23 changes: 0 additions & 23 deletions templates/terraform/extra_schema_entry/alert_policy.erb

This file was deleted.

20 changes: 0 additions & 20 deletions templates/terraform/extra_schema_entry/forwarding_rule.erb

This file was deleted.

Loading

0 comments on commit 7048643

Please sign in to comment.