From 1800fbf70c95bcf29bc06d3f0647e38cd4ef90ce Mon Sep 17 00:00:00 2001 From: Zhenhua Li Date: Tue, 16 Apr 2024 13:08:16 -0700 Subject: [PATCH] Convert templates for custom_update, decoders, encoders, extra_schema_entry, post_create --- .../cloud_identity_group_membership.go.tmpl | 137 ++++++++++++++++++ .../custom_update/go/secret_version.go.tmpl | 18 +++ .../go/avoid_meaningless_project_update.tmpl | 60 ++++++++ .../decoders/go/backend_service.go.tmpl | 38 +++++ .../go/bigquery_data_transfer.go.tmpl | 26 ++++ .../decoders/go/billing_project_info.go.tmpl | 2 + .../terraform/decoders/go/cloud_run.go.tmpl | 21 +++ ..._disk_resource_policies_attachment.go.tmpl | 2 + .../decoders/go/compute_network.go.tmpl | 2 + .../compute_region_target_https_proxy.go.tmpl | 15 ++ .../go/compute_target_https_proxy.go.tmpl | 15 ++ ...neranalysis_attestation_field_name.go.tmpl | 21 +++ .../go/containeranalysis_occurrence.go.tmpl | 41 ++++++ .../templates/terraform/decoders/go/disk.tmpl | 62 ++++++++ .../decoders/go/dlp_job_trigger.go.tmpl | 17 +++ .../decoders/go/dlp_stored_info_type.go.tmpl | 24 +++ .../decoders/go/dlp_template_id.go.tmpl | 17 +++ .../go/firebase_database_instance.go.tmpl | 6 + .../go/firebasehosting_release.go.tmpl | 5 + .../go/firebasehosting_version.go.tmpl | 5 + .../decoders/go/firestore_document.go.tmpl | 21 +++ .../decoders/go/integrations_client.go.tmpl | 4 + .../terraform/decoders/go/kms.go.tmpl | 18 +++ .../go/long_name_to_self_link.go.tmpl | 22 +++ .../go/monitoring_monitored_project.go.tmpl | 48 ++++++ .../monitoring_notification_channel.go.tmpl | 26 ++++ .../decoders/go/network_endpoint.go.tmpl | 18 +++ .../decoders/go/network_endpoints.go.tmpl | 54 +++++++ .../terraform/decoders/go/noop.go.tmpl | 1 + .../go/os_config_patch_deployment.go.tmpl | 9 ++ .../decoders/go/private_cloud.go.tmpl | 54 +++++++ .../decoders/go/redis_instance.go.tmpl | 50 +++++++ .../go/region_backend_service.go.tmpl | 51 +++++++ .../terraform/decoders/go/route.tmpl | 12 ++ .../terraform/decoders/go/snapshot.go.tmpl | 53 +++++++ .../decoders/go/spanner_database.go.tmpl | 14 ++ .../decoders/go/spanner_instance.go.tmpl | 13 ++ ...sql_source_representation_instance.go.tmpl | 28 ++++ .../go/treat_deleted_state_as_gone.go.tmpl | 5 + .../go/treat_destroyed_state_as_gone.tmpl | 17 +++ .../decoders/go/unwrap_global_neg.go.tmpl | 18 +++ .../decoders/go/unwrap_resource.go.tmpl | 18 +++ .../encoders/cloud_run_domain_mapping.go.erb | 2 +- mmv1/templates/terraform/encoders/disk.erb | 8 +- .../go/access_level_never_send_parent.go.tmpl | 14 ++ .../go/active_directory_domain_trust.go.tmpl | 17 +++ .../terraform/encoders/go/alloydb_backup.tmpl | 3 + .../terraform/encoders/go/api_config.go.tmpl | 13 ++ .../encoders/go/apigee_organization.go.tmpl | 2 + .../encoders/go/backend_service.go.tmpl | 85 +++++++++++ .../encoders/go/bigquery_connection.go.tmpl | 3 + .../go/bigquery_data_transfer.go.tmpl | 29 ++++ .../encoders/go/bigquery_job.go.tmpl | 18 +++ .../encoders/go/bigtable_app_profile.go.tmpl | 20 +++ .../encoders/go/billing_project_info.go.tmpl | 8 + .../encoders/go/cloud_asset_feed.go.tmpl | 10 ++ .../go/cloud_run_domain_mapping.go.tmpl | 20 +++ .../encoders/go/cloud_run_service.go.tmpl | 23 +++ .../encoders/go/cloud_scheduler.go.tmpl | 2 + .../cloudbuild_bitbucketserver_config.go.tmpl | 3 + .../go/cloudbuildv2_repository.go.tmpl | 35 +++++ .../go/clouddomains_registration.go.tmpl | 28 ++++ .../go/compute_backend_bucket.go.tmpl | 44 ++++++ ..._disk_resource_policies_attachment.go.tmpl | 25 ++++ .../compute_global_network_endpoint.go.tmpl | 21 +++ .../compute_instance_group_membership.go.tmpl | 21 +++ .../encoders/go/compute_network.go.tmpl | 2 + .../go/compute_network_endpoint.go.tmpl | 21 +++ .../go/compute_network_endpoints.go.tmpl | 18 +++ .../go/compute_per_instance_config.go.tmpl | 16 ++ ..._disk_resource_policies_attachment.go.tmpl | 17 +++ .../compute_region_network_endpoint.go.tmpl | 21 +++ .../compute_region_target_https_proxy.go.tmpl | 10 ++ .../go/compute_target_https_proxy.go.tmpl | 10 ++ ...neranalysis_attestation_field_name.go.tmpl | 21 +++ .../go/containeranalysis_occurrence.go.tmpl | 41 ++++++ .../encoders/go/data_catalog_tag.go.tmpl | 17 +++ .../encoders/go/datastream_stream.go.tmpl | 16 ++ ...chat_engine_hardcode_solution_type.go.tmpl | 3 + ...arch_engine_hardcode_solution_type.go.tmpl | 3 + .../templates/terraform/encoders/go/disk.tmpl | 54 +++++++ .../encoders/go/dlp_job_trigger.go.tmpl | 20 +++ .../encoders/go/dlp_stored_info_type.go.tmpl | 19 +++ .../encoders/go/firestore_field.go.tmpl | 9 ++ .../encoders/go/flex_app_version.go.tmpl | 2 + .../encoders/go/health_check_type.tmpl | 100 +++++++++++++ .../terraform/encoders/go/index.go.tmpl | 19 +++ .../encoders/go/kms_crypto_key.go.tmpl | 32 ++++ .../encoders/go/location_from_region.go.tmpl | 23 +++ .../go/logging_linked_dataset.go.tmpl | 34 +++++ .../encoders/go/logging_log_view.go.tmpl | 34 +++++ .../go/monitoring_monitored_project.go.tmpl | 24 +++ .../monitoring_notification_channel.go.tmpl | 29 ++++ .../encoders/go/monitoring_service.go.tmpl | 22 +++ .../encoders/go/monitoring_slo.go.tmpl | 40 +++++ .../go/network_peering_routes_config.go.tmpl | 17 +++ .../encoders/go/no_send_name.go.tmpl | 14 ++ .../encoders/go/normalize_group.go.tmpl | 17 +++ .../go/os_config_patch_deployment.go.tmpl | 28 ++++ .../terraform/encoders/go/pubsub_lite.tmpl | 20 +++ ...edis_location_id_for_fallback_zone.go.tmpl | 21 +++ .../go/region_backend_service.go.tmpl | 80 ++++++++++ .../encoders/go/send_nil_body.go.tmpl | 1 + .../go/service_connection_policy.go.tmpl | 2 + .../encoders/go/spanner_database.go.tmpl | 19 +++ .../encoders/go/spanner_instance.go.tmpl | 16 ++ .../go/spanner_instance_update.go.tmpl | 49 +++++++ ...sql_source_representation_instance.go.tmpl | 17 +++ .../vertex_ai_featurestore_entitytype.go.tmpl | 8 + ...ai_featurestore_entitytype_feature.go.tmpl | 8 + .../terraform/encoders/go/vpn_tunnel.go.tmpl | 16 ++ .../terraform/encoders/go/workflow.go.tmpl | 14 ++ .../terraform/encoders/go/wrap_object.go.tmpl | 15 ++ ...t_with_deployment_resource_pool_id.go.tmpl | 19 +++ .../go/wrap_object_with_template_id.go.tmpl | 19 +++ .../extra_schema_entry/go/api_config.tmpl | 8 + .../go/bigquery_dataset_access.go.tmpl | 17 +++ .../go/bigtable_app_profile.go.tmpl | 21 +++ .../extra_schema_entry/go/firewall.tmpl | 19 +++ .../extra_schema_entry/go/redis_instance.tmpl | 6 + .../extra_schema_entry/go/route.tmpl | 7 + ...cret_version_is_secret_data_base64.go.tmpl | 19 +++ .../go/ssl_certificate.tmpl | 18 +++ .../extra_schema_entry/go/subnetwork.tmpl | 18 +++ .../vertex_ai_featurestore_entitytype.go.tmpl | 5 + ...ai_featurestore_entitytype_feature.go.tmpl | 5 + .../extra_schema_entry/go/workflow.tmpl | 7 + .../post_create/go/KMS_Verify.go.tmpl | 17 +++ .../post_create/go/accesspolicy.tmpl | 11 ++ .../post_create/go/agent_pool.go.tmpl | 3 + .../go/bigquery_connection_id.go.tmpl | 14 ++ .../go/bigquery_dataset_access.go.tmpl | 40 +++++ .../post_create/go/cloud_asset_feed.go.tmpl | 2 + .../post_create/go/cloud_scheduler.go.tmpl | 29 ++++ .../cloudbuild_bitbucketserver_config.go.tmpl | 50 +++++++ .../go/cloudbuild_trigger_id.go.tmpl | 18 +++ .../go/clouddomains_registration.go.tmpl | 3 + ...ute_backend_bucket_security_policy.go.tmpl | 19 +++ ...te_backend_service_security_policy.go.tmpl | 38 +++++ .../compute_network_delete_default_route.tmpl | 31 ++++ ...on_backend_service_security_policy.go.tmpl | 39 +++++ ...te_target_instance_security_policy.go.tmpl | 34 +++++ .../post_create/go/datastream_stream.go.tmpl | 22 +++ .../go/firebase_database_instance.go.tmpl | 20 +++ ...g_custom_domain_wait_dns_verification.tmpl | 14 ++ .../go/firebasehosting_release.tmpl | 6 + ...asehosting_version_immediate_finalize.tmpl | 39 +++++ .../post_create/go/gcip_tenant.go.tmpl | 14 ++ .../go/global_network_endpoint_group.go.tmpl | 33 +++++ .../terraform/post_create/go/group.tmpl | 4 + .../go/iam_workforce_pool_provider.go.tmpl | 17 +++ .../post_create/go/iap_client.go.tmpl | 7 + .../terraform/post_create/go/index.go.tmpl | 21 +++ .../integration_connectors_connection.go.tmpl | 3 + .../go/interconnect_attachment.go.tmpl | 3 + .../go/kms_secret_ciphertext.go.tmpl | 14 ++ .../terraform/post_create/go/labels.tmpl | 67 +++++++++ .../terraform/post_create/go/lien.tmpl | 11 ++ ...app_volume_replication_post_create.go.tmpl | 7 + .../post_create/go/notebooks_instance.go.tmpl | 13 ++ .../go/org_security_policy.go.tmpl | 26 ++++ .../org_security_policy_association.go.tmpl | 29 ++++ .../go/org_security_policy_rule.go.tmpl | 29 ++++ .../post_create/go/private_connection.go.tmpl | 3 + .../privateca_certificate_authority.go.tmpl | 24 +++ .../post_create/go/secret_version.go.tmpl | 14 ++ .../post_create/go/set_computed_name.tmpl | 17 +++ .../terraform/post_create/go/sleep.go.tmpl | 4 + .../post_create/go/sleep_2_min.go.tmpl | 4 + .../go/source_repo_repository_update.go.tmpl | 5 + .../post_create/go/spanner_database.go.tmpl | 107 ++++++++++++++ .../post_create/go/sshkeyfingerprint.go.tmpl | 23 +++ .../post_create/go/storage_hmac_key.go.tmpl | 27 ++++ .../post_create/go/workbench_instance.go.tmpl | 13 ++ .../terraform/post_create/labels.erb | 2 +- 175 files changed, 3752 insertions(+), 7 deletions(-) create mode 100644 mmv1/templates/terraform/custom_update/go/cloud_identity_group_membership.go.tmpl create mode 100644 mmv1/templates/terraform/custom_update/go/secret_version.go.tmpl create mode 100644 mmv1/templates/terraform/decoders/go/avoid_meaningless_project_update.tmpl create mode 100644 mmv1/templates/terraform/decoders/go/backend_service.go.tmpl create mode 100644 mmv1/templates/terraform/decoders/go/bigquery_data_transfer.go.tmpl create mode 100644 mmv1/templates/terraform/decoders/go/billing_project_info.go.tmpl create mode 100644 mmv1/templates/terraform/decoders/go/cloud_run.go.tmpl create mode 100644 mmv1/templates/terraform/decoders/go/compute_disk_resource_policies_attachment.go.tmpl create mode 100644 mmv1/templates/terraform/decoders/go/compute_network.go.tmpl create mode 100644 mmv1/templates/terraform/decoders/go/compute_region_target_https_proxy.go.tmpl create mode 100644 mmv1/templates/terraform/decoders/go/compute_target_https_proxy.go.tmpl create mode 100644 mmv1/templates/terraform/decoders/go/containeranalysis_attestation_field_name.go.tmpl create mode 100644 mmv1/templates/terraform/decoders/go/containeranalysis_occurrence.go.tmpl create mode 100644 mmv1/templates/terraform/decoders/go/disk.tmpl create mode 100644 mmv1/templates/terraform/decoders/go/dlp_job_trigger.go.tmpl create mode 100644 mmv1/templates/terraform/decoders/go/dlp_stored_info_type.go.tmpl create mode 100644 mmv1/templates/terraform/decoders/go/dlp_template_id.go.tmpl create mode 100644 mmv1/templates/terraform/decoders/go/firebase_database_instance.go.tmpl create mode 100644 mmv1/templates/terraform/decoders/go/firebasehosting_release.go.tmpl create mode 100644 mmv1/templates/terraform/decoders/go/firebasehosting_version.go.tmpl create mode 100644 mmv1/templates/terraform/decoders/go/firestore_document.go.tmpl create mode 100644 mmv1/templates/terraform/decoders/go/integrations_client.go.tmpl create mode 100644 mmv1/templates/terraform/decoders/go/kms.go.tmpl create mode 100644 mmv1/templates/terraform/decoders/go/long_name_to_self_link.go.tmpl create mode 100644 mmv1/templates/terraform/decoders/go/monitoring_monitored_project.go.tmpl create mode 100644 mmv1/templates/terraform/decoders/go/monitoring_notification_channel.go.tmpl create mode 100644 mmv1/templates/terraform/decoders/go/network_endpoint.go.tmpl create mode 100644 mmv1/templates/terraform/decoders/go/network_endpoints.go.tmpl create mode 100644 mmv1/templates/terraform/decoders/go/noop.go.tmpl create mode 100644 mmv1/templates/terraform/decoders/go/os_config_patch_deployment.go.tmpl create mode 100644 mmv1/templates/terraform/decoders/go/private_cloud.go.tmpl create mode 100644 mmv1/templates/terraform/decoders/go/redis_instance.go.tmpl create mode 100644 mmv1/templates/terraform/decoders/go/region_backend_service.go.tmpl create mode 100644 mmv1/templates/terraform/decoders/go/route.tmpl create mode 100644 mmv1/templates/terraform/decoders/go/snapshot.go.tmpl create mode 100644 mmv1/templates/terraform/decoders/go/spanner_database.go.tmpl create mode 100644 mmv1/templates/terraform/decoders/go/spanner_instance.go.tmpl create mode 100644 mmv1/templates/terraform/decoders/go/sql_source_representation_instance.go.tmpl create mode 100644 mmv1/templates/terraform/decoders/go/treat_deleted_state_as_gone.go.tmpl create mode 100644 mmv1/templates/terraform/decoders/go/treat_destroyed_state_as_gone.tmpl create mode 100644 mmv1/templates/terraform/decoders/go/unwrap_global_neg.go.tmpl create mode 100644 mmv1/templates/terraform/decoders/go/unwrap_resource.go.tmpl create mode 100644 mmv1/templates/terraform/encoders/go/access_level_never_send_parent.go.tmpl create mode 100644 mmv1/templates/terraform/encoders/go/active_directory_domain_trust.go.tmpl create mode 100644 mmv1/templates/terraform/encoders/go/alloydb_backup.tmpl create mode 100644 mmv1/templates/terraform/encoders/go/api_config.go.tmpl create mode 100644 mmv1/templates/terraform/encoders/go/apigee_organization.go.tmpl create mode 100644 mmv1/templates/terraform/encoders/go/backend_service.go.tmpl create mode 100644 mmv1/templates/terraform/encoders/go/bigquery_connection.go.tmpl create mode 100644 mmv1/templates/terraform/encoders/go/bigquery_data_transfer.go.tmpl create mode 100644 mmv1/templates/terraform/encoders/go/bigquery_job.go.tmpl create mode 100644 mmv1/templates/terraform/encoders/go/bigtable_app_profile.go.tmpl create mode 100644 mmv1/templates/terraform/encoders/go/billing_project_info.go.tmpl create mode 100644 mmv1/templates/terraform/encoders/go/cloud_asset_feed.go.tmpl create mode 100644 mmv1/templates/terraform/encoders/go/cloud_run_domain_mapping.go.tmpl create mode 100644 mmv1/templates/terraform/encoders/go/cloud_run_service.go.tmpl create mode 100644 mmv1/templates/terraform/encoders/go/cloud_scheduler.go.tmpl create mode 100644 mmv1/templates/terraform/encoders/go/cloudbuild_bitbucketserver_config.go.tmpl create mode 100644 mmv1/templates/terraform/encoders/go/cloudbuildv2_repository.go.tmpl create mode 100644 mmv1/templates/terraform/encoders/go/clouddomains_registration.go.tmpl create mode 100644 mmv1/templates/terraform/encoders/go/compute_backend_bucket.go.tmpl create mode 100644 mmv1/templates/terraform/encoders/go/compute_disk_resource_policies_attachment.go.tmpl create mode 100644 mmv1/templates/terraform/encoders/go/compute_global_network_endpoint.go.tmpl create mode 100644 mmv1/templates/terraform/encoders/go/compute_instance_group_membership.go.tmpl create mode 100644 mmv1/templates/terraform/encoders/go/compute_network.go.tmpl create mode 100644 mmv1/templates/terraform/encoders/go/compute_network_endpoint.go.tmpl create mode 100644 mmv1/templates/terraform/encoders/go/compute_network_endpoints.go.tmpl create mode 100644 mmv1/templates/terraform/encoders/go/compute_per_instance_config.go.tmpl create mode 100644 mmv1/templates/terraform/encoders/go/compute_region_disk_resource_policies_attachment.go.tmpl create mode 100644 mmv1/templates/terraform/encoders/go/compute_region_network_endpoint.go.tmpl create mode 100644 mmv1/templates/terraform/encoders/go/compute_region_target_https_proxy.go.tmpl create mode 100644 mmv1/templates/terraform/encoders/go/compute_target_https_proxy.go.tmpl create mode 100644 mmv1/templates/terraform/encoders/go/containeranalysis_attestation_field_name.go.tmpl create mode 100644 mmv1/templates/terraform/encoders/go/containeranalysis_occurrence.go.tmpl create mode 100644 mmv1/templates/terraform/encoders/go/data_catalog_tag.go.tmpl create mode 100644 mmv1/templates/terraform/encoders/go/datastream_stream.go.tmpl create mode 100644 mmv1/templates/terraform/encoders/go/discovery_engine_chat_engine_hardcode_solution_type.go.tmpl create mode 100644 mmv1/templates/terraform/encoders/go/discovery_engine_search_engine_hardcode_solution_type.go.tmpl create mode 100644 mmv1/templates/terraform/encoders/go/disk.tmpl create mode 100644 mmv1/templates/terraform/encoders/go/dlp_job_trigger.go.tmpl create mode 100644 mmv1/templates/terraform/encoders/go/dlp_stored_info_type.go.tmpl create mode 100644 mmv1/templates/terraform/encoders/go/firestore_field.go.tmpl create mode 100644 mmv1/templates/terraform/encoders/go/flex_app_version.go.tmpl create mode 100644 mmv1/templates/terraform/encoders/go/health_check_type.tmpl create mode 100644 mmv1/templates/terraform/encoders/go/index.go.tmpl create mode 100644 mmv1/templates/terraform/encoders/go/kms_crypto_key.go.tmpl create mode 100644 mmv1/templates/terraform/encoders/go/location_from_region.go.tmpl create mode 100644 mmv1/templates/terraform/encoders/go/logging_linked_dataset.go.tmpl create mode 100644 mmv1/templates/terraform/encoders/go/logging_log_view.go.tmpl create mode 100644 mmv1/templates/terraform/encoders/go/monitoring_monitored_project.go.tmpl create mode 100644 mmv1/templates/terraform/encoders/go/monitoring_notification_channel.go.tmpl create mode 100644 mmv1/templates/terraform/encoders/go/monitoring_service.go.tmpl create mode 100644 mmv1/templates/terraform/encoders/go/monitoring_slo.go.tmpl create mode 100644 mmv1/templates/terraform/encoders/go/network_peering_routes_config.go.tmpl create mode 100644 mmv1/templates/terraform/encoders/go/no_send_name.go.tmpl create mode 100644 mmv1/templates/terraform/encoders/go/normalize_group.go.tmpl create mode 100644 mmv1/templates/terraform/encoders/go/os_config_patch_deployment.go.tmpl create mode 100644 mmv1/templates/terraform/encoders/go/pubsub_lite.tmpl create mode 100644 mmv1/templates/terraform/encoders/go/redis_location_id_for_fallback_zone.go.tmpl create mode 100644 mmv1/templates/terraform/encoders/go/region_backend_service.go.tmpl create mode 100644 mmv1/templates/terraform/encoders/go/send_nil_body.go.tmpl create mode 100644 mmv1/templates/terraform/encoders/go/service_connection_policy.go.tmpl create mode 100644 mmv1/templates/terraform/encoders/go/spanner_database.go.tmpl create mode 100644 mmv1/templates/terraform/encoders/go/spanner_instance.go.tmpl create mode 100644 mmv1/templates/terraform/encoders/go/spanner_instance_update.go.tmpl create mode 100644 mmv1/templates/terraform/encoders/go/sql_source_representation_instance.go.tmpl create mode 100644 mmv1/templates/terraform/encoders/go/vertex_ai_featurestore_entitytype.go.tmpl create mode 100644 mmv1/templates/terraform/encoders/go/vertex_ai_featurestore_entitytype_feature.go.tmpl create mode 100644 mmv1/templates/terraform/encoders/go/vpn_tunnel.go.tmpl create mode 100644 mmv1/templates/terraform/encoders/go/workflow.go.tmpl create mode 100644 mmv1/templates/terraform/encoders/go/wrap_object.go.tmpl create mode 100644 mmv1/templates/terraform/encoders/go/wrap_object_with_deployment_resource_pool_id.go.tmpl create mode 100644 mmv1/templates/terraform/encoders/go/wrap_object_with_template_id.go.tmpl create mode 100644 mmv1/templates/terraform/extra_schema_entry/go/api_config.tmpl create mode 100644 mmv1/templates/terraform/extra_schema_entry/go/bigquery_dataset_access.go.tmpl create mode 100644 mmv1/templates/terraform/extra_schema_entry/go/bigtable_app_profile.go.tmpl create mode 100644 mmv1/templates/terraform/extra_schema_entry/go/firewall.tmpl create mode 100644 mmv1/templates/terraform/extra_schema_entry/go/redis_instance.tmpl create mode 100644 mmv1/templates/terraform/extra_schema_entry/go/route.tmpl create mode 100644 mmv1/templates/terraform/extra_schema_entry/go/secret_version_is_secret_data_base64.go.tmpl create mode 100644 mmv1/templates/terraform/extra_schema_entry/go/ssl_certificate.tmpl create mode 100644 mmv1/templates/terraform/extra_schema_entry/go/subnetwork.tmpl create mode 100644 mmv1/templates/terraform/extra_schema_entry/go/vertex_ai_featurestore_entitytype.go.tmpl create mode 100644 mmv1/templates/terraform/extra_schema_entry/go/vertex_ai_featurestore_entitytype_feature.go.tmpl create mode 100644 mmv1/templates/terraform/extra_schema_entry/go/workflow.tmpl create mode 100644 mmv1/templates/terraform/post_create/go/KMS_Verify.go.tmpl create mode 100644 mmv1/templates/terraform/post_create/go/accesspolicy.tmpl create mode 100644 mmv1/templates/terraform/post_create/go/agent_pool.go.tmpl create mode 100644 mmv1/templates/terraform/post_create/go/bigquery_connection_id.go.tmpl create mode 100644 mmv1/templates/terraform/post_create/go/bigquery_dataset_access.go.tmpl create mode 100644 mmv1/templates/terraform/post_create/go/cloud_asset_feed.go.tmpl create mode 100644 mmv1/templates/terraform/post_create/go/cloud_scheduler.go.tmpl create mode 100644 mmv1/templates/terraform/post_create/go/cloudbuild_bitbucketserver_config.go.tmpl create mode 100644 mmv1/templates/terraform/post_create/go/cloudbuild_trigger_id.go.tmpl create mode 100644 mmv1/templates/terraform/post_create/go/clouddomains_registration.go.tmpl create mode 100644 mmv1/templates/terraform/post_create/go/compute_backend_bucket_security_policy.go.tmpl create mode 100644 mmv1/templates/terraform/post_create/go/compute_backend_service_security_policy.go.tmpl create mode 100644 mmv1/templates/terraform/post_create/go/compute_network_delete_default_route.tmpl create mode 100644 mmv1/templates/terraform/post_create/go/compute_region_backend_service_security_policy.go.tmpl create mode 100644 mmv1/templates/terraform/post_create/go/compute_target_instance_security_policy.go.tmpl create mode 100644 mmv1/templates/terraform/post_create/go/datastream_stream.go.tmpl create mode 100644 mmv1/templates/terraform/post_create/go/firebase_database_instance.go.tmpl create mode 100644 mmv1/templates/terraform/post_create/go/firebasehosting_custom_domain_wait_dns_verification.tmpl create mode 100644 mmv1/templates/terraform/post_create/go/firebasehosting_release.tmpl create mode 100644 mmv1/templates/terraform/post_create/go/firebasehosting_version_immediate_finalize.tmpl create mode 100644 mmv1/templates/terraform/post_create/go/gcip_tenant.go.tmpl create mode 100644 mmv1/templates/terraform/post_create/go/global_network_endpoint_group.go.tmpl create mode 100644 mmv1/templates/terraform/post_create/go/group.tmpl create mode 100644 mmv1/templates/terraform/post_create/go/iam_workforce_pool_provider.go.tmpl create mode 100644 mmv1/templates/terraform/post_create/go/iap_client.go.tmpl create mode 100644 mmv1/templates/terraform/post_create/go/index.go.tmpl create mode 100644 mmv1/templates/terraform/post_create/go/integration_connectors_connection.go.tmpl create mode 100644 mmv1/templates/terraform/post_create/go/interconnect_attachment.go.tmpl create mode 100644 mmv1/templates/terraform/post_create/go/kms_secret_ciphertext.go.tmpl create mode 100644 mmv1/templates/terraform/post_create/go/labels.tmpl create mode 100644 mmv1/templates/terraform/post_create/go/lien.tmpl create mode 100644 mmv1/templates/terraform/post_create/go/netapp_volume_replication_post_create.go.tmpl create mode 100644 mmv1/templates/terraform/post_create/go/notebooks_instance.go.tmpl create mode 100644 mmv1/templates/terraform/post_create/go/org_security_policy.go.tmpl create mode 100644 mmv1/templates/terraform/post_create/go/org_security_policy_association.go.tmpl create mode 100644 mmv1/templates/terraform/post_create/go/org_security_policy_rule.go.tmpl create mode 100644 mmv1/templates/terraform/post_create/go/private_connection.go.tmpl create mode 100644 mmv1/templates/terraform/post_create/go/privateca_certificate_authority.go.tmpl create mode 100644 mmv1/templates/terraform/post_create/go/secret_version.go.tmpl create mode 100644 mmv1/templates/terraform/post_create/go/set_computed_name.tmpl create mode 100644 mmv1/templates/terraform/post_create/go/sleep.go.tmpl create mode 100644 mmv1/templates/terraform/post_create/go/sleep_2_min.go.tmpl create mode 100644 mmv1/templates/terraform/post_create/go/source_repo_repository_update.go.tmpl create mode 100644 mmv1/templates/terraform/post_create/go/spanner_database.go.tmpl create mode 100644 mmv1/templates/terraform/post_create/go/sshkeyfingerprint.go.tmpl create mode 100644 mmv1/templates/terraform/post_create/go/storage_hmac_key.go.tmpl create mode 100644 mmv1/templates/terraform/post_create/go/workbench_instance.go.tmpl diff --git a/mmv1/templates/terraform/custom_update/go/cloud_identity_group_membership.go.tmpl b/mmv1/templates/terraform/custom_update/go/cloud_identity_group_membership.go.tmpl new file mode 100644 index 000000000000..c1105aaf3c66 --- /dev/null +++ b/mmv1/templates/terraform/custom_update/go/cloud_identity_group_membership.go.tmpl @@ -0,0 +1,137 @@ +{{- /* + The license inside this block applies to this file + Copyright 2024 Google Inc. + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/}} + userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) + if err != nil { + return err + } + + billingProject := "" + + d.Partial(true) + + if d.HasChange("roles") { + url, err := tpgresource.ReplaceVars(d, config, "{{"{{"}}CloudIdentityBasePath{{"}}"}}{{"{{"}}name{{"}}"}}:modifyMembershipRoles") + if err != nil { + return err + } + + // err == nil indicates that the billing_project value was found + if bp, err := tpgresource.GetBillingProject(d, config); err == nil { + billingProject = bp + } + + // Return object for modifyMembershipRoles (we build request object from scratch, without using `obj`) + b, a := d.GetChange("roles") + before := b.(*schema.Set) + after := a.(*schema.Set) + + ignoreUpdateR := make(map[string]struct{}) + addRoleList := after.Difference(before).List() + removeRoleList := before.Difference(after).List() + + var updateRolesParams []map[string]interface{} + for _, addR := range addRoleList { + ar := addR.(map[string]interface{})["name"].(string) + ae := addR.(map[string]interface{})["expiry_detail"].([]interface {}) + for _, removeR := range removeRoleList { + if ar == removeR.(map[string]interface{})["name"].(string) { + ignoreUpdateR[ar] = struct{}{} + var updateR map[string]interface{} + if len(ae) == 0 { + updateR = map[string]interface{}{"name": ar} + } else { + updateR = map[string]interface{}{"name": ar, "expiry_detail": ae[0]} + } + updateP := map[string]interface{}{"field_mask": "expiryDetail.expire_time", "membership_role": updateR} + updateRolesParams = append(updateRolesParams, updateP) + } + } + } + + var addRoles []map[string]interface{} + for _, r := range addRoleList { + name := r.(map[string]interface{})["name"].(string) + if _, ignore := ignoreUpdateR[name]; ignore { + continue + } + expiryDetail := r.(map[string]interface{})["expiry_detail"].([]interface {}) + if len(expiryDetail) == 0 { + addRoles = append(addRoles, map[string]interface{}{"name": name}) + } else { + addRoles = append(addRoles, map[string]interface{}{"name": name, "expiry_detail": expiryDetail[0]}) + } + } + var removeRoles []string + for _, r := range removeRoleList { + name := r.(map[string]interface{})["name"].(string) + if _, ignore := ignoreUpdateR[name]; ignore { + continue + } + removeRoles = append(removeRoles, name) + } + + // ref: https://cloud.google.com/identity/docs/reference/rest/v1/groups.memberships/modifyMembershipRoles#request-body + // Only single operation per request is allowed. + if len(removeRoles) > 0 { + res, err := transport_tpg.SendRequest(transport_tpg.SendRequestOptions{ + Config: config, + Method: "POST", + Project: billingProject, + RawURL: url, + UserAgent: userAgent, + Body: map[string]interface{}{"removeRoles": removeRoles}, + Timeout: d.Timeout(schema.TimeoutUpdate), + }) + if err != nil { + return fmt.Errorf("Error removing GroupMembership %q: %s", d.Id(), err) + } else { + log.Printf("[DEBUG] Finished removing GroupMembership %q: %#v", d.Id(), res) + } + } + if len(updateRolesParams) > 0 { + res, err := transport_tpg.SendRequest(transport_tpg.SendRequestOptions{ + Config: config, + Method: "POST", + Project: billingProject, + RawURL: url, + UserAgent: userAgent, + Body: map[string]interface{}{"updateRolesParams": updateRolesParams}, + Timeout: d.Timeout(schema.TimeoutUpdate), + }) + if err != nil { + return fmt.Errorf("Error updating GroupMembership %q: %s", d.Id(), err) + } else { + log.Printf("[DEBUG] Finished updating GroupMembership %q: %#v", d.Id(), res) + } + } + if len(addRoles) > 0 { + res, err := transport_tpg.SendRequest(transport_tpg.SendRequestOptions{ + Config: config, + Method: "POST", + Project: billingProject, + RawURL: url, + UserAgent: userAgent, + Body: map[string]interface{}{"addRoles": addRoles}, + Timeout: d.Timeout(schema.TimeoutUpdate), + }) + if err != nil { + return fmt.Errorf("Error adding GroupMembership %q: %s", d.Id(), err) + } else { + log.Printf("[DEBUG] Finished adding GroupMembership %q: %#v", d.Id(), res) + } + } + } + + d.Partial(false) + + return resourceCloudIdentityGroupMembershipRead(d, meta) diff --git a/mmv1/templates/terraform/custom_update/go/secret_version.go.tmpl b/mmv1/templates/terraform/custom_update/go/secret_version.go.tmpl new file mode 100644 index 000000000000..fcd1f4a1b159 --- /dev/null +++ b/mmv1/templates/terraform/custom_update/go/secret_version.go.tmpl @@ -0,0 +1,18 @@ +{{- /* + The license inside this block applies to this file + Copyright 2024 Google Inc. + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/}} +_, err := expandSecretManagerSecretVersionEnabled(d.Get("enabled"), d, config) +if err != nil { + return err +} + +return resourceSecretManagerSecretVersionRead(d, meta) \ No newline at end of file diff --git a/mmv1/templates/terraform/decoders/go/avoid_meaningless_project_update.tmpl b/mmv1/templates/terraform/decoders/go/avoid_meaningless_project_update.tmpl new file mode 100644 index 000000000000..533c57ce50fb --- /dev/null +++ b/mmv1/templates/terraform/decoders/go/avoid_meaningless_project_update.tmpl @@ -0,0 +1,60 @@ + // The problem we're trying to solve here is that this property is a Project, + // and there are a lot of ways to specify a Project, including the ID vs + // Number, which is something that we can't address in a diffsuppress. + // Since we can't enforce a particular method of entering the project, + // we're just going to have to use whatever the user entered, whether + // it's project/projectName, project/12345, projectName, or 12345. + // The normal behavior of this method would be 'return res' - and that's + // what we'll fall back to if any of our conditions aren't met. Those + // conditions are: + // 1) if the new or old values contain '/', the prefix of that is 'projects'. + // 2) if either is non-numeric, a project with that ID exists. + // 3) the project IDs represented by both the new and old values are the same. + config := meta.(*transport_tpg.Config) + + userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) + if err != nil { + return nil, err + } + + new := res["parent"].(string) + old := d.Get("parent").(string) + if strings.HasPrefix(new, "projects/") { + new = strings.Split(new, "/")[1] + } + if strings.HasPrefix(old, "projects/") { + old = strings.Split(old, "/")[1] + } + log.Printf("[DEBUG] Trying to figure out whether to use %s or %s", old, new) + // If there's still a '/' in there, the value must not be a project ID. + if strings.Contains(old, "/") || strings.Contains(new, "/") { + return res, nil + } + // If 'old' isn't entirely numeric, let's assume it's a project ID. + // If it's a project ID + var oldProjId int64 + var newProjId int64 + if oldVal, err := tpgresource.StringToFixed64(old); err == nil { + log.Printf("[DEBUG] The old value was a real number: %d", oldVal) + oldProjId = oldVal + } else { + pOld, err := config.NewResourceManagerClient(userAgent).Projects.Get(old).Do() + if err != nil { + return res, nil + } + oldProjId = pOld.ProjectNumber + } + if newVal, err := tpgresource.StringToFixed64(new); err == nil { + log.Printf("[DEBUG] The new value was a real number: %d", newVal) + newProjId = newVal + } else { + pNew, err := config.NewResourceManagerClient(userAgent).Projects.Get(new).Do() + if err != nil { + return res, nil + } + newProjId = pNew.ProjectNumber + } + if newProjId == oldProjId { + res["parent"] = d.Get("parent") + } + return res, nil diff --git a/mmv1/templates/terraform/decoders/go/backend_service.go.tmpl b/mmv1/templates/terraform/decoders/go/backend_service.go.tmpl new file mode 100644 index 000000000000..f61950b4226c --- /dev/null +++ b/mmv1/templates/terraform/decoders/go/backend_service.go.tmpl @@ -0,0 +1,38 @@ +{{- /* + The license inside this block applies to this file + Copyright 2024 Google Inc. + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/}} +// We need to pretend IAP isn't there if it's disabled for Terraform to maintain +// BC behaviour with the handwritten resource. +v, ok := res["iap"] +if !ok || v == nil { + delete(res, "iap") + return res, nil +} +m := v.(map[string]interface{}) +if ok && m["enabled"] == false { + delete(res, "iap") +} + +// Requests with consistentHash will error for specific values of +// localityLbPolicy. However, the API will not remove it if the backend +// service is updated to from supporting to non-supporting localityLbPolicy +// (e.g. RING_HASH to RANDOM), which causes an error on subsequent update. +// In order to prevent errors, we ignore any consistentHash returned +// from the API when the localityLbPolicy doesn't support it. +if v, ok := res["localityLbPolicy"]; ok { + lbPolicy := v.(string) + if lbPolicy != "MAGLEV" && lbPolicy != "RING_HASH" { + delete(res, "consistentHash") + } +} + +return res, nil diff --git a/mmv1/templates/terraform/decoders/go/bigquery_data_transfer.go.tmpl b/mmv1/templates/terraform/decoders/go/bigquery_data_transfer.go.tmpl new file mode 100644 index 000000000000..41564182db0c --- /dev/null +++ b/mmv1/templates/terraform/decoders/go/bigquery_data_transfer.go.tmpl @@ -0,0 +1,26 @@ +{{- /* + The license inside this block applies to this file + Copyright 2024 Google Inc. + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/}} +if paramMap, ok := res["params"]; ok { + params := paramMap.(map[string]interface{}) + for _, sp := range sensitiveParams { + if _, apiOk := params[sp]; apiOk { + if _, exists := d.GetOkExists("sensitive_params.0." + sp); exists { + delete(params, sp) + } else { + params[sp] = d.Get("params." + sp) + } + } + } +} + +return res, nil \ No newline at end of file diff --git a/mmv1/templates/terraform/decoders/go/billing_project_info.go.tmpl b/mmv1/templates/terraform/decoders/go/billing_project_info.go.tmpl new file mode 100644 index 000000000000..1d00154311e8 --- /dev/null +++ b/mmv1/templates/terraform/decoders/go/billing_project_info.go.tmpl @@ -0,0 +1,2 @@ +res["billing_account"] = strings.TrimPrefix(res["billingAccountName"].(string), "billingAccounts/") +return res, nil diff --git a/mmv1/templates/terraform/decoders/go/cloud_run.go.tmpl b/mmv1/templates/terraform/decoders/go/cloud_run.go.tmpl new file mode 100644 index 000000000000..e1c05d03d3a1 --- /dev/null +++ b/mmv1/templates/terraform/decoders/go/cloud_run.go.tmpl @@ -0,0 +1,21 @@ +{{- /* + The license inside this block applies to this file + Copyright 2024 Google Inc. + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/}} +// metadata is not present if the API returns an error +if obj, ok := res["metadata"]; ok { + if meta, ok := obj.(map[string]interface{}); ok { + res["name"] = meta["name"] + } else { + return nil, fmt.Errorf("Unable to decode 'metadata' block from API response.") + } +} +return res, nil diff --git a/mmv1/templates/terraform/decoders/go/compute_disk_resource_policies_attachment.go.tmpl b/mmv1/templates/terraform/decoders/go/compute_disk_resource_policies_attachment.go.tmpl new file mode 100644 index 000000000000..206b7ef48b3d --- /dev/null +++ b/mmv1/templates/terraform/decoders/go/compute_disk_resource_policies_attachment.go.tmpl @@ -0,0 +1,2 @@ +res["name"] = tpgresource.GetResourceNameFromSelfLink(res["name"].(string)) +return res, nil diff --git a/mmv1/templates/terraform/decoders/go/compute_network.go.tmpl b/mmv1/templates/terraform/decoders/go/compute_network.go.tmpl new file mode 100644 index 000000000000..d1dfb685ae0b --- /dev/null +++ b/mmv1/templates/terraform/decoders/go/compute_network.go.tmpl @@ -0,0 +1,2 @@ +res["numericId"] = res["id"] // stores unique id into numericId attribute before it's changed to path format +return res, nil diff --git a/mmv1/templates/terraform/decoders/go/compute_region_target_https_proxy.go.tmpl b/mmv1/templates/terraform/decoders/go/compute_region_target_https_proxy.go.tmpl new file mode 100644 index 000000000000..0a72fe1c476a --- /dev/null +++ b/mmv1/templates/terraform/decoders/go/compute_region_target_https_proxy.go.tmpl @@ -0,0 +1,15 @@ +// Since both sslCertificates and certificateManagerCertificates maps to the same API field (sslCertificates), we need to check the types +// of certificates that exist in the array and decide whether to change the field to certificateManagerCertificate or not. +// The decoder logic depends on the fact that the API does not allow mixed type of certificates and it returns +// certificate manager certificates in the format of //certificatemanager.googleapis.com/projects/*/locations/*/certificates/* +if sslCertificates, ok := res["sslCertificates"].([]interface{}); ok && len(sslCertificates) > 0 { + regPat, _ := regexp.Compile("//certificatemanager.googleapis.com/projects/(.*)/locations/(.*)/certificates/(.*)") + + if regPat.MatchString(sslCertificates[0].(string)) { + // It is enough to check only the type of one of the provided certificates beacuse all the certificates should be the same type. + log.Printf("[DEBUG] The field sslCertificates contains certificateManagerCertificates, the field name will be converted to certificateManagerCertificates") + res["certificateManagerCertificates"] = res["sslCertificates"] + delete(res, "sslCertificates") + } +} +return res, nil \ No newline at end of file diff --git a/mmv1/templates/terraform/decoders/go/compute_target_https_proxy.go.tmpl b/mmv1/templates/terraform/decoders/go/compute_target_https_proxy.go.tmpl new file mode 100644 index 000000000000..0a72fe1c476a --- /dev/null +++ b/mmv1/templates/terraform/decoders/go/compute_target_https_proxy.go.tmpl @@ -0,0 +1,15 @@ +// Since both sslCertificates and certificateManagerCertificates maps to the same API field (sslCertificates), we need to check the types +// of certificates that exist in the array and decide whether to change the field to certificateManagerCertificate or not. +// The decoder logic depends on the fact that the API does not allow mixed type of certificates and it returns +// certificate manager certificates in the format of //certificatemanager.googleapis.com/projects/*/locations/*/certificates/* +if sslCertificates, ok := res["sslCertificates"].([]interface{}); ok && len(sslCertificates) > 0 { + regPat, _ := regexp.Compile("//certificatemanager.googleapis.com/projects/(.*)/locations/(.*)/certificates/(.*)") + + if regPat.MatchString(sslCertificates[0].(string)) { + // It is enough to check only the type of one of the provided certificates beacuse all the certificates should be the same type. + log.Printf("[DEBUG] The field sslCertificates contains certificateManagerCertificates, the field name will be converted to certificateManagerCertificates") + res["certificateManagerCertificates"] = res["sslCertificates"] + delete(res, "sslCertificates") + } +} +return res, nil \ No newline at end of file diff --git a/mmv1/templates/terraform/decoders/go/containeranalysis_attestation_field_name.go.tmpl b/mmv1/templates/terraform/decoders/go/containeranalysis_attestation_field_name.go.tmpl new file mode 100644 index 000000000000..be338c044b6a --- /dev/null +++ b/mmv1/templates/terraform/decoders/go/containeranalysis_attestation_field_name.go.tmpl @@ -0,0 +1,21 @@ +{{- /* + The license inside this block applies to this file + Copyright 2024 Google Inc. + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/}} +{{- if eq $.TargetVersionName "ga" }} +// Field was renamed in GA API +res["attestationAuthority"] = res["attestation"] +delete(res, "attestation") +{{- else }} +// decoder logic only in GA provider +{{- end }} + +return res, nil diff --git a/mmv1/templates/terraform/decoders/go/containeranalysis_occurrence.go.tmpl b/mmv1/templates/terraform/decoders/go/containeranalysis_occurrence.go.tmpl new file mode 100644 index 000000000000..f246d5331eef --- /dev/null +++ b/mmv1/templates/terraform/decoders/go/containeranalysis_occurrence.go.tmpl @@ -0,0 +1,41 @@ +{{- /* + The license inside this block applies to this file + Copyright 2024 Google Inc. + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/}} +{{- if ne $.TargetVersionName "ga" }} +// Resource object was flattened in GA API +if nestedResource, ok := res["resource"]; ok { + if resObj, ok := nestedResource.(map[string]interface{}); ok { + res["resourceUri"] = resObj["uri"] + delete(res, "resource") + } +} + +// Beta attestation.attestation.genericSignedAttestation +// => GA attestation +if attV, ok := res["attestation"]; ok && attV != nil { + att := attV.(map[string]interface{}) + if nestedAttV, ok := att["attestation"]; ok && nestedAttV != nil { + nestedAtt := nestedAttV.(map[string]interface{}) + if genericV, ok := nestedAtt["genericSignedAttestation"]; ok { + genericAtt := genericV.(map[string]interface{}) + res["attestation"] = map[string]interface{}{ + "serializedPayload": genericAtt["serializedPayload"], + "signatures": genericAtt["signatures"], + } + } + } +} + +{{- else }} +// encoder logic only in non-GA version +{{- end }} +return res, nil diff --git a/mmv1/templates/terraform/decoders/go/disk.tmpl b/mmv1/templates/terraform/decoders/go/disk.tmpl new file mode 100644 index 000000000000..a5f33263f5c3 --- /dev/null +++ b/mmv1/templates/terraform/decoders/go/disk.tmpl @@ -0,0 +1,62 @@ +if v, ok := res["diskEncryptionKey"]; ok { + original := v.(map[string]interface{}) + transformed := make(map[string]interface{}) + // The raw key won't be returned, so we need to use the original. + transformed["rawKey"] = d.Get("disk_encryption_key.0.raw_key") + transformed["rsaEncryptedKey"] = d.Get("disk_encryption_key.0.rsa_encrypted_key") + transformed["sha256"] = original["sha256"] + + if kmsKeyName, ok := original["kmsKeyName"]; ok { + // The response for crypto keys often includes the version of the key which needs to be removed + // format: projects//locations//keyRings//cryptoKeys//cryptoKeyVersions/1 + transformed["kmsKeyName"] = strings.Split(kmsKeyName.(string), "/cryptoKeyVersions")[0] + } + + if kmsKeyServiceAccount, ok := original["kmsKeyServiceAccount"]; ok { + transformed["kmsKeyServiceAccount"] = kmsKeyServiceAccount + } + + res["diskEncryptionKey"] = transformed +} + +if v, ok := res["sourceImageEncryptionKey"]; ok { + original := v.(map[string]interface{}) + transformed := make(map[string]interface{}) + // The raw key won't be returned, so we need to use the original. + transformed["rawKey"] = d.Get("source_image_encryption_key.0.raw_key") + transformed["sha256"] = original["sha256"] + + if kmsKeyName, ok := original["kmsKeyName"]; ok { + // The response for crypto keys often includes the version of the key which needs to be removed + // format: projects//locations//keyRings//cryptoKeys//cryptoKeyVersions/1 + transformed["kmsKeyName"] = strings.Split(kmsKeyName.(string), "/cryptoKeyVersions")[0] + } + + if kmsKeyServiceAccount, ok := original["kmsKeyServiceAccount"]; ok { + transformed["kmsKeyServiceAccount"] = kmsKeyServiceAccount + } + + res["sourceImageEncryptionKey"] = transformed +} + +if v, ok := res["sourceSnapshotEncryptionKey"]; ok { + original := v.(map[string]interface{}) + transformed := make(map[string]interface{}) + // The raw key won't be returned, so we need to use the original. + transformed["rawKey"] = d.Get("source_snapshot_encryption_key.0.raw_key") + transformed["sha256"] = original["sha256"] + + if kmsKeyName, ok := original["kmsKeyName"]; ok { + // The response for crypto keys often includes the version of the key which needs to be removed + // format: projects//locations//keyRings//cryptoKeys//cryptoKeyVersions/1 + transformed["kmsKeyName"] = strings.Split(kmsKeyName.(string), "/cryptoKeyVersions")[0] + } + + if kmsKeyServiceAccount, ok := original["kmsKeyServiceAccount"]; ok { + transformed["kmsKeyServiceAccount"] = kmsKeyServiceAccount + } + + res["sourceSnapshotEncryptionKey"] = transformed +} + +return res, nil diff --git a/mmv1/templates/terraform/decoders/go/dlp_job_trigger.go.tmpl b/mmv1/templates/terraform/decoders/go/dlp_job_trigger.go.tmpl new file mode 100644 index 000000000000..3cda81929e95 --- /dev/null +++ b/mmv1/templates/terraform/decoders/go/dlp_job_trigger.go.tmpl @@ -0,0 +1,17 @@ +{{- /* + The license inside this block applies to this file + Copyright 2024 Google Inc. + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/}} +config := meta.(*transport_tpg.Config) +if err := d.Set("trigger_id", flattenDataLossPrevention{{$.Name}}Name(res["name"], d, config)); err != nil { + return nil, fmt.Errorf("Error reading {{$.Name}}: %s", err) +} +return res, nil diff --git a/mmv1/templates/terraform/decoders/go/dlp_stored_info_type.go.tmpl b/mmv1/templates/terraform/decoders/go/dlp_stored_info_type.go.tmpl new file mode 100644 index 000000000000..65407883b9b8 --- /dev/null +++ b/mmv1/templates/terraform/decoders/go/dlp_stored_info_type.go.tmpl @@ -0,0 +1,24 @@ +// Stored info types come back nested with previous versions. We only want the current +// version in the unwrapped form +name := res["name"].(string) +v, ok := res["currentVersion"] +if !ok || v == nil { + return nil, nil +} + +current := v.(map[string]interface{}) +configRaw, ok := current["config"] +if !ok || configRaw == nil { + return nil, nil +} + +config := configRaw.(map[string]interface{}) +// Name comes back on the top level, so set here +config["name"] = name + +configMeta := meta.(*transport_tpg.Config) +if err := d.Set("stored_info_type_id", flattenDataLossPreventionStoredInfoTypeName(res["name"], d, configMeta)); err != nil { + return nil, fmt.Errorf("Error reading StoredInfoType: %s", err) +} + +return config, nil diff --git a/mmv1/templates/terraform/decoders/go/dlp_template_id.go.tmpl b/mmv1/templates/terraform/decoders/go/dlp_template_id.go.tmpl new file mode 100644 index 000000000000..beb0a871f0ac --- /dev/null +++ b/mmv1/templates/terraform/decoders/go/dlp_template_id.go.tmpl @@ -0,0 +1,17 @@ +{{- /* + The license inside this block applies to this file + Copyright 2024 Google Inc. + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/}} +config := meta.(*transport_tpg.Config) +if err := d.Set("template_id", flattenDataLossPrevention{{$.Name}}Name(res["name"], d, config)); err != nil { + return nil, fmt.Errorf("Error reading {{$.Name}}: %s", err) +} +return res, nil diff --git a/mmv1/templates/terraform/decoders/go/firebase_database_instance.go.tmpl b/mmv1/templates/terraform/decoders/go/firebase_database_instance.go.tmpl new file mode 100644 index 000000000000..efb6a838e9b9 --- /dev/null +++ b/mmv1/templates/terraform/decoders/go/firebase_database_instance.go.tmpl @@ -0,0 +1,6 @@ +if v := res["state"]; v == "DELETED" { + return nil, nil +} +res["desired_state"] = res["state"] + +return res, nil diff --git a/mmv1/templates/terraform/decoders/go/firebasehosting_release.go.tmpl b/mmv1/templates/terraform/decoders/go/firebasehosting_release.go.tmpl new file mode 100644 index 000000000000..b6b262279b9f --- /dev/null +++ b/mmv1/templates/terraform/decoders/go/firebasehosting_release.go.tmpl @@ -0,0 +1,5 @@ +if err := d.Set("release_id", tpgresource.GetResourceNameFromSelfLink(res["name"].(string))); err != nil { + return nil, err +} + +return res, nil \ No newline at end of file diff --git a/mmv1/templates/terraform/decoders/go/firebasehosting_version.go.tmpl b/mmv1/templates/terraform/decoders/go/firebasehosting_version.go.tmpl new file mode 100644 index 000000000000..85885fe5909e --- /dev/null +++ b/mmv1/templates/terraform/decoders/go/firebasehosting_version.go.tmpl @@ -0,0 +1,5 @@ +if err := d.Set("version_id", tpgresource.GetResourceNameFromSelfLink(res["name"].(string))); err != nil { + return nil, err +} + +return res, nil \ No newline at end of file diff --git a/mmv1/templates/terraform/decoders/go/firestore_document.go.tmpl b/mmv1/templates/terraform/decoders/go/firestore_document.go.tmpl new file mode 100644 index 000000000000..6ad0249ee9c9 --- /dev/null +++ b/mmv1/templates/terraform/decoders/go/firestore_document.go.tmpl @@ -0,0 +1,21 @@ +{{- /* + The license inside this block applies to this file + Copyright 2024 Google Inc. + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/}} +// We use this decoder to add the path field +if name, ok := res["name"]; ok { + re := regexp.MustCompile("^projects/[^/]+/databases/[^/]+/documents/(.+)$") + match := re.FindStringSubmatch(name.(string)) + if len(match) > 0{ + res["path"] = match[1] + } +} +return res, nil diff --git a/mmv1/templates/terraform/decoders/go/integrations_client.go.tmpl b/mmv1/templates/terraform/decoders/go/integrations_client.go.tmpl new file mode 100644 index 000000000000..f0a1abfd8804 --- /dev/null +++ b/mmv1/templates/terraform/decoders/go/integrations_client.go.tmpl @@ -0,0 +1,4 @@ +// Since Client resource doesnt have any properties, +// Adding this decoder as placeholder else the linter will +// complain that the returned `res` is never used afterwards. +return res, nil \ No newline at end of file diff --git a/mmv1/templates/terraform/decoders/go/kms.go.tmpl b/mmv1/templates/terraform/decoders/go/kms.go.tmpl new file mode 100644 index 000000000000..a1f9936efacb --- /dev/null +++ b/mmv1/templates/terraform/decoders/go/kms.go.tmpl @@ -0,0 +1,18 @@ +{{- /* + The license inside this block applies to this file + Copyright 2024 Google Inc. + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/}} + // Modify the name to be the user specified form. + // We can't just ignore_read on `name` as the linter will + // complain that the returned `res` is never used afterwards. + // Some field needs to be actually set, and we chose `name`. + res["name"] = d.Get("name").(string) +return res, nil diff --git a/mmv1/templates/terraform/decoders/go/long_name_to_self_link.go.tmpl b/mmv1/templates/terraform/decoders/go/long_name_to_self_link.go.tmpl new file mode 100644 index 000000000000..c03ada0c8390 --- /dev/null +++ b/mmv1/templates/terraform/decoders/go/long_name_to_self_link.go.tmpl @@ -0,0 +1,22 @@ +{{- /* + The license inside this block applies to this file + Copyright 2024 Google Inc. + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/}} + // Take the returned long form of the name and use it as `self_link`. + // Then modify the name to be the user specified form. + // We can't just ignore_read on `name` as the linter will + // complain that the returned `res` is never used afterwards. + // Some field needs to be actually set, and we chose `name`. + if err := d.Set("self_link", res["name"].(string)); err != nil { + return nil, fmt.Errorf("Error setting self_link: %s", err) + } + res["name"] = d.Get("name").(string) +return res, nil diff --git a/mmv1/templates/terraform/decoders/go/monitoring_monitored_project.go.tmpl b/mmv1/templates/terraform/decoders/go/monitoring_monitored_project.go.tmpl new file mode 100644 index 000000000000..82c8ab576e83 --- /dev/null +++ b/mmv1/templates/terraform/decoders/go/monitoring_monitored_project.go.tmpl @@ -0,0 +1,48 @@ +{{- /* + The license inside this block applies to this file + Copyright 2024 Google Inc. + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/}} +// terraform resource config +config := meta.(*transport_tpg.Config) + +// The API returns all monitored projects +monitoredProjects, _ := res["monitoredProjects"].([]interface{}) + +// Convert configured terraform monitored_project resource name to a ProjectNumber +expectedProject, configProjectErr := config.NewResourceManagerClient(config.UserAgent).Projects.Get(d.Get("name").(string)).Do() +if configProjectErr != nil { + return nil, configProjectErr +} +expectedProjectNumber := strconv.FormatInt(expectedProject.ProjectNumber, 10) + +log.Printf("[DEBUG] Scanning for ProjectNumber: %s.", expectedProjectNumber) + +// Iterate through the list of monitoredProjects to make sure one matches the configured monitored_project +for _, monitoredProjectRaw := range monitoredProjects { + if monitoredProjectRaw == nil { + continue + } + monitoredProject := monitoredProjectRaw.(map[string]interface{}) + + // MonitoredProject names have the format locations/global/metricsScopes/[metricScopeProjectNumber]/projects/[projectNumber] + monitoredProjectName := monitoredProject["name"] + + // `res` contains the MonitoredProjects of the relevant metrics scope + log.Printf("[DEBUG] Matching ProjectNumbers: %s to %s.", expectedProjectNumber, monitoredProjectName) + if strings.HasSuffix(monitoredProjectName.(string), fmt.Sprintf("/%s", expectedProjectNumber)) { + // Match found - set response object name to match + res["name"] = monitoredProjectName + log.Printf("[DEBUG] Matched ProjectNumbers: %s and %s.", expectedProjectNumber, monitoredProjectName) + return res, nil + } +} +log.Printf("[DEBUG] MonitoringMonitoredProject couldn't be matched.") +return nil, nil diff --git a/mmv1/templates/terraform/decoders/go/monitoring_notification_channel.go.tmpl b/mmv1/templates/terraform/decoders/go/monitoring_notification_channel.go.tmpl new file mode 100644 index 000000000000..e5fad1a3ecf8 --- /dev/null +++ b/mmv1/templates/terraform/decoders/go/monitoring_notification_channel.go.tmpl @@ -0,0 +1,26 @@ +{{- /* + The license inside this block applies to this file + Copyright 2024 Google Inc. + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/}} +if labelmap, ok := res["labels"]; ok { + labels := labelmap.(map[string]interface{}) + for _, sl := range sensitiveLabels { + if _, apiOk := labels[sl]; apiOk { + if _, exists := d.GetOkExists("sensitive_labels.0." + sl); exists { + delete(labels, sl) + } else { + labels[sl] = d.Get("labels." + sl) + } + } + } +} + +return res, nil \ No newline at end of file diff --git a/mmv1/templates/terraform/decoders/go/network_endpoint.go.tmpl b/mmv1/templates/terraform/decoders/go/network_endpoint.go.tmpl new file mode 100644 index 000000000000..8f14dc675325 --- /dev/null +++ b/mmv1/templates/terraform/decoders/go/network_endpoint.go.tmpl @@ -0,0 +1,18 @@ +{{- /* + The license inside this block applies to this file + Copyright 2024 Google Inc. + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/}} +v, ok := res["networkEndpoint"] +if !ok || v == nil { + return res, nil +} + +return v.(map[string]interface{}), nil diff --git a/mmv1/templates/terraform/decoders/go/network_endpoints.go.tmpl b/mmv1/templates/terraform/decoders/go/network_endpoints.go.tmpl new file mode 100644 index 000000000000..663a3175d5da --- /dev/null +++ b/mmv1/templates/terraform/decoders/go/network_endpoints.go.tmpl @@ -0,0 +1,54 @@ +{{- /* + The license inside this block applies to this file + Copyright 2024 Google Inc. + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/}} +config := meta.(*transport_tpg.Config) +userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) +if err != nil { + return nil, err +} + +url, err := tpgresource.ReplaceVars(d, config, "{{"{{"}}ComputeBasePath{{"}}"}}projects/{{"{{"}}project{{"}}"}}/zones/{{"{{"}}zone{{"}}"}}/networkEndpointGroups/{{"{{"}}network_endpoint_group{{"}}"}}/listNetworkEndpoints") +if err != nil { + return nil, err +} + +billingProject := "" + +project, err := tpgresource.GetProject(d, config) +if err != nil { + return nil, fmt.Errorf("Error fetching project for NetworkEndpoint: %s", err) +} +billingProject = project + +// err == nil indicates that the billing_project value was found +if bp, err := tpgresource.GetBillingProject(d, config); err == nil { + billingProject = bp +} +// Read past the first page to get all endpoints. +pt, _ := res["nextPageToken"].(string) +allEndpoints, err := networkEndpointsPaginatedRead(d, config, userAgent, url, project, billingProject, pt) +if err != nil { + // networkEndpointsPaginatedRead already adds error description + return nil, err +} +firstPage := res["items"].([]interface{}) +allEndpoints = append(firstPage, allEndpoints...) + +// listNetworkEndpoints returns data in a different structure, so we need to +// convert to the Terraform schema. +var transformed []interface{} +for _, e := range allEndpoints { + t := e.(map[string]interface{})["networkEndpoint"] + transformed = append(transformed, t) +} + +return map[string]interface{}{"networkEndpoints": transformed}, nil \ No newline at end of file diff --git a/mmv1/templates/terraform/decoders/go/noop.go.tmpl b/mmv1/templates/terraform/decoders/go/noop.go.tmpl new file mode 100644 index 000000000000..5bbb7131eb35 --- /dev/null +++ b/mmv1/templates/terraform/decoders/go/noop.go.tmpl @@ -0,0 +1 @@ +return res, nil diff --git a/mmv1/templates/terraform/decoders/go/os_config_patch_deployment.go.tmpl b/mmv1/templates/terraform/decoders/go/os_config_patch_deployment.go.tmpl new file mode 100644 index 000000000000..fce9e9366fc3 --- /dev/null +++ b/mmv1/templates/terraform/decoders/go/os_config_patch_deployment.go.tmpl @@ -0,0 +1,9 @@ +if res["patchConfig"] != nil { + patchConfig := res["patchConfig"].(map[string]interface{}) + if patchConfig["goo"] != nil { + patchConfig["goo"].(map[string]interface{})["enabled"] = true + res["patchConfig"] = patchConfig + } +} + +return res, nil diff --git a/mmv1/templates/terraform/decoders/go/private_cloud.go.tmpl b/mmv1/templates/terraform/decoders/go/private_cloud.go.tmpl new file mode 100644 index 000000000000..99bb7f71b831 --- /dev/null +++ b/mmv1/templates/terraform/decoders/go/private_cloud.go.tmpl @@ -0,0 +1,54 @@ +config := meta.(*transport_tpg.Config) + +userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) +if err != nil { + return nil, err +} + +url, err := tpgresource.ReplaceVars(d, config, "{{"{{"}}VmwareengineBasePath{{"}}"}}projects/{{"{{"}}project{{"}}"}}/locations/{{"{{"}}location{{"}}"}}/privateClouds/{{"{{"}}name{{"}}"}}/clusters") +if err != nil { + return nil, err +} + +url, err = transport_tpg.AddQueryParams(url, map[string]string{"filter": "management=true"}) +if err != nil { + return nil, err +} + +billingProject := "" + +project, err := tpgresource.GetProject(d, config) +if err != nil { + return nil, fmt.Errorf("Error fetching project for Instance: %s", err) +} + +billingProject = project + +// err == nil indicates that the billing_project value was found +if bp, err := tpgresource.GetBillingProject(d, config); err == nil { + billingProject = bp +} + +clusterResponse, err := transport_tpg.SendRequest(transport_tpg.SendRequestOptions{ + Config: config, + Method: "GET", + Project: billingProject, + RawURL: url, + UserAgent: userAgent, +}) + +if err != nil { + return nil, fmt.Errorf("Error reading management cluster of PrivateCloud: %s", err) +} + +// There can only be 1 management cluster and if the PC read is successfuly and +// we got response from cluster API then it should be present. +mgmtClusterObj := clusterResponse["clusters"].([]interface{})[0].(map[string]interface{}) +clusterName := mgmtClusterObj["name"].(string) +// get clusterId from the full name, clusterName is "projects/project/locations/location/privateClouds/pc/clusters/cls" +// then clusterId will be "cls" +mgmtClusterObj["clusterId"] = clusterName[strings.LastIndex(clusterName, "/")+1:] + +res["managementCluster"] = mgmtClusterObj + +return res, nil \ No newline at end of file diff --git a/mmv1/templates/terraform/decoders/go/redis_instance.go.tmpl b/mmv1/templates/terraform/decoders/go/redis_instance.go.tmpl new file mode 100644 index 000000000000..148c3a0efd42 --- /dev/null +++ b/mmv1/templates/terraform/decoders/go/redis_instance.go.tmpl @@ -0,0 +1,50 @@ +config := meta.(*transport_tpg.Config) + +userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) +if err != nil { + return nil, err +} + +if v, ok := res["authEnabled"].(bool); ok { + if v { + url, err := tpgresource.ReplaceVars(d, config, "{{"{{"}}RedisBasePath{{"}}"}}projects/{{"{{"}}project{{"}}"}}/locations/{{"{{"}}region{{"}}"}}/instances/{{"{{"}}name{{"}}"}}/authString") + if err != nil { + return nil, err + } + + billingProject := "" + + project, err := tpgresource.GetProject(d, config) + if err != nil { + return nil, fmt.Errorf("Error fetching project for Instance: %s", err) + } + + billingProject = project + + // err == nil indicates that the billing_project value was found + if bp, err := tpgresource.GetBillingProject(d, config); err == nil { + billingProject = bp + } + + res, err := transport_tpg.SendRequest(transport_tpg.SendRequestOptions{ + Config: config, + Method: "GET", + Project: billingProject, + RawURL: url, + UserAgent: userAgent, + }) + if err != nil { + return nil, fmt.Errorf("Error reading AuthString: %s", err) + } + + if err := d.Set("auth_string", res["authString"]); err != nil { + return nil, fmt.Errorf("Error reading Instance: %s", err) + } + } +} else { + if err := d.Set("auth_string", ""); err != nil { + return nil, fmt.Errorf("Error reading Instance: %s", err) + } +} + +return res, nil \ No newline at end of file diff --git a/mmv1/templates/terraform/decoders/go/region_backend_service.go.tmpl b/mmv1/templates/terraform/decoders/go/region_backend_service.go.tmpl new file mode 100644 index 000000000000..a5115fb455ae --- /dev/null +++ b/mmv1/templates/terraform/decoders/go/region_backend_service.go.tmpl @@ -0,0 +1,51 @@ +{{- /* + The license inside this block applies to this file + Copyright 2024 Google Inc. + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/}} +// We need to pretend IAP isn't there if it's disabled for Terraform to maintain +// BC behaviour with the handwritten resource. +v, ok := res["iap"] +if !ok || v == nil { + delete(res, "iap") + return res, nil +} +m := v.(map[string]interface{}) +if ok && m["enabled"] == false { + delete(res, "iap") +} + +{{- if ne $.TargetVersionName "ga" }} +// Since we add in a NONE subsetting policy, we need to remove it in some +// cases for backwards compatibility with the config +v, ok = res["subsetting"] +if ok && v != nil { + subsetting := v.(map[string]interface{}) + policy, ok := subsetting["policy"] + if ok && policy == "NONE" { + delete(res, "subsetting") + } +} +{{- end }} + +// Requests with consistentHash will error for specific values of +// localityLbPolicy. However, the API will not remove it if the backend +// service is updated to from supporting to non-supporting localityLbPolicy +// (e.g. RING_HASH to RANDOM), which causes an error on subsequent update. +// In order to prevent errors, we ignore any consistentHash returned +// from the API when the localityLbPolicy doesn't support it. +if v, ok := res["localityLbPolicy"]; ok { + lbPolicy := v.(string) + if lbPolicy != "MAGLEV" && lbPolicy != "RING_HASH" { + delete(res, "consistentHash") + } +} + +return res, nil diff --git a/mmv1/templates/terraform/decoders/go/route.tmpl b/mmv1/templates/terraform/decoders/go/route.tmpl new file mode 100644 index 000000000000..a2eef2bc1f43 --- /dev/null +++ b/mmv1/templates/terraform/decoders/go/route.tmpl @@ -0,0 +1,12 @@ +if v, ok := res["nextHopInstance"]; ok { + val, err := tpgresource.ParseZonalFieldValue("instances", v.(string), "project", "next_hop_instance_zone", d, meta.(*transport_tpg.Config), true) + if err != nil { + return nil, err + } + if err := d.Set("next_hop_instance_zone", val.Zone); err != nil { + return nil, fmt.Errorf("Error setting next_hop_instance_zone: %s", err) + } + res["nextHopInstance"] = val.RelativeLink() +} + +return res, nil diff --git a/mmv1/templates/terraform/decoders/go/snapshot.go.tmpl b/mmv1/templates/terraform/decoders/go/snapshot.go.tmpl new file mode 100644 index 000000000000..f12238dabb2f --- /dev/null +++ b/mmv1/templates/terraform/decoders/go/snapshot.go.tmpl @@ -0,0 +1,53 @@ +{{- /* + The license inside this block applies to this file + Copyright 2024 Google Inc. + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/}} +if v, ok := res["snapshotEncryptionKey"]; ok { + original := v.(map[string]interface{}) + transformed := make(map[string]interface{}) + // The raw key won't be returned, so we need to use the original. + transformed["rawKey"] = d.Get("snapshot_encryption_key.0.raw_key") + transformed["sha256"] = original["sha256"] + + if kmsKeyName, ok := original["kmsKeyName"]; ok { + // The response for crypto keys often includes the version of the key which needs to be removed + // format: projects//locations//keyRings//cryptoKeys//cryptoKeyVersions/1 + transformed["kmsKeyName"] = strings.Split(kmsKeyName.(string), "/cryptoKeyVersions")[0] + } + + if kmsKeyServiceAccount, ok := original["kmsKeyServiceAccount"]; ok { + transformed["kmsKeyServiceAccount"] = kmsKeyServiceAccount + } + + res["snapshotEncryptionKey"] = transformed +} + +if v, ok := res["sourceDiskEncryptionKey"]; ok { + original := v.(map[string]interface{}) + transformed := make(map[string]interface{}) + // The raw key won't be returned, so we need to use the original. + transformed["rawKey"] = d.Get("source_disk_encryption_key.0.raw_key") + transformed["sha256"] = original["sha256"] + + if kmsKeyName, ok := original["kmsKeyName"]; ok { + // The response for crypto keys often includes the version of the key which needs to be removed + // format: projects//locations//keyRings//cryptoKeys//cryptoKeyVersions/1 + transformed["kmsKeyName"] = strings.Split(kmsKeyName.(string), "/cryptoKeyVersions")[0] + } + + if kmsKeyServiceAccount, ok := original["kmsKeyServiceAccount"]; ok { + transformed["kmsKeyServiceAccount"] = kmsKeyServiceAccount + } + + res["sourceDiskEncryptionKey"] = transformed +} + +return res, nil diff --git a/mmv1/templates/terraform/decoders/go/spanner_database.go.tmpl b/mmv1/templates/terraform/decoders/go/spanner_database.go.tmpl new file mode 100644 index 000000000000..c1b4cba3b249 --- /dev/null +++ b/mmv1/templates/terraform/decoders/go/spanner_database.go.tmpl @@ -0,0 +1,14 @@ +config := meta.(*transport_tpg.Config) +d.SetId(res["name"].(string)) +if err := tpgresource.ParseImportId([]string{"projects/(?P[^/]+)/instances/(?P[^/]+)/databases/(?P[^/]+)"}, d, config); err != nil { + return nil, err +} +res["project"] = d.Get("project").(string) +res["instance"] = d.Get("instance").(string) +res["name"] = d.Get("name").(string) +id, err := tpgresource.ReplaceVars(d, config, "{{"{{"}}instance{{"}}"}}/{{"{{"}}name{{"}}"}}") +if err != nil { + return nil, err +} +d.SetId(id) +return res, nil diff --git a/mmv1/templates/terraform/decoders/go/spanner_instance.go.tmpl b/mmv1/templates/terraform/decoders/go/spanner_instance.go.tmpl new file mode 100644 index 000000000000..ee871f377d2a --- /dev/null +++ b/mmv1/templates/terraform/decoders/go/spanner_instance.go.tmpl @@ -0,0 +1,13 @@ +config := meta.(*transport_tpg.Config) +d.SetId(res["name"].(string)) +if err := tpgresource.ParseImportId([]string{"projects/(?P[^/]+)/instances/(?P[^/]+)"}, d, config); err != nil { + return nil, err +} +res["project"] = d.Get("project").(string) +res["name"] = d.Get("name").(string) +id, err := tpgresource.ReplaceVars(d, config, "{{"{{"}}project{{"}}"}}/{{"{{"}}name{{"}}"}}") +if err != nil { + return nil, err +} +d.SetId(id) +return res, nil diff --git a/mmv1/templates/terraform/decoders/go/sql_source_representation_instance.go.tmpl b/mmv1/templates/terraform/decoders/go/sql_source_representation_instance.go.tmpl new file mode 100644 index 000000000000..381e1903c103 --- /dev/null +++ b/mmv1/templates/terraform/decoders/go/sql_source_representation_instance.go.tmpl @@ -0,0 +1,28 @@ +{{- /* + The license inside this block applies to this file + Copyright 2024 Google Inc. + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/}} +if v, ok := res["onPremisesConfiguration"]; ok { + opc := v.(map[string]interface{}) + hostPort := opc["hostPort"] + spl := strings.Split(hostPort.(string), ":") + if len(spl) != 2 { + return nil, fmt.Errorf("unexpected value for hostPort, expected [host]:[port], got %q", hostPort) + } + opc["host"] = spl[0] + p, err := strconv.Atoi(spl[1]) + if err != nil { + return nil, fmt.Errorf("error converting port %q to int: %v", spl[1], err) + } + opc["port"] = p + delete(opc, "hostPort") +} +return res, nil \ No newline at end of file diff --git a/mmv1/templates/terraform/decoders/go/treat_deleted_state_as_gone.go.tmpl b/mmv1/templates/terraform/decoders/go/treat_deleted_state_as_gone.go.tmpl new file mode 100644 index 000000000000..85855239db2d --- /dev/null +++ b/mmv1/templates/terraform/decoders/go/treat_deleted_state_as_gone.go.tmpl @@ -0,0 +1,5 @@ +if v := res["state"]; v == "DELETED" { + return nil, nil +} + +return res, nil diff --git a/mmv1/templates/terraform/decoders/go/treat_destroyed_state_as_gone.tmpl b/mmv1/templates/terraform/decoders/go/treat_destroyed_state_as_gone.tmpl new file mode 100644 index 000000000000..2a75e3922480 --- /dev/null +++ b/mmv1/templates/terraform/decoders/go/treat_destroyed_state_as_gone.tmpl @@ -0,0 +1,17 @@ +{{- /* + The license inside this block applies to this file + Copyright 2024 Google Inc. + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/}} +if v := res["state"]; v == "DESTROYED" { + return nil, nil +} + +return res, nil \ No newline at end of file diff --git a/mmv1/templates/terraform/decoders/go/unwrap_global_neg.go.tmpl b/mmv1/templates/terraform/decoders/go/unwrap_global_neg.go.tmpl new file mode 100644 index 000000000000..8f14dc675325 --- /dev/null +++ b/mmv1/templates/terraform/decoders/go/unwrap_global_neg.go.tmpl @@ -0,0 +1,18 @@ +{{- /* + The license inside this block applies to this file + Copyright 2024 Google Inc. + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/}} +v, ok := res["networkEndpoint"] +if !ok || v == nil { + return res, nil +} + +return v.(map[string]interface{}), nil diff --git a/mmv1/templates/terraform/decoders/go/unwrap_resource.go.tmpl b/mmv1/templates/terraform/decoders/go/unwrap_resource.go.tmpl new file mode 100644 index 000000000000..7a798ecda836 --- /dev/null +++ b/mmv1/templates/terraform/decoders/go/unwrap_resource.go.tmpl @@ -0,0 +1,18 @@ +{{- /* + The license inside this block applies to this file + Copyright 2024 Google Inc. + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/}} +v, ok := res["{{camelize $.Name "lower"}}"] +if !ok || v == nil { + return res, nil +} + +return v.(map[string]interface{}), nil diff --git a/mmv1/templates/terraform/encoders/cloud_run_domain_mapping.go.erb b/mmv1/templates/terraform/encoders/cloud_run_domain_mapping.go.erb index 5b382bc4053e..b368b7f79990 100644 --- a/mmv1/templates/terraform/encoders/cloud_run_domain_mapping.go.erb +++ b/mmv1/templates/terraform/encoders/cloud_run_domain_mapping.go.erb @@ -18,5 +18,5 @@ metadata["name"] = name // The only acceptable version/kind right now obj["apiVersion"] = "domains.cloudrun.com/v1" -obj["kind"] = "<%= "#{object.name}" -%>" +obj["kind"] = "<%= object.name -%>" return obj, nil diff --git a/mmv1/templates/terraform/encoders/disk.erb b/mmv1/templates/terraform/encoders/disk.erb index 55dd63d40757..ec80bb4a000a 100644 --- a/mmv1/templates/terraform/encoders/disk.erb +++ b/mmv1/templates/terraform/encoders/disk.erb @@ -34,11 +34,9 @@ if v, ok := d.GetOk("type"); ok { obj["type"] = diskType.RelativeLink() } -<% -else - raise 'disk.erb included in non-disk type #{object.name}' -end --%> +<% else -%> + raise 'disk.erb included in non-disk type <%= object.name -%>' +<% end -%> if v, ok := d.GetOk("image"); ok { log.Printf("[DEBUG] Resolving image name: %s", v.(string)) diff --git a/mmv1/templates/terraform/encoders/go/access_level_never_send_parent.go.tmpl b/mmv1/templates/terraform/encoders/go/access_level_never_send_parent.go.tmpl new file mode 100644 index 000000000000..7fc837505699 --- /dev/null +++ b/mmv1/templates/terraform/encoders/go/access_level_never_send_parent.go.tmpl @@ -0,0 +1,14 @@ +{{- /* + The license inside this block applies to this file + Copyright 2024 Google Inc. + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/}} +delete(obj, "parent") +return obj, nil diff --git a/mmv1/templates/terraform/encoders/go/active_directory_domain_trust.go.tmpl b/mmv1/templates/terraform/encoders/go/active_directory_domain_trust.go.tmpl new file mode 100644 index 000000000000..ab6867c3163f --- /dev/null +++ b/mmv1/templates/terraform/encoders/go/active_directory_domain_trust.go.tmpl @@ -0,0 +1,17 @@ +{{- /* + The license inside this block applies to this file + Copyright 2024 Google Inc. + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/}} + +wrappedReq := map[string]interface{}{ + "trust": obj, +} +return wrappedReq, nil diff --git a/mmv1/templates/terraform/encoders/go/alloydb_backup.tmpl b/mmv1/templates/terraform/encoders/go/alloydb_backup.tmpl new file mode 100644 index 000000000000..9152c151078f --- /dev/null +++ b/mmv1/templates/terraform/encoders/go/alloydb_backup.tmpl @@ -0,0 +1,3 @@ +// The only other available type is AUTOMATED which cannot be set manually +obj["type"] = "ON_DEMAND" +return obj, nil \ No newline at end of file diff --git a/mmv1/templates/terraform/encoders/go/api_config.go.tmpl b/mmv1/templates/terraform/encoders/go/api_config.go.tmpl new file mode 100644 index 000000000000..39d38b3d715c --- /dev/null +++ b/mmv1/templates/terraform/encoders/go/api_config.go.tmpl @@ -0,0 +1,13 @@ +var apiConfigId string +if v, ok := d.GetOk("api_config_id"); ok { + apiConfigId = v.(string) +} else if v, ok := d.GetOk("api_config_id_prefix"); ok { + apiConfigId = resource.PrefixedUniqueId(v.(string)) +} else { + apiConfigId = resource.UniqueId() +} + +if err := d.Set("api_config_id", apiConfigId); err != nil { + return nil, fmt.Errorf("Error setting api_config_id: %s", err) +} +return obj, nil \ No newline at end of file diff --git a/mmv1/templates/terraform/encoders/go/apigee_organization.go.tmpl b/mmv1/templates/terraform/encoders/go/apigee_organization.go.tmpl new file mode 100644 index 000000000000..03c99cada236 --- /dev/null +++ b/mmv1/templates/terraform/encoders/go/apigee_organization.go.tmpl @@ -0,0 +1,2 @@ +obj["name"] = d.Get("project_id").(string) +return obj, nil diff --git a/mmv1/templates/terraform/encoders/go/backend_service.go.tmpl b/mmv1/templates/terraform/encoders/go/backend_service.go.tmpl new file mode 100644 index 000000000000..2010d4d0d522 --- /dev/null +++ b/mmv1/templates/terraform/encoders/go/backend_service.go.tmpl @@ -0,0 +1,85 @@ +{{- /* + The license inside this block applies to this file + Copyright 2024 Google Inc. + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/}} +// 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 +} +backends := backendsRaw.([]interface{}) +for _, backendRaw := range backends { + backend := backendRaw.(map[string]interface{}) + + if isNegBackend(backend) { + // Remove `max_utilization` from any backend that belongs to an NEG. This field + // has a default value and causes API validation errors + backend["maxUtilization"] = nil + } +} + +// This custom encoding helps prevent sending 0 for clientTtl, defaultTtl and +// maxTtl in API calls to update these values when unset in the provider +// (doing so results in an API level error) +c, cdnPolicyOk := d.GetOk("cdn_policy") + +// Only apply during updates +if !cdnPolicyOk || obj["cdnPolicy"] == nil { + return obj, nil +} + +currentCdnPolicies := c.([]interface{}) + +// state does not contain cdnPolicy, so we can return early here as well +if len(currentCdnPolicies) == 0 { + return obj, nil +} + +futureCdnPolicy := obj["cdnPolicy"].(map[string]interface{}) +currentCdnPolicy := currentCdnPolicies[0].(map[string]interface{}) + +cacheMode, ok := futureCdnPolicy["cache_mode"].(string) +// Fallback to state if doesn't exist in object +if !ok { + cacheMode = currentCdnPolicy["cache_mode"].(string) +} + +switch cacheMode { +case "USE_ORIGIN_HEADERS": + if _, ok := futureCdnPolicy["clientTtl"]; ok { + delete(futureCdnPolicy, "clientTtl") + } + if _, ok := futureCdnPolicy["defaultTtl"]; ok { + delete(futureCdnPolicy, "defaultTtl") + } + if _, ok := futureCdnPolicy["maxTtl"]; ok { + delete(futureCdnPolicy, "maxTtl") + } +} + +return obj, nil diff --git a/mmv1/templates/terraform/encoders/go/bigquery_connection.go.tmpl b/mmv1/templates/terraform/encoders/go/bigquery_connection.go.tmpl new file mode 100644 index 000000000000..13bb5b3f7cff --- /dev/null +++ b/mmv1/templates/terraform/encoders/go/bigquery_connection.go.tmpl @@ -0,0 +1,3 @@ + // connection_id is needed to qualify the URL but cannot be sent in the body + delete(obj, "connection_id") + return obj, nil \ No newline at end of file diff --git a/mmv1/templates/terraform/encoders/go/bigquery_data_transfer.go.tmpl b/mmv1/templates/terraform/encoders/go/bigquery_data_transfer.go.tmpl new file mode 100644 index 000000000000..9b790f9795e6 --- /dev/null +++ b/mmv1/templates/terraform/encoders/go/bigquery_data_transfer.go.tmpl @@ -0,0 +1,29 @@ +{{- /* + The license inside this block applies to this file + Copyright 2024 Google Inc. + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/}} +paramMap, ok := obj["params"] +if !ok { + paramMap = make(map[string]string) +} + +var params map[string]string +params = paramMap.(map[string]string) + +for _, sp := range sensitiveParams { + if auth, _ := d.GetOkExists("sensitive_params.0." + sp); auth != "" { + params[sp] = auth.(string) + } +} + +obj["params"] = params + +return obj, nil \ No newline at end of file diff --git a/mmv1/templates/terraform/encoders/go/bigquery_job.go.tmpl b/mmv1/templates/terraform/encoders/go/bigquery_job.go.tmpl new file mode 100644 index 000000000000..f9f9dc1b3f09 --- /dev/null +++ b/mmv1/templates/terraform/encoders/go/bigquery_job.go.tmpl @@ -0,0 +1,18 @@ +{{- /* + The license inside this block applies to this file + Copyright 2024 Google Inc. + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/}} +project, err := tpgresource.GetProject(d, meta.(*transport_tpg.Config)) +if err != nil { + return nil, err +} +obj["jobReference"].(map[string]interface{})["project"] = project +return obj, nil \ No newline at end of file diff --git a/mmv1/templates/terraform/encoders/go/bigtable_app_profile.go.tmpl b/mmv1/templates/terraform/encoders/go/bigtable_app_profile.go.tmpl new file mode 100644 index 000000000000..95655c650282 --- /dev/null +++ b/mmv1/templates/terraform/encoders/go/bigtable_app_profile.go.tmpl @@ -0,0 +1,20 @@ +{{- /* + The license inside this block applies to this file + Copyright 2024 Google Inc. + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/}} +{{- /* Because instance is a URL param only, it does not get expanded and + # the URL is constructed from ResourceData. Set it in + # state and use a encoder instead of a field expander */}} +// Instance is a URL parameter only, so replace self-link/path with resource name only. +if err := d.Set("instance", tpgresource.GetResourceNameFromSelfLink(d.Get("instance").(string))); err != nil { + return nil, fmt.Errorf("Error setting instance: %s", err) +} +return obj, nil \ No newline at end of file diff --git a/mmv1/templates/terraform/encoders/go/billing_project_info.go.tmpl b/mmv1/templates/terraform/encoders/go/billing_project_info.go.tmpl new file mode 100644 index 000000000000..1928c246a990 --- /dev/null +++ b/mmv1/templates/terraform/encoders/go/billing_project_info.go.tmpl @@ -0,0 +1,8 @@ +ba := d.Get("billing_account").(string) +if ba == "" { + obj["billingAccountName"] = "" +} else { + obj["billingAccountName"] = "billingAccounts/" + ba +} +delete(obj, "billing_account") +return obj, nil diff --git a/mmv1/templates/terraform/encoders/go/cloud_asset_feed.go.tmpl b/mmv1/templates/terraform/encoders/go/cloud_asset_feed.go.tmpl new file mode 100644 index 000000000000..f18150458cb5 --- /dev/null +++ b/mmv1/templates/terraform/encoders/go/cloud_asset_feed.go.tmpl @@ -0,0 +1,10 @@ +// Remove the "folders/" prefix from the folder ID +if folder, ok := d.GetOkExists("folder"); ok { + if err := d.Set("folder_id", strings.TrimPrefix(folder.(string), "folders/")); err != nil { + return nil, fmt.Errorf("Error setting folder_id: %s", err) + } +} +// The feed object must be under the "feed" attribute on the request. +newObj := make(map[string]interface{}) +newObj["feed"] = obj +return newObj, nil \ No newline at end of file diff --git a/mmv1/templates/terraform/encoders/go/cloud_run_domain_mapping.go.tmpl b/mmv1/templates/terraform/encoders/go/cloud_run_domain_mapping.go.tmpl new file mode 100644 index 000000000000..6a8c49c77d12 --- /dev/null +++ b/mmv1/templates/terraform/encoders/go/cloud_run_domain_mapping.go.tmpl @@ -0,0 +1,20 @@ +{{- /* + The license inside this block applies to this file + Copyright 2024 Google Inc. + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/}} +name := d.Get("name").(string) +metadata := obj["metadata"].(map[string]interface{}) +metadata["name"] = name + +// The only acceptable version/kind right now +obj["apiVersion"] = "domains.cloudrun.com/v1" +obj["kind"] = "{{$.Name}}" +return obj, nil diff --git a/mmv1/templates/terraform/encoders/go/cloud_run_service.go.tmpl b/mmv1/templates/terraform/encoders/go/cloud_run_service.go.tmpl new file mode 100644 index 000000000000..931fcc3d8b7a --- /dev/null +++ b/mmv1/templates/terraform/encoders/go/cloud_run_service.go.tmpl @@ -0,0 +1,23 @@ +{{- /* + The license inside this block applies to this file + Copyright 2024 Google Inc. + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/}} +name := d.Get("name").(string) +if obj["metadata"] == nil { + obj["metadata"] = make(map[string]interface{}) +} +metadata := obj["metadata"].(map[string]interface{}) +metadata["name"] = name + +// The only acceptable version/kind right now +obj["apiVersion"] = "serving.knative.dev/v1" +obj["kind"] = "Service" +return obj, nil diff --git a/mmv1/templates/terraform/encoders/go/cloud_scheduler.go.tmpl b/mmv1/templates/terraform/encoders/go/cloud_scheduler.go.tmpl new file mode 100644 index 000000000000..8a9b4e7e9da9 --- /dev/null +++ b/mmv1/templates/terraform/encoders/go/cloud_scheduler.go.tmpl @@ -0,0 +1,2 @@ +delete(obj, "paused") // Field doesn't exist in API +return obj, nil \ No newline at end of file diff --git a/mmv1/templates/terraform/encoders/go/cloudbuild_bitbucketserver_config.go.tmpl b/mmv1/templates/terraform/encoders/go/cloudbuild_bitbucketserver_config.go.tmpl new file mode 100644 index 000000000000..5b34ac221e68 --- /dev/null +++ b/mmv1/templates/terraform/encoders/go/cloudbuild_bitbucketserver_config.go.tmpl @@ -0,0 +1,3 @@ +// connectedRepositories is needed for batchCreate on the config after creation. +delete(obj, "connectedRepositories") +return obj, nil diff --git a/mmv1/templates/terraform/encoders/go/cloudbuildv2_repository.go.tmpl b/mmv1/templates/terraform/encoders/go/cloudbuildv2_repository.go.tmpl new file mode 100644 index 000000000000..6b7753d1833c --- /dev/null +++ b/mmv1/templates/terraform/encoders/go/cloudbuildv2_repository.go.tmpl @@ -0,0 +1,35 @@ +{{- /* + The license inside this block applies to this file + Copyright 2024 Google Inc. + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/}} +config := meta.(*transport_tpg.Config) +// Extract any empty fields from the parent_connection field. +project, err := tpgresource.GetProject(d, config) +if err != nil { + return nil, fmt.Errorf("error getting project: %s", err) +} +parent_connection := d.Get("parent_connection").(string) +project, err = tpgresource.ExtractFieldByPattern("project", project, parent_connection, "projects/([a-z0-9A-Z-]*)/locations/.*") +if err != nil { + return nil, fmt.Errorf("error extracting project field: %s", err) +} +location := d.Get("location").(string) +location, err = tpgresource.ExtractFieldByPattern("location", location, parent_connection, "projects/[a-z0-9A-Z-]*/locations/([a-z0-9-]*)/connections/.*") +if err != nil { + return nil, fmt.Errorf("error extracting location field: %s", err) +} +// Set project to the extracted value. +d.Set("project", project) +// Set all the other fields to their short forms before forming url and setting ID. +name := d.Get("name").(string) +d.Set("location", location) +d.Set("name", name) +return obj, nil diff --git a/mmv1/templates/terraform/encoders/go/clouddomains_registration.go.tmpl b/mmv1/templates/terraform/encoders/go/clouddomains_registration.go.tmpl new file mode 100644 index 000000000000..b816af3ec4c9 --- /dev/null +++ b/mmv1/templates/terraform/encoders/go/clouddomains_registration.go.tmpl @@ -0,0 +1,28 @@ +{{- /* + The license inside this block applies to this file + Copyright 2024 Google Inc. + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/}} + +// Request body is registration object with additional fields +// See https://cloud.google.com/domains/docs/reference/rest/v1beta1/projects.locations.registrations/register + +newObj := make(map[string]interface{}) + +newObj["domainNotices"] = obj["domainNotices"] +delete(obj, "domainNotices") +newObj["contactNotices"] = obj["contactNotices"] +delete(obj, "contactNotices") +newObj["yearlyPrice"] = obj["yearlyPrice"] +delete(obj, "yearlyPrice") + +newObj["registration"] = obj + +return newObj, nil \ No newline at end of file diff --git a/mmv1/templates/terraform/encoders/go/compute_backend_bucket.go.tmpl b/mmv1/templates/terraform/encoders/go/compute_backend_bucket.go.tmpl new file mode 100644 index 000000000000..57e75f87adcd --- /dev/null +++ b/mmv1/templates/terraform/encoders/go/compute_backend_bucket.go.tmpl @@ -0,0 +1,44 @@ +// This custom encoder helps prevent sending 0 for clientTtl, defaultTtl and +// maxTtl in API calls to update these values when unset in the provider +// (doing so results in an API level error) +c, cdnPolicyOk := d.GetOk("cdn_policy") + +// Only apply during updates +if !cdnPolicyOk || obj["cdnPolicy"] == nil { + return obj, nil +} + +currentCdnPolicies := c.([]interface{}) + +// state does not contain cdnPolicy, so we can return early here as well +if len(currentCdnPolicies) == 0 { + return obj, nil +} + +futureCdnPolicy := obj["cdnPolicy"].(map[string]interface{}) +currentCdnPolicy := currentCdnPolicies[0].(map[string]interface{}) + +cacheMode, ok := futureCdnPolicy["cache_mode"].(string) +// Fallback to state if doesn't exist in object +if !ok { + cacheMode = currentCdnPolicy["cache_mode"].(string) +} + +switch cacheMode { +case "USE_ORIGIN_HEADERS": + if _, ok := futureCdnPolicy["clientTtl"]; ok { + delete(futureCdnPolicy, "clientTtl") + } + if _, ok := futureCdnPolicy["defaultTtl"]; ok { + delete(futureCdnPolicy, "defaultTtl") + } + if _, ok := futureCdnPolicy["maxTtl"]; ok { + delete(futureCdnPolicy, "maxTtl") + } +case "FORCE_CACHE_ALL": + if _, ok := futureCdnPolicy["maxTtl"]; ok { + delete(futureCdnPolicy, "maxTtl") + } +} + +return obj, nil diff --git a/mmv1/templates/terraform/encoders/go/compute_disk_resource_policies_attachment.go.tmpl b/mmv1/templates/terraform/encoders/go/compute_disk_resource_policies_attachment.go.tmpl new file mode 100644 index 000000000000..3f9adbc0e159 --- /dev/null +++ b/mmv1/templates/terraform/encoders/go/compute_disk_resource_policies_attachment.go.tmpl @@ -0,0 +1,25 @@ +config := meta.(*transport_tpg.Config) +project, err := tpgresource.GetProject(d, config) +if err != nil { + return nil, err +} + +zone, err := tpgresource.GetZone(d, config) +if err != nil { + return nil, err +} +if zone == "" { + return nil, fmt.Errorf("zone must be non-empty - set in resource or at provider-level") +} + +// resourcePolicies are referred to by region but affixed to zonal disks. +// We construct the regional name from the zone: +// projects/{project}/regions/{region}/resourcePolicies/{resourceId} +region := tpgresource.GetRegionFromZone(zone) +if region == "" { + return nil, fmt.Errorf("invalid zone %q, unable to infer region from zone", zone) +} + +obj["resourcePolicies"] = []interface{}{fmt.Sprintf("projects/%s/regions/%s/resourcePolicies/%s", project, region, obj["name"])} +delete(obj, "name") +return obj, nil diff --git a/mmv1/templates/terraform/encoders/go/compute_global_network_endpoint.go.tmpl b/mmv1/templates/terraform/encoders/go/compute_global_network_endpoint.go.tmpl new file mode 100644 index 000000000000..891aae34803d --- /dev/null +++ b/mmv1/templates/terraform/encoders/go/compute_global_network_endpoint.go.tmpl @@ -0,0 +1,21 @@ +{{- /* + The license inside this block applies to this file + Copyright 2024 Google Inc. + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/}} +// Network Endpoint Group is a URL parameter only, so replace self-link/path with resource name only. +if err := d.Set("global_network_endpoint_group", tpgresource.GetResourceNameFromSelfLink(d.Get("global_network_endpoint_group").(string))); err != nil { + return nil, fmt.Errorf("Error setting global_network_endpoint_group: %s", err) +} + +wrappedReq := map[string]interface{}{ + "networkEndpoints": []interface{}{obj}, +} +return wrappedReq, nil diff --git a/mmv1/templates/terraform/encoders/go/compute_instance_group_membership.go.tmpl b/mmv1/templates/terraform/encoders/go/compute_instance_group_membership.go.tmpl new file mode 100644 index 000000000000..53133ee4dd63 --- /dev/null +++ b/mmv1/templates/terraform/encoders/go/compute_instance_group_membership.go.tmpl @@ -0,0 +1,21 @@ +{{- /* + The license inside this block applies to this file + Copyright 2024 Google Inc. + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/}} +// Instance Group is a URL parameter only, so replace self-link/path with resource name only. +if err := d.Set("instance_group", tpgresource.GetResourceNameFromSelfLink(d.Get("instance_group").(string))); err != nil { + return nil, fmt.Errorf("Error setting instance_group: %s", err) +} + +wrappedReq := map[string]interface{}{ + "instances": []interface{}{obj}, +} +return wrappedReq, nil diff --git a/mmv1/templates/terraform/encoders/go/compute_network.go.tmpl b/mmv1/templates/terraform/encoders/go/compute_network.go.tmpl new file mode 100644 index 000000000000..084107f2772e --- /dev/null +++ b/mmv1/templates/terraform/encoders/go/compute_network.go.tmpl @@ -0,0 +1,2 @@ +delete(obj, "numeric_id") // Field doesn't exist in the API +return obj, nil diff --git a/mmv1/templates/terraform/encoders/go/compute_network_endpoint.go.tmpl b/mmv1/templates/terraform/encoders/go/compute_network_endpoint.go.tmpl new file mode 100644 index 000000000000..561d8442f926 --- /dev/null +++ b/mmv1/templates/terraform/encoders/go/compute_network_endpoint.go.tmpl @@ -0,0 +1,21 @@ +{{- /* + The license inside this block applies to this file + Copyright 2024 Google Inc. + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/}} +// Network Endpoint Group is a URL parameter only, so replace self-link/path with resource name only. +if err := d.Set("network_endpoint_group", tpgresource.GetResourceNameFromSelfLink(d.Get("network_endpoint_group").(string))); err != nil { + return nil, fmt.Errorf("Error setting network_endpoint_group: %s", err) +} + +wrappedReq := map[string]interface{}{ + "networkEndpoints": []interface{}{obj}, +} +return wrappedReq, nil diff --git a/mmv1/templates/terraform/encoders/go/compute_network_endpoints.go.tmpl b/mmv1/templates/terraform/encoders/go/compute_network_endpoints.go.tmpl new file mode 100644 index 000000000000..be414662887d --- /dev/null +++ b/mmv1/templates/terraform/encoders/go/compute_network_endpoints.go.tmpl @@ -0,0 +1,18 @@ +{{- /* + The license inside this block applies to this file + Copyright 2024 Google Inc. + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/}} +// Network Endpoint Group is a URL parameter only, so replace self-link/path with resource name only. +if err := d.Set("network_endpoint_group", tpgresource.GetResourceNameFromSelfLink(d.Get("network_endpoint_group").(string))); err != nil { + return nil, fmt.Errorf("Error setting network_endpoint_group: %s", err) +} + +return obj, nil diff --git a/mmv1/templates/terraform/encoders/go/compute_per_instance_config.go.tmpl b/mmv1/templates/terraform/encoders/go/compute_per_instance_config.go.tmpl new file mode 100644 index 000000000000..1797a0f90509 --- /dev/null +++ b/mmv1/templates/terraform/encoders/go/compute_per_instance_config.go.tmpl @@ -0,0 +1,16 @@ +{{- /* + The license inside this block applies to this file + Copyright 2024 Google Inc. + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/}} +wrappedReq := map[string]interface{}{ + "instances": []interface{}{obj}, +} +return wrappedReq, nil diff --git a/mmv1/templates/terraform/encoders/go/compute_region_disk_resource_policies_attachment.go.tmpl b/mmv1/templates/terraform/encoders/go/compute_region_disk_resource_policies_attachment.go.tmpl new file mode 100644 index 000000000000..d1dce38c2f08 --- /dev/null +++ b/mmv1/templates/terraform/encoders/go/compute_region_disk_resource_policies_attachment.go.tmpl @@ -0,0 +1,17 @@ +config := meta.(*transport_tpg.Config) +project, err := tpgresource.GetProject(d, config) +if err != nil { + return nil, err +} + +region, err := tpgresource.GetRegion(d, config) +if err != nil { + return nil, err +} +if region == "" { + return nil, fmt.Errorf("region must be non-empty - set in resource or at provider-level") +} + +obj["resourcePolicies"] = []interface{}{fmt.Sprintf("projects/%s/regions/%s/resourcePolicies/%s", project, region, obj["name"])} +delete(obj, "name") +return obj, nil diff --git a/mmv1/templates/terraform/encoders/go/compute_region_network_endpoint.go.tmpl b/mmv1/templates/terraform/encoders/go/compute_region_network_endpoint.go.tmpl new file mode 100644 index 000000000000..6bbad31d623c --- /dev/null +++ b/mmv1/templates/terraform/encoders/go/compute_region_network_endpoint.go.tmpl @@ -0,0 +1,21 @@ +{{- /* + The license inside this block applies to this file + Copyright 2024 Google Inc. + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/}} +// Network Endpoint Group is a URL parameter only, so replace self-link/path with resource name only. +if err := d.Set("region_network_endpoint_group", tpgresource.GetResourceNameFromSelfLink(d.Get("region_network_endpoint_group").(string))); err != nil { + return nil, fmt.Errorf("Error setting region_network_endpoint_group: %s", err) +} + +wrappedReq := map[string]interface{}{ + "networkEndpoints": []interface{}{obj}, +} +return wrappedReq, nil diff --git a/mmv1/templates/terraform/encoders/go/compute_region_target_https_proxy.go.tmpl b/mmv1/templates/terraform/encoders/go/compute_region_target_https_proxy.go.tmpl new file mode 100644 index 000000000000..168d4a65c5ef --- /dev/null +++ b/mmv1/templates/terraform/encoders/go/compute_region_target_https_proxy.go.tmpl @@ -0,0 +1,10 @@ + +if _, ok := obj["certificateManagerCertificates"]; ok { + // The field certificateManagerCertificates should not be included in the API request, and it should be renamed to `sslCertificates` + // The API does not allow using both certificate manager certificates and sslCertificates. If that changes + // in the future, the encoder logic should change accordingly because this will mean that both fields are no longer mutual exclusive. + log.Printf("[DEBUG] converting the field CertificateManagerCertificates to sslCertificates before sending the request") + obj["sslCertificates"] = obj["certificateManagerCertificates"] + delete(obj, "certificateManagerCertificates") +} +return obj, nil \ No newline at end of file diff --git a/mmv1/templates/terraform/encoders/go/compute_target_https_proxy.go.tmpl b/mmv1/templates/terraform/encoders/go/compute_target_https_proxy.go.tmpl new file mode 100644 index 000000000000..168d4a65c5ef --- /dev/null +++ b/mmv1/templates/terraform/encoders/go/compute_target_https_proxy.go.tmpl @@ -0,0 +1,10 @@ + +if _, ok := obj["certificateManagerCertificates"]; ok { + // The field certificateManagerCertificates should not be included in the API request, and it should be renamed to `sslCertificates` + // The API does not allow using both certificate manager certificates and sslCertificates. If that changes + // in the future, the encoder logic should change accordingly because this will mean that both fields are no longer mutual exclusive. + log.Printf("[DEBUG] converting the field CertificateManagerCertificates to sslCertificates before sending the request") + obj["sslCertificates"] = obj["certificateManagerCertificates"] + delete(obj, "certificateManagerCertificates") +} +return obj, nil \ No newline at end of file diff --git a/mmv1/templates/terraform/encoders/go/containeranalysis_attestation_field_name.go.tmpl b/mmv1/templates/terraform/encoders/go/containeranalysis_attestation_field_name.go.tmpl new file mode 100644 index 000000000000..0ad87829a3b2 --- /dev/null +++ b/mmv1/templates/terraform/encoders/go/containeranalysis_attestation_field_name.go.tmpl @@ -0,0 +1,21 @@ +{{- /* + The license inside this block applies to this file + Copyright 2024 Google Inc. + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/}} +{{- if eq $.TargetVersionName "ga" }} +// Field was renamed in GA API +obj["attestation"] = obj["attestationAuthority"] +delete(obj, "attestationAuthority") +{{- else }} +// encoder logic only in GA provider +{{- end }} + +return obj, nil diff --git a/mmv1/templates/terraform/encoders/go/containeranalysis_occurrence.go.tmpl b/mmv1/templates/terraform/encoders/go/containeranalysis_occurrence.go.tmpl new file mode 100644 index 000000000000..b8f8a1148758 --- /dev/null +++ b/mmv1/templates/terraform/encoders/go/containeranalysis_occurrence.go.tmpl @@ -0,0 +1,41 @@ +{{- /* + The license inside this block applies to this file + Copyright 2024 Google Inc. + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/}} +{{- if ne $.TargetVersionName "ga" }} +// Resource object was flattened in GA API +if resourceuri, ok := obj["resourceUri"]; ok { + obj["resource"] = map[string]interface{}{ + "uri": resourceuri, + } + delete(obj, "resourceUri") +} + + +// Beta `attestation.genericSignedAttestation` was flattened to just +// `attestation` (no contentType) in GA +if v, ok := obj["attestation"]; ok && v != nil { + gaAtt := v.(map[string]interface{}) + obj["attestation"] = map[string]interface{}{ + "attestation": map[string]interface{}{ + "genericSignedAttestation": map[string]interface{}{ + "contentType": "SIMPLE_SIGNING_JSON", + "serializedPayload": gaAtt["serializedPayload"], + "signatures": gaAtt["signatures"], + }, + }, + } +} +{{- else }} +// encoder logic only in non-GA versions +{{- end }} + +return obj, nil diff --git a/mmv1/templates/terraform/encoders/go/data_catalog_tag.go.tmpl b/mmv1/templates/terraform/encoders/go/data_catalog_tag.go.tmpl new file mode 100644 index 000000000000..1d99fcf41f9d --- /dev/null +++ b/mmv1/templates/terraform/encoders/go/data_catalog_tag.go.tmpl @@ -0,0 +1,17 @@ + if obj["fields"] != nil { + // IsEmptyValue() does not work for a boolean as it shows + // false when it is 'empty'. Filter boolValue here based on + // the rule api does not take more than 1 'value' + fields := obj["fields"].(map[string]interface{}) + for _, elements := range fields { + values := elements.(map[string]interface{}) + if len(values) > 1 { + for val := range values { + if val == "boolValue" { + delete(values, "boolValue") + } + } + } + } + } + return obj, nil diff --git a/mmv1/templates/terraform/encoders/go/datastream_stream.go.tmpl b/mmv1/templates/terraform/encoders/go/datastream_stream.go.tmpl new file mode 100644 index 000000000000..1b83ca8f749f --- /dev/null +++ b/mmv1/templates/terraform/encoders/go/datastream_stream.go.tmpl @@ -0,0 +1,16 @@ +{{- /* + The license inside this block applies to this file + Copyright 2024 Google Inc. + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/}} +if d.HasChange("desired_state") { + obj["state"] = d.Get("desired_state") +} +return obj, nil \ No newline at end of file diff --git a/mmv1/templates/terraform/encoders/go/discovery_engine_chat_engine_hardcode_solution_type.go.tmpl b/mmv1/templates/terraform/encoders/go/discovery_engine_chat_engine_hardcode_solution_type.go.tmpl new file mode 100644 index 000000000000..f84b27a792d2 --- /dev/null +++ b/mmv1/templates/terraform/encoders/go/discovery_engine_chat_engine_hardcode_solution_type.go.tmpl @@ -0,0 +1,3 @@ +//hard code solutionType to "SOLUTION_TYPE_CHAT" for chat engine resource +obj["solutionType"] = "SOLUTION_TYPE_CHAT" +return obj, nil \ No newline at end of file diff --git a/mmv1/templates/terraform/encoders/go/discovery_engine_search_engine_hardcode_solution_type.go.tmpl b/mmv1/templates/terraform/encoders/go/discovery_engine_search_engine_hardcode_solution_type.go.tmpl new file mode 100644 index 000000000000..fb2cf72a32af --- /dev/null +++ b/mmv1/templates/terraform/encoders/go/discovery_engine_search_engine_hardcode_solution_type.go.tmpl @@ -0,0 +1,3 @@ +// hard code solutionType to "SOLUTION_TYPE_SEARCH" for search engine resource +obj["solutionType"] = "SOLUTION_TYPE_SEARCH" +return obj, nil \ No newline at end of file diff --git a/mmv1/templates/terraform/encoders/go/disk.tmpl b/mmv1/templates/terraform/encoders/go/disk.tmpl new file mode 100644 index 000000000000..d32ecae6a410 --- /dev/null +++ b/mmv1/templates/terraform/encoders/go/disk.tmpl @@ -0,0 +1,54 @@ +config := meta.(*transport_tpg.Config) + +project, err := tpgresource.GetProject(d, config) +if err != nil { + return nil, err +} + +userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) +if err != nil { + return nil, err +} + +{{- if eq $.Name "Disk" }} +if v, ok := d.GetOk("type"); ok { + log.Printf("[DEBUG] Loading disk type: %s", v.(string)) + diskType, err := readDiskType(config, d, v.(string)) + if err != nil { + return nil, fmt.Errorf( + "Error loading disk type '%s': %s", + v.(string), err) + } + + obj["type"] = diskType.RelativeLink() +} +{{- else if eq $.Name "RegionDisk" }} +if v, ok := d.GetOk("type"); ok { + log.Printf("[DEBUG] Loading disk type: %s", v.(string)) + diskType, err := readRegionDiskType(config, d, v.(string)) + if err != nil { + return nil, fmt.Errorf( + "Error loading disk type '%s': %s", + v.(string), err) + } + + obj["type"] = diskType.RelativeLink() +} +{{- else }} + raise 'disk.tmpl included in non-disk type {{$.Name}}' +{{- end }} + +if v, ok := d.GetOk("image"); ok { + log.Printf("[DEBUG] Resolving image name: %s", v.(string)) + imageUrl, err := ResolveImage(config, project, v.(string), userAgent) + if err != nil { + return nil, fmt.Errorf( + "Error resolving image name '%s': %s", + v.(string), err) + } + + obj["sourceImage"] = imageUrl + log.Printf("[DEBUG] Image name resolved to: %s", imageUrl) +} + +return obj, nil diff --git a/mmv1/templates/terraform/encoders/go/dlp_job_trigger.go.tmpl b/mmv1/templates/terraform/encoders/go/dlp_job_trigger.go.tmpl new file mode 100644 index 000000000000..416f7e16229a --- /dev/null +++ b/mmv1/templates/terraform/encoders/go/dlp_job_trigger.go.tmpl @@ -0,0 +1,20 @@ +{{- /* + The license inside this block applies to this file + Copyright 2024 Google Inc. + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/}} + + newObj := make(map[string]interface{}) + newObj["{{camelize $.Name "lower"}}"] = obj + triggerIdProp, ok := d.GetOk("trigger_id") + if ok && triggerIdProp != nil { + newObj["triggerId"] = triggerIdProp + } + return newObj, nil diff --git a/mmv1/templates/terraform/encoders/go/dlp_stored_info_type.go.tmpl b/mmv1/templates/terraform/encoders/go/dlp_stored_info_type.go.tmpl new file mode 100644 index 000000000000..b8d74e40ce77 --- /dev/null +++ b/mmv1/templates/terraform/encoders/go/dlp_stored_info_type.go.tmpl @@ -0,0 +1,19 @@ +{{- /* + The license inside this block applies to this file + Copyright 2024 Google Inc. + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/}} + newObj := make(map[string]interface{}) + newObj["config"] = obj + storedInfoTypeIdProp, ok := d.GetOk("stored_info_type_id") + if ok && storedInfoTypeIdProp != nil { + newObj["storedInfoTypeId"] = storedInfoTypeIdProp + } + return newObj, nil diff --git a/mmv1/templates/terraform/encoders/go/firestore_field.go.tmpl b/mmv1/templates/terraform/encoders/go/firestore_field.go.tmpl new file mode 100644 index 000000000000..96383af29f6e --- /dev/null +++ b/mmv1/templates/terraform/encoders/go/firestore_field.go.tmpl @@ -0,0 +1,9 @@ + +// We've added project / database / collection / field as split fields of the name, but +// the API doesn't expect them. Make sure we remove them from any requests. + +delete(obj, "project") +delete(obj, "database") +delete(obj, "collection") +delete(obj, "field") +return obj, nil diff --git a/mmv1/templates/terraform/encoders/go/flex_app_version.go.tmpl b/mmv1/templates/terraform/encoders/go/flex_app_version.go.tmpl new file mode 100644 index 000000000000..ff55a1d59361 --- /dev/null +++ b/mmv1/templates/terraform/encoders/go/flex_app_version.go.tmpl @@ -0,0 +1,2 @@ +obj["env"] = "flex" +return obj, nil \ No newline at end of file diff --git a/mmv1/templates/terraform/encoders/go/health_check_type.tmpl b/mmv1/templates/terraform/encoders/go/health_check_type.tmpl new file mode 100644 index 000000000000..f5849366f680 --- /dev/null +++ b/mmv1/templates/terraform/encoders/go/health_check_type.tmpl @@ -0,0 +1,100 @@ +{{- /* + The license inside this block applies to this file + Copyright 2024 Google Inc. + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/}} + +if _, ok := d.GetOk("http_health_check"); ok { + hc := d.Get("http_health_check").([]interface{})[0] + ps := hc.(map[string]interface{})["port_specification"] + pn := hc.(map[string]interface{})["port_name"] + + if ps == "USE_FIXED_PORT" || (ps == "" && pn == "") { + m := obj["httpHealthCheck"].(map[string]interface{}) + if m["port"] == nil { + m["port"] = 80 + } + } + obj["type"] = "HTTP" + return obj, nil +} +if _, ok := d.GetOk("https_health_check"); ok { + hc := d.Get("https_health_check").([]interface{})[0] + ps := hc.(map[string]interface{})["port_specification"] + pn := hc.(map[string]interface{})["port_name"] + + if ps == "USE_FIXED_PORT" || (ps == "" && pn == "") { + m := obj["httpsHealthCheck"].(map[string]interface{}) + if m["port"] == nil { + m["port"] = 443 + } + } + obj["type"] = "HTTPS" + return obj, nil +} +if _, ok := d.GetOk("http2_health_check"); ok { + hc := d.Get("http2_health_check").([]interface{})[0] + ps := hc.(map[string]interface{})["port_specification"] + pn := hc.(map[string]interface{})["port_name"] + + if ps == "USE_FIXED_PORT" || (ps == "" && pn == "") { + m := obj["http2HealthCheck"].(map[string]interface{}) + if m["port"] == nil { + m["port"] = 443 + } + } + obj["type"] = "HTTP2" + return obj, nil +} +if _, ok := d.GetOk("tcp_health_check"); ok { + hc := d.Get("tcp_health_check").([]interface{})[0] + ps := hc.(map[string]interface{})["port_specification"] + pn := hc.(map[string]interface{})["port_name"] + + if ps == "USE_FIXED_PORT" || (ps == "" && pn == "") { + m := obj["tcpHealthCheck"].(map[string]interface{}) + if m["port"] == nil { + m["port"] = 80 + } + } + obj["type"] = "TCP" + return obj, nil +} +if _, ok := d.GetOk("ssl_health_check"); ok { + hc := d.Get("ssl_health_check").([]interface{})[0] + ps := hc.(map[string]interface{})["port_specification"] + pn := hc.(map[string]interface{})["port_name"] + + if ps == "USE_FIXED_PORT" || (ps == "" && pn == "") { + m := obj["sslHealthCheck"].(map[string]interface{}) + if m["port"] == nil { + m["port"] = 443 + } + } + obj["type"] = "SSL" + return obj, nil +} + +if _, ok := d.GetOk("grpc_health_check"); ok { + hc := d.Get("grpc_health_check").([]interface{})[0] + ps := hc.(map[string]interface{})["port_specification"] + pn := hc.(map[string]interface{})["port_name"] + + if ps == "USE_FIXED_PORT" || (ps == "" && pn == "") { + m := obj["grpcHealthCheck"].(map[string]interface{}) + if m["port"] == nil { + return nil, fmt.Errorf("error in HealthCheck %s: `port` must be set for GRPC health checks`.", d.Get("name").(string)) + } + } + obj["type"] = "GRPC" + return obj, nil +} + +return nil, fmt.Errorf("error in HealthCheck %s: No health check block specified.", d.Get("name").(string)) diff --git a/mmv1/templates/terraform/encoders/go/index.go.tmpl b/mmv1/templates/terraform/encoders/go/index.go.tmpl new file mode 100644 index 000000000000..231e5124eca3 --- /dev/null +++ b/mmv1/templates/terraform/encoders/go/index.go.tmpl @@ -0,0 +1,19 @@ +{{- /* + The license inside this block applies to this file + Copyright 2024 Google Inc. + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/}} +// We've added project / database / collection as split fields of the name, but +// the API doesn't expect them. Make sure we remove them from any requests. + +delete(obj, "project") +delete(obj, "database") +delete(obj, "collection") +return obj, nil diff --git a/mmv1/templates/terraform/encoders/go/kms_crypto_key.go.tmpl b/mmv1/templates/terraform/encoders/go/kms_crypto_key.go.tmpl new file mode 100644 index 000000000000..66416a0c3ba4 --- /dev/null +++ b/mmv1/templates/terraform/encoders/go/kms_crypto_key.go.tmpl @@ -0,0 +1,32 @@ +{{- /* + The license inside this block applies to this file + Copyright 2024 Google Inc. + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/}} + // if rotationPeriod is set, nextRotationTime must also be set. + if d.Get("rotation_period") != "" { + rotationPeriod := d.Get("rotation_period").(string) + nextRotation, err := kmsCryptoKeyNextRotation(time.Now(), rotationPeriod) + + if err != nil { + return nil, fmt.Errorf("Error setting CryptoKey rotation period: %s", err.Error()) + } + + obj["nextRotationTime"] = nextRotation + } + + // set to false if it is not true explicitly + if !(d.Get("skip_initial_version_creation").(bool)) { + if err := d.Set("skip_initial_version_creation", false); err != nil { + return nil, fmt.Errorf("Error setting skip_initial_version_creation: %s", err) + } + } + + return obj, nil diff --git a/mmv1/templates/terraform/encoders/go/location_from_region.go.tmpl b/mmv1/templates/terraform/encoders/go/location_from_region.go.tmpl new file mode 100644 index 000000000000..e5a0f2cc1b52 --- /dev/null +++ b/mmv1/templates/terraform/encoders/go/location_from_region.go.tmpl @@ -0,0 +1,23 @@ +{{- /* + The license inside this block applies to this file + Copyright 2024 Google Inc. + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/}} +config := meta.(*transport_tpg.Config) +if _, ok := d.GetOk("location"); !ok { + location, err := tpgresource.GetRegionFromSchema("region", "zone", d, config) + if err != nil { + return nil, fmt.Errorf("Cannot determine location: set in this resource, or set provider-level 'region' or 'zone'.") + } + if err := d.Set("location", location); err != nil { + return nil, fmt.Errorf("Error setting location: %s", err) + } +} +return obj, nil diff --git a/mmv1/templates/terraform/encoders/go/logging_linked_dataset.go.tmpl b/mmv1/templates/terraform/encoders/go/logging_linked_dataset.go.tmpl new file mode 100644 index 000000000000..871e6384d2fb --- /dev/null +++ b/mmv1/templates/terraform/encoders/go/logging_linked_dataset.go.tmpl @@ -0,0 +1,34 @@ +{{- /* + The license inside this block applies to this file + Copyright 2024 Google Inc. + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/}} +// Extract any empty fields from the bucket field. +parent := d.Get("parent").(string) +bucket := d.Get("bucket").(string) +parent, err := tpgresource.ExtractFieldByPattern("parent", parent, bucket, "((projects|folders|organizations|billingAccounts)/[a-z0-9A-Z-]*)/locations/.*") +if err != nil { + return nil, fmt.Errorf("error extracting parent field: %s", err) +} +location := d.Get("location").(string) +location, err = tpgresource.ExtractFieldByPattern("location", location, bucket, "[a-zA-Z]*/[a-z0-9A-Z-]*/locations/([a-z0-9-]*)/buckets/.*") +if err != nil { + return nil, fmt.Errorf("error extracting location field: %s", err) +} +// Set parent to the extracted value. +d.Set("parent", parent) +// Set all the other fields to their short forms before forming url and setting ID. +bucket = tpgresource.GetResourceNameFromSelfLink(bucket) +name := d.Get("name").(string) +name = tpgresource.GetResourceNameFromSelfLink(name) +d.Set("location", location) +d.Set("bucket", bucket) +d.Set("name", name) +return obj, nil diff --git a/mmv1/templates/terraform/encoders/go/logging_log_view.go.tmpl b/mmv1/templates/terraform/encoders/go/logging_log_view.go.tmpl new file mode 100644 index 000000000000..871e6384d2fb --- /dev/null +++ b/mmv1/templates/terraform/encoders/go/logging_log_view.go.tmpl @@ -0,0 +1,34 @@ +{{- /* + The license inside this block applies to this file + Copyright 2024 Google Inc. + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/}} +// Extract any empty fields from the bucket field. +parent := d.Get("parent").(string) +bucket := d.Get("bucket").(string) +parent, err := tpgresource.ExtractFieldByPattern("parent", parent, bucket, "((projects|folders|organizations|billingAccounts)/[a-z0-9A-Z-]*)/locations/.*") +if err != nil { + return nil, fmt.Errorf("error extracting parent field: %s", err) +} +location := d.Get("location").(string) +location, err = tpgresource.ExtractFieldByPattern("location", location, bucket, "[a-zA-Z]*/[a-z0-9A-Z-]*/locations/([a-z0-9-]*)/buckets/.*") +if err != nil { + return nil, fmt.Errorf("error extracting location field: %s", err) +} +// Set parent to the extracted value. +d.Set("parent", parent) +// Set all the other fields to their short forms before forming url and setting ID. +bucket = tpgresource.GetResourceNameFromSelfLink(bucket) +name := d.Get("name").(string) +name = tpgresource.GetResourceNameFromSelfLink(name) +d.Set("location", location) +d.Set("bucket", bucket) +d.Set("name", name) +return obj, nil diff --git a/mmv1/templates/terraform/encoders/go/monitoring_monitored_project.go.tmpl b/mmv1/templates/terraform/encoders/go/monitoring_monitored_project.go.tmpl new file mode 100644 index 000000000000..76442aa5e446 --- /dev/null +++ b/mmv1/templates/terraform/encoders/go/monitoring_monitored_project.go.tmpl @@ -0,0 +1,24 @@ +{{- /* + The license inside this block applies to this file + Copyright 2024 Google Inc. + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/}} +name := d.Get("name").(string) +log.Printf("[DEBUG] Encoded monitored project name: %s", name) +name = tpgresource.GetResourceNameFromSelfLink(name) +log.Printf("[DEBUG] Encoded monitored project resource name: %s", name) +d.Set("name", name) +metricsScope := d.Get("metrics_scope").(string) +log.Printf("[DEBUG] Encoded monitored project metricsScope: %s", metricsScope) +metricsScope = tpgresource.GetResourceNameFromSelfLink(metricsScope) +log.Printf("[DEBUG] Encoded monitored project metricsScope resource name: %s", metricsScope) +d.Set("metrics_scope", metricsScope) +obj["name"] = fmt.Sprintf("locations/global/metricsScopes/%s/projects/%s", metricsScope, name) +return obj, nil diff --git a/mmv1/templates/terraform/encoders/go/monitoring_notification_channel.go.tmpl b/mmv1/templates/terraform/encoders/go/monitoring_notification_channel.go.tmpl new file mode 100644 index 000000000000..bde26ac93c37 --- /dev/null +++ b/mmv1/templates/terraform/encoders/go/monitoring_notification_channel.go.tmpl @@ -0,0 +1,29 @@ +{{- /* + The license inside this block applies to this file + Copyright 2024 Google Inc. + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/}} +labelmap, ok := obj["labels"] +if !ok { + labelmap = make(map[string]string) +} + +var labels map[string]string +labels = labelmap.(map[string]string) + +for _, sl := range sensitiveLabels { + if auth, _ := d.GetOkExists("sensitive_labels.0." + sl); auth != "" { + labels[sl] = auth.(string) + } +} + +obj["labels"] = labels + +return obj, nil \ No newline at end of file diff --git a/mmv1/templates/terraform/encoders/go/monitoring_service.go.tmpl b/mmv1/templates/terraform/encoders/go/monitoring_service.go.tmpl new file mode 100644 index 000000000000..e9b60bab04a1 --- /dev/null +++ b/mmv1/templates/terraform/encoders/go/monitoring_service.go.tmpl @@ -0,0 +1,22 @@ +{{- /* + The license inside this block applies to this file + Copyright 2024 Google Inc. + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/}} +// Currently only CUSTOM service types can be created, but the +// custom identifier block does not actually have fields right now. +// Set to empty to indicate manually-created service type is CUSTOM. +if _, ok := obj["custom"]; !ok { + obj["custom"] = map[string]interface{}{} +} +// Name/Service ID is a query parameter only +delete(obj, "name") + +return obj, nil \ No newline at end of file diff --git a/mmv1/templates/terraform/encoders/go/monitoring_slo.go.tmpl b/mmv1/templates/terraform/encoders/go/monitoring_slo.go.tmpl new file mode 100644 index 000000000000..038323202a85 --- /dev/null +++ b/mmv1/templates/terraform/encoders/go/monitoring_slo.go.tmpl @@ -0,0 +1,40 @@ +{{- /* + The license inside this block applies to this file + Copyright 2024 Google Inc. + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/}} +// Name/Service Level Objective ID is a query parameter and cannot +// be given in data +delete(obj, "sloId") +Sli := obj["serviceLevelIndicator"].(map[string]interface{}) +if basicSli, ok := Sli["basicSli"].(map[string]interface{}); ok { + //Removing the dummy `enabled` attribute + if availability, ok := basicSli["availability"]; ok { + transAvailability := availability.(map[string]interface{}) + delete(transAvailability, "enabled") + basicSli["availability"] = transAvailability + } +} + +if windowBasedSli, ok := Sli["windowsBased"].(map[string]interface{}); ok { + if goodTotalRatioThreshold, ok := windowBasedSli["goodTotalRatioThreshold"].(map[string]interface{}); ok { + if basicSli, ok := goodTotalRatioThreshold["basicSliPerformance"].(map[string]interface{}); ok { + //Removing the dummy `enabled` attribute + if availability, ok := basicSli["availability"]; ok { + transAvailability := availability.(map[string]interface{}) + delete(transAvailability, "enabled") + basicSli["availability"] = transAvailability + } + } + } +} + +return obj, nil + diff --git a/mmv1/templates/terraform/encoders/go/network_peering_routes_config.go.tmpl b/mmv1/templates/terraform/encoders/go/network_peering_routes_config.go.tmpl new file mode 100644 index 000000000000..8bdd678fdf3e --- /dev/null +++ b/mmv1/templates/terraform/encoders/go/network_peering_routes_config.go.tmpl @@ -0,0 +1,17 @@ +{{- /* + The license inside this block applies to this file + Copyright 2024 Google Inc. + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/}} + // Stick request in a networkPeering block as in + // https://cloud.google.com/compute/docs/reference/rest/v1/networks/updatePeering + newObj := make(map[string]interface{}) + newObj["networkPeering"] = obj + return newObj, nil diff --git a/mmv1/templates/terraform/encoders/go/no_send_name.go.tmpl b/mmv1/templates/terraform/encoders/go/no_send_name.go.tmpl new file mode 100644 index 000000000000..0db0a98e867f --- /dev/null +++ b/mmv1/templates/terraform/encoders/go/no_send_name.go.tmpl @@ -0,0 +1,14 @@ +{{- /* + The license inside this block applies to this file + Copyright 2024 Google Inc. + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/}} +delete(obj, "name") +return obj, nil diff --git a/mmv1/templates/terraform/encoders/go/normalize_group.go.tmpl b/mmv1/templates/terraform/encoders/go/normalize_group.go.tmpl new file mode 100644 index 000000000000..1412175a174e --- /dev/null +++ b/mmv1/templates/terraform/encoders/go/normalize_group.go.tmpl @@ -0,0 +1,17 @@ +config := meta.(*transport_tpg.Config) +ig, err := tpgresource.ParseInstanceGroupFieldValue(d.Get("group").(string), d, config) +if err != nil { + return nil, err +} + +if err := d.Set("group", ig.Name); err != nil { + return nil, fmt.Errorf("Error setting group: %s", err) +} +if err := d.Set("zone", ig.Zone); err != nil { + return nil, fmt.Errorf("Error setting zone: %s", err) +} +if err := d.Set("project", ig.Project); err != nil { + return nil, fmt.Errorf("Error setting project: %s", err) +} + +return obj, nil diff --git a/mmv1/templates/terraform/encoders/go/os_config_patch_deployment.go.tmpl b/mmv1/templates/terraform/encoders/go/os_config_patch_deployment.go.tmpl new file mode 100644 index 000000000000..a5660782d606 --- /dev/null +++ b/mmv1/templates/terraform/encoders/go/os_config_patch_deployment.go.tmpl @@ -0,0 +1,28 @@ +if obj["recurringSchedule"] != nil { + schedule := obj["recurringSchedule"].(map[string]interface{}) + if schedule["monthly"] != nil { + obj["recurringSchedule"].(map[string]interface{})["frequency"] = "MONTHLY" + } else if schedule["weekly"] != nil { + obj["recurringSchedule"].(map[string]interface{})["frequency"] = "WEEKLY" + } else { + obj["recurringSchedule"].(map[string]interface{})["frequency"] = "DAILY" + } +} + +if obj["patchConfig"] != nil { + patchConfig := obj["patchConfig"].(map[string]interface{}) + if patchConfig["goo"] != nil { + goo := patchConfig["goo"].(map[string]interface{}) + + if goo["enabled"] == true { + delete(goo, "enabled") + patchConfig["goo"] = goo + } else { + delete(patchConfig, "goo") + } + + obj["patchConfig"] = patchConfig + } +} + +return obj, nil diff --git a/mmv1/templates/terraform/encoders/go/pubsub_lite.tmpl b/mmv1/templates/terraform/encoders/go/pubsub_lite.tmpl new file mode 100644 index 000000000000..c7a37c217324 --- /dev/null +++ b/mmv1/templates/terraform/encoders/go/pubsub_lite.tmpl @@ -0,0 +1,20 @@ +config := meta.(*transport_tpg.Config) + +zone, err := tpgresource.GetZone(d, config) +if err != nil { + return nil, err +} + +if zone == "" { + return nil, fmt.Errorf("zone must be non-empty - set in resource or at provider-level") +} + +// API Endpoint requires region in the URL. We infer it from the zone. + +region := tpgresource.GetRegionFromZone(zone) + +if region == "" { + return nil, fmt.Errorf("invalid zone %q, unable to infer region from zone", zone) +} + +return obj, nil \ No newline at end of file diff --git a/mmv1/templates/terraform/encoders/go/redis_location_id_for_fallback_zone.go.tmpl b/mmv1/templates/terraform/encoders/go/redis_location_id_for_fallback_zone.go.tmpl new file mode 100644 index 000000000000..7748ca309318 --- /dev/null +++ b/mmv1/templates/terraform/encoders/go/redis_location_id_for_fallback_zone.go.tmpl @@ -0,0 +1,21 @@ +{{- /* + The license inside this block applies to this file + Copyright 2024 Google Inc. + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/}} +config := meta.(*transport_tpg.Config) +region, err := tpgresource.GetRegionFromSchema("region", "location_id", d, config) +if err != nil { + return nil, err +} +if err := d.Set("region", region); err != nil { + return nil, fmt.Errorf("Error setting region: %s", err) +} +return obj, nil diff --git a/mmv1/templates/terraform/encoders/go/region_backend_service.go.tmpl b/mmv1/templates/terraform/encoders/go/region_backend_service.go.tmpl new file mode 100644 index 000000000000..684766841fb7 --- /dev/null +++ b/mmv1/templates/terraform/encoders/go/region_backend_service.go.tmpl @@ -0,0 +1,80 @@ +{{- /* + The license inside this block applies to this file + Copyright 2024 Google Inc. + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/}} +// 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 +} + +{{- if ne $.TargetVersionName "ga" }} +// To remove subsetting on an ILB, "NONE" must be specified. If subsetting +// isn't specified, we set the value to NONE to make this use case work. +_, ok := obj["subsetting"] +if !ok { + loadBalancingScheme, ok := obj["loadBalancingScheme"] + // External load balancing scheme does not support subsetting + if !ok || loadBalancingScheme.(string) != "EXTERNAL" { + data := map[string]interface{}{} + data["policy"] = "NONE" + obj["subsetting"] = data + } +} +{{- end }} + +backendServiceOnlyManagedApiFieldNames := []string{ + "capacityScaler", + "maxConnections", + "maxConnectionsPerInstance", + "maxConnectionsPerEndpoint", + "maxRate", + "maxRatePerInstance", + "maxRatePerEndpoint", + "maxUtilization", +} + +var backends []interface{} +if lsV := obj["backends"]; lsV != nil { + backends = lsV.([]interface{}) +} +for idx, v := range backends { + if v == nil { + continue + } + backend := v.(map[string]interface{}) + // Remove fields from backends that cannot be sent for non-managed + // backend services + for _, k := range backendServiceOnlyManagedApiFieldNames { + log.Printf("[DEBUG] Removing field %q for request for non-managed backend service %s", k, d.Get("name")) + delete(backend, k) + } + backends[idx] = backend +} + +obj["backends"] = backends +return obj, nil diff --git a/mmv1/templates/terraform/encoders/go/send_nil_body.go.tmpl b/mmv1/templates/terraform/encoders/go/send_nil_body.go.tmpl new file mode 100644 index 000000000000..83c186327a3d --- /dev/null +++ b/mmv1/templates/terraform/encoders/go/send_nil_body.go.tmpl @@ -0,0 +1 @@ +return nil, nil diff --git a/mmv1/templates/terraform/encoders/go/service_connection_policy.go.tmpl b/mmv1/templates/terraform/encoders/go/service_connection_policy.go.tmpl new file mode 100644 index 000000000000..0a3866b9aca9 --- /dev/null +++ b/mmv1/templates/terraform/encoders/go/service_connection_policy.go.tmpl @@ -0,0 +1,2 @@ +obj["network"] = d.Get("network").(string) +return obj, nil diff --git a/mmv1/templates/terraform/encoders/go/spanner_database.go.tmpl b/mmv1/templates/terraform/encoders/go/spanner_database.go.tmpl new file mode 100644 index 000000000000..0e8ae39b76cf --- /dev/null +++ b/mmv1/templates/terraform/encoders/go/spanner_database.go.tmpl @@ -0,0 +1,19 @@ +obj["createStatement"] = fmt.Sprintf("CREATE DATABASE `%s`", obj["name"]) +if dialect, ok := obj["databaseDialect"]; ok && dialect == "POSTGRESQL" { + obj["createStatement"] = fmt.Sprintf("CREATE DATABASE \"%s\"", obj["name"]) +} + +// Extra DDL statements are removed from the create request and instead applied to the database in +// a post-create action, to accommodate retrictions when creating PostgreSQL-enabled databases. +// https://cloud.google.com/spanner/docs/create-manage-databases#create_a_database +log.Printf("[DEBUG] Preparing to create new Database. Any extra DDL statements will be applied to the Database in a separate API call") + +delete(obj, "name") +delete(obj, "instance") +{{- /* These are added back in post-create, but do not remove for Validator. */}} +{{- if ne $.Compiler "terraformgoogleconversion-codegen" }} +delete(obj, "versionRetentionPeriod") +delete(obj, "extraStatements") +delete(obj, "enableDropProtection") +{{- end }} +return obj, nil diff --git a/mmv1/templates/terraform/encoders/go/spanner_instance.go.tmpl b/mmv1/templates/terraform/encoders/go/spanner_instance.go.tmpl new file mode 100644 index 000000000000..7dde01e82fa7 --- /dev/null +++ b/mmv1/templates/terraform/encoders/go/spanner_instance.go.tmpl @@ -0,0 +1,16 @@ +// Temp Logic to accommodate autoscaling_config, processing_units and num_nodes +if obj["processingUnits"] == nil && obj["nodeCount"] == nil && obj["autoscalingConfig"] == nil { + obj["nodeCount"] = 1 +} +newObj := make(map[string]interface{}) +newObj["instance"] = obj +if obj["name"] == nil { + if err := d.Set("name", resource.PrefixedUniqueId("tfgen-spanid-")[:30]); err != nil { + return nil, fmt.Errorf("Error setting name: %s", err) + } + newObj["instanceId"] = d.Get("name").(string) +} else { + newObj["instanceId"] = obj["name"] +} +delete(obj, "name") +return newObj, nil diff --git a/mmv1/templates/terraform/encoders/go/spanner_instance_update.go.tmpl b/mmv1/templates/terraform/encoders/go/spanner_instance_update.go.tmpl new file mode 100644 index 000000000000..8870556d158b --- /dev/null +++ b/mmv1/templates/terraform/encoders/go/spanner_instance_update.go.tmpl @@ -0,0 +1,49 @@ +project, err := tpgresource.GetProject(d, meta.(*transport_tpg.Config)) +if err != nil { + return nil, err +} +obj["name"] = fmt.Sprintf("projects/%s/instances/%s", project, obj["name"]) +newObj := make(map[string]interface{}) +newObj["instance"] = obj +updateMask := make([]string, 0) +if d.HasChange("num_nodes") { + updateMask = append(updateMask, "nodeCount") +} +if d.HasChange("display_name") { + updateMask = append(updateMask, "displayName") +} +if d.HasChange("labels") { + updateMask = append(updateMask, "labels") +} +if d.HasChange("processing_units") { + updateMask = append(updateMask, "processingUnits") +} +if d.HasChange("autoscaling_config") { + old, new := d.GetChange("autoscaling_config") + oldSlice := old.([]interface{}) + newSlice := new.([]interface{}) + if len(oldSlice) == 0 || len(newSlice) == 0 { + updateMask = append(updateMask, "autoscalingConfig") + } else { + if d.HasChange("autoscaling_config.0.autoscaling_limits.0.max_processing_units") { + updateMask = append(updateMask, "autoscalingConfig.autoscalingLimits.maxProcessingUnits") + } + if d.HasChange("autoscaling_config.0.autoscaling_limits.0.min_processing_units") { + updateMask = append(updateMask, "autoscalingConfig.autoscalingLimits.minProcessingUnits") + } + if d.HasChange("autoscaling_config.0.autoscaling_limits.0.max_nodes") { + updateMask = append(updateMask, "autoscalingConfig.autoscalingLimits.maxNodes") + } + if d.HasChange("autoscaling_config.0.autoscaling_limits.0.min_nodes") { + updateMask = append(updateMask, "autoscalingConfig.autoscalingLimits.minNodes") + } + if d.HasChange("autoscaling_config.0.autoscaling_targets.0.high_priority_cpu_utilization_percent") { + updateMask = append(updateMask, "autoscalingConfig.autoscalingTargets.highPriorityCpuUtilizationPercent") + } + if d.HasChange("autoscaling_config.0.autoscaling_targets.0.storage_utilization_percent") { + updateMask = append(updateMask, "autoscalingConfig.autoscalingTargets.storageUtilizationPercent") + } + } +} +newObj["fieldMask"] = strings.Join(updateMask, ",") +return newObj, nil diff --git a/mmv1/templates/terraform/encoders/go/sql_source_representation_instance.go.tmpl b/mmv1/templates/terraform/encoders/go/sql_source_representation_instance.go.tmpl new file mode 100644 index 000000000000..68cd0ce41bf6 --- /dev/null +++ b/mmv1/templates/terraform/encoders/go/sql_source_representation_instance.go.tmpl @@ -0,0 +1,17 @@ +{{- /* + The license inside this block applies to this file + Copyright 2024 Google Inc. + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/}} +opc := obj["onPremisesConfiguration"].(map[string]interface{}) +opc["hostPort"] = fmt.Sprintf("%v:%v", opc["host"], opc["port"]) +delete(opc, "host") +delete(opc, "port") +return obj, nil diff --git a/mmv1/templates/terraform/encoders/go/vertex_ai_featurestore_entitytype.go.tmpl b/mmv1/templates/terraform/encoders/go/vertex_ai_featurestore_entitytype.go.tmpl new file mode 100644 index 000000000000..69ac8d6d84ad --- /dev/null +++ b/mmv1/templates/terraform/encoders/go/vertex_ai_featurestore_entitytype.go.tmpl @@ -0,0 +1,8 @@ +if v, ok := d.GetOk("featurestore"); ok { + re := regexp.MustCompile("projects/(.+)/locations/(.+)/featurestores/(.+)$") + if parts := re.FindStringSubmatch(v.(string)); parts != nil { + d.Set("region", parts[2]) + } +} + +return obj, nil \ No newline at end of file diff --git a/mmv1/templates/terraform/encoders/go/vertex_ai_featurestore_entitytype_feature.go.tmpl b/mmv1/templates/terraform/encoders/go/vertex_ai_featurestore_entitytype_feature.go.tmpl new file mode 100644 index 000000000000..450c499ba865 --- /dev/null +++ b/mmv1/templates/terraform/encoders/go/vertex_ai_featurestore_entitytype_feature.go.tmpl @@ -0,0 +1,8 @@ +if v, ok := d.GetOk("entitytype"); ok { + re := regexp.MustCompile("^projects/(.+)/locations/(.+)/featurestores/(.+)/entityTypes/(.+)$") + if parts := re.FindStringSubmatch(v.(string)); parts != nil { + d.Set("region", parts[2]) + } +} + +return obj, nil diff --git a/mmv1/templates/terraform/encoders/go/vpn_tunnel.go.tmpl b/mmv1/templates/terraform/encoders/go/vpn_tunnel.go.tmpl new file mode 100644 index 000000000000..24eeb8cbbd15 --- /dev/null +++ b/mmv1/templates/terraform/encoders/go/vpn_tunnel.go.tmpl @@ -0,0 +1,16 @@ +config := meta.(*transport_tpg.Config) +f, err := tpgresource.ParseRegionalFieldValue("targetVpnGateways", d.Get("target_vpn_gateway").(string), "project", "region", "zone", d, config, true) +if err != nil { + return nil, err +} +if _, ok := d.GetOk("project"); !ok { + if err := d.Set("project", f.Project); err != nil { + return nil, fmt.Errorf("Error setting project: %s", err) + } +} +if _, ok := d.GetOk("region"); !ok { + if err := d.Set("region", f.Region); err != nil { + return nil, fmt.Errorf("Error setting region: %s", err) + } +} +return obj, nil diff --git a/mmv1/templates/terraform/encoders/go/workflow.go.tmpl b/mmv1/templates/terraform/encoders/go/workflow.go.tmpl new file mode 100644 index 000000000000..8e87273991e9 --- /dev/null +++ b/mmv1/templates/terraform/encoders/go/workflow.go.tmpl @@ -0,0 +1,14 @@ +var ResName string +if v, ok := d.GetOk("name"); ok { + ResName = v.(string) +} else if v, ok := d.GetOk("name_prefix"); ok { + ResName = resource.PrefixedUniqueId(v.(string)) +} else { + ResName = resource.UniqueId() +} + +if err := d.Set("name", ResName); err != nil { + return nil, fmt.Errorf("Error setting name: %s", err) +} + +return obj, nil \ No newline at end of file diff --git a/mmv1/templates/terraform/encoders/go/wrap_object.go.tmpl b/mmv1/templates/terraform/encoders/go/wrap_object.go.tmpl new file mode 100644 index 000000000000..b739d6c24c22 --- /dev/null +++ b/mmv1/templates/terraform/encoders/go/wrap_object.go.tmpl @@ -0,0 +1,15 @@ +{{- /* + The license inside this block applies to this file + Copyright 2024 Google Inc. + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/}} + newObj := make(map[string]interface{}) + newObj["{{camelize $.Name "lower"}}"] = obj + return newObj, nil diff --git a/mmv1/templates/terraform/encoders/go/wrap_object_with_deployment_resource_pool_id.go.tmpl b/mmv1/templates/terraform/encoders/go/wrap_object_with_deployment_resource_pool_id.go.tmpl new file mode 100644 index 000000000000..eccc59bc586e --- /dev/null +++ b/mmv1/templates/terraform/encoders/go/wrap_object_with_deployment_resource_pool_id.go.tmpl @@ -0,0 +1,19 @@ +{{- /* + The license inside this block applies to this file + Copyright 2024 Google Inc. + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/}} + newObj := make(map[string]interface{}) + newObj["deploymentResourcePool"] = obj + nameProp, ok := d.GetOk("name") + if ok && nameProp != nil { + newObj["deploymentResourcePoolId"] = nameProp + } + return newObj, nil diff --git a/mmv1/templates/terraform/encoders/go/wrap_object_with_template_id.go.tmpl b/mmv1/templates/terraform/encoders/go/wrap_object_with_template_id.go.tmpl new file mode 100644 index 000000000000..efc2e3edc08d --- /dev/null +++ b/mmv1/templates/terraform/encoders/go/wrap_object_with_template_id.go.tmpl @@ -0,0 +1,19 @@ +{{- /* + The license inside this block applies to this file + Copyright 2024 Google Inc. + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/}} + newObj := make(map[string]interface{}) + newObj["{{camelize $.Name "lower"}}"] = obj + templateIdProp, ok := d.GetOk("template_id") + if ok && templateIdProp != nil { + newObj["templateId"] = templateIdProp + } + return newObj, nil diff --git a/mmv1/templates/terraform/extra_schema_entry/go/api_config.tmpl b/mmv1/templates/terraform/extra_schema_entry/go/api_config.tmpl new file mode 100644 index 000000000000..2873476f657e --- /dev/null +++ b/mmv1/templates/terraform/extra_schema_entry/go/api_config.tmpl @@ -0,0 +1,8 @@ +"api_config_id_prefix": { + Type: schema.TypeString, + Optional: true, + Computed: true, + ForceNew: true, + ConflictsWith: []string{"api_config_id"}, + Description: `Creates a unique name beginning with the specified prefix. If this and api_config_id are unspecified, a random value is chosen for the name.`, +}, diff --git a/mmv1/templates/terraform/extra_schema_entry/go/bigquery_dataset_access.go.tmpl b/mmv1/templates/terraform/extra_schema_entry/go/bigquery_dataset_access.go.tmpl new file mode 100644 index 000000000000..ac7abe767b75 --- /dev/null +++ b/mmv1/templates/terraform/extra_schema_entry/go/bigquery_dataset_access.go.tmpl @@ -0,0 +1,17 @@ +{{- /* + The license inside this block applies to this file + Copyright 2024 Google Inc. + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/}} +"api_updated_member": { + Type: schema.TypeBool, + Computed: true, + Description: "If true, represents that that the iam_member in the config was translated to a different member type by the API, and is stored in state as a different member type", +}, \ No newline at end of file diff --git a/mmv1/templates/terraform/extra_schema_entry/go/bigtable_app_profile.go.tmpl b/mmv1/templates/terraform/extra_schema_entry/go/bigtable_app_profile.go.tmpl new file mode 100644 index 000000000000..2c13c0f9ff4c --- /dev/null +++ b/mmv1/templates/terraform/extra_schema_entry/go/bigtable_app_profile.go.tmpl @@ -0,0 +1,21 @@ +{{- /* + The license inside this block applies to this file + Copyright 2024 Google Inc. + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/}} +"multi_cluster_routing_cluster_ids": { + Type: schema.TypeList, + Optional: true, + Description: `The set of clusters to route to. The order is ignored; clusters will be tried in order of distance. If left empty, all clusters are eligible.`, + Elem: &schema.Schema{ + Type: schema.TypeString, + }, + ConflictsWith: []string{"single_cluster_routing"}, +}, \ No newline at end of file diff --git a/mmv1/templates/terraform/extra_schema_entry/go/firewall.tmpl b/mmv1/templates/terraform/extra_schema_entry/go/firewall.tmpl new file mode 100644 index 000000000000..43543a0fefba --- /dev/null +++ b/mmv1/templates/terraform/extra_schema_entry/go/firewall.tmpl @@ -0,0 +1,19 @@ +{{- /* + The license inside this block applies to this file + Copyright 2024 Google Inc. + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/}} +"enable_logging": { + Type: schema.TypeBool, + Optional: true, + Computed: true, + Deprecated: "Deprecated in favor of log_config", + Description: "This field denotes whether to enable logging for a particular firewall rule. If logging is enabled, logs will be exported to Stackdriver.", +}, \ No newline at end of file diff --git a/mmv1/templates/terraform/extra_schema_entry/go/redis_instance.tmpl b/mmv1/templates/terraform/extra_schema_entry/go/redis_instance.tmpl new file mode 100644 index 000000000000..fea34e1686d2 --- /dev/null +++ b/mmv1/templates/terraform/extra_schema_entry/go/redis_instance.tmpl @@ -0,0 +1,6 @@ +"auth_string": { + Type: schema.TypeString, + Description: "AUTH String set on the instance. This field will only be populated if auth_enabled is true.", + Computed: true, + Sensitive: true, +}, \ No newline at end of file diff --git a/mmv1/templates/terraform/extra_schema_entry/go/route.tmpl b/mmv1/templates/terraform/extra_schema_entry/go/route.tmpl new file mode 100644 index 000000000000..e395a1edcdf3 --- /dev/null +++ b/mmv1/templates/terraform/extra_schema_entry/go/route.tmpl @@ -0,0 +1,7 @@ +"next_hop_instance_zone": &schema.Schema{ + Type: schema.TypeString, + Optional: true, + ForceNew: true, + Computed: true, + Description: "The zone of the instance specified in next_hop_instance. Omit if next_hop_instance is specified as a URL.", +}, diff --git a/mmv1/templates/terraform/extra_schema_entry/go/secret_version_is_secret_data_base64.go.tmpl b/mmv1/templates/terraform/extra_schema_entry/go/secret_version_is_secret_data_base64.go.tmpl new file mode 100644 index 000000000000..a3a34cbe89a3 --- /dev/null +++ b/mmv1/templates/terraform/extra_schema_entry/go/secret_version_is_secret_data_base64.go.tmpl @@ -0,0 +1,19 @@ +{{- /* + The license inside this block applies to this file + Copyright 2024 Google Inc. + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/}} +"is_secret_data_base64": { + Type: schema.TypeBool, + Optional: true, + ForceNew: true, + Default: false, + Description: `If set to 'true', the secret data is expected to be base64-encoded string and would be sent as is.`, +}, diff --git a/mmv1/templates/terraform/extra_schema_entry/go/ssl_certificate.tmpl b/mmv1/templates/terraform/extra_schema_entry/go/ssl_certificate.tmpl new file mode 100644 index 000000000000..589b25919642 --- /dev/null +++ b/mmv1/templates/terraform/extra_schema_entry/go/ssl_certificate.tmpl @@ -0,0 +1,18 @@ +"name_prefix": { + Type: schema.TypeString, + Optional: true, + Computed: true, + ForceNew: true, + ConflictsWith: []string{"name"}, + Description: "Creates a unique name beginning with the specified prefix. Conflicts with name.", + ValidateFunc: func(v interface{}, k string) (ws []string, errors []error) { + // https://cloud.google.com/compute/docs/reference/latest/sslCertificates#resource + // uuid is 26 characters, limit the prefix to 37. + value := v.(string) + if len(value) > 37 { + errors = append(errors, fmt.Errorf( + "%q cannot be longer than 37 characters, name is limited to 63", k)) + } + return + }, +}, diff --git a/mmv1/templates/terraform/extra_schema_entry/go/subnetwork.tmpl b/mmv1/templates/terraform/extra_schema_entry/go/subnetwork.tmpl new file mode 100644 index 000000000000..07a76118e8b6 --- /dev/null +++ b/mmv1/templates/terraform/extra_schema_entry/go/subnetwork.tmpl @@ -0,0 +1,18 @@ +{{- /* + The license inside this block applies to this file + Copyright 2024 Google Inc. + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/}} +"fingerprint": { + Type: schema.TypeString, + Computed: true, + Description: "Fingerprint of this resource. This field is used internally during updates of this resource.", + Deprecated: "This field is not useful for users, and has been removed as an output.", +}, diff --git a/mmv1/templates/terraform/extra_schema_entry/go/vertex_ai_featurestore_entitytype.go.tmpl b/mmv1/templates/terraform/extra_schema_entry/go/vertex_ai_featurestore_entitytype.go.tmpl new file mode 100644 index 000000000000..ef3520411c52 --- /dev/null +++ b/mmv1/templates/terraform/extra_schema_entry/go/vertex_ai_featurestore_entitytype.go.tmpl @@ -0,0 +1,5 @@ +"region": { + Type: schema.TypeString, + Computed: true, + Description: "The region of the EntityType.", +}, diff --git a/mmv1/templates/terraform/extra_schema_entry/go/vertex_ai_featurestore_entitytype_feature.go.tmpl b/mmv1/templates/terraform/extra_schema_entry/go/vertex_ai_featurestore_entitytype_feature.go.tmpl new file mode 100644 index 000000000000..9f78c3ba2dc5 --- /dev/null +++ b/mmv1/templates/terraform/extra_schema_entry/go/vertex_ai_featurestore_entitytype_feature.go.tmpl @@ -0,0 +1,5 @@ +"region": { + Type: schema.TypeString, + Computed: true, + Description: "The region of the feature", +}, diff --git a/mmv1/templates/terraform/extra_schema_entry/go/workflow.tmpl b/mmv1/templates/terraform/extra_schema_entry/go/workflow.tmpl new file mode 100644 index 000000000000..8696cae22b92 --- /dev/null +++ b/mmv1/templates/terraform/extra_schema_entry/go/workflow.tmpl @@ -0,0 +1,7 @@ +"name_prefix": { + Type: schema.TypeString, + Optional: true, + Computed: true, + ForceNew: true, + ConflictsWith: []string{"name"}, +}, diff --git a/mmv1/templates/terraform/post_create/go/KMS_Verify.go.tmpl b/mmv1/templates/terraform/post_create/go/KMS_Verify.go.tmpl new file mode 100644 index 000000000000..1f3100cba31d --- /dev/null +++ b/mmv1/templates/terraform/post_create/go/KMS_Verify.go.tmpl @@ -0,0 +1,17 @@ +url_kms_verify, err := tpgresource.ReplaceVars(d, config, "{{"{{"}}NetappBasePath{{"}}"}}projects/{{"{{"}}project{{"}}"}}/locations/{{"{{"}}location{{"}}"}}/kmsConfigs/{{"{{"}}name{{"}}"}}:verify") + if err != nil { + return err + } + + res_kms_verify, err := transport_tpg.SendRequest(transport_tpg.SendRequestOptions{ + Config: config, + Method: "POST", + Project: billingProject, + RawURL: url_kms_verify, + UserAgent: userAgent, + Timeout: d.Timeout(schema.TimeoutCreate), + }) + if err != nil { + return fmt.Errorf("Error verifying kmsconfig: %s", err) + } + log.Printf("[DEBUG] Finished verifying kmsconfig : %#v",res_kms_verify) \ No newline at end of file diff --git a/mmv1/templates/terraform/post_create/go/accesspolicy.tmpl b/mmv1/templates/terraform/post_create/go/accesspolicy.tmpl new file mode 100644 index 000000000000..b6590cdf11cb --- /dev/null +++ b/mmv1/templates/terraform/post_create/go/accesspolicy.tmpl @@ -0,0 +1,11 @@ +// The operation for this resource contains the generated name that we need +// in order to perform a READ. We need to access the object inside of it as +// a map[string]interface, so let's do that. + +resp := res["response"].(map[string]interface{}) +name := tpgresource.GetResourceNameFromSelfLink(resp["name"].(string)) +log.Printf("[DEBUG] Setting AccessPolicy name, id to %s", name) +if err := d.Set("name", name); err != nil { + return fmt.Errorf("Error setting name: %s", err) +} +d.SetId(name) diff --git a/mmv1/templates/terraform/post_create/go/agent_pool.go.tmpl b/mmv1/templates/terraform/post_create/go/agent_pool.go.tmpl new file mode 100644 index 000000000000..379d65fe7de4 --- /dev/null +++ b/mmv1/templates/terraform/post_create/go/agent_pool.go.tmpl @@ -0,0 +1,3 @@ +if err := waitForAgentPoolReady(d, config, d.Timeout(schema.TimeoutCreate) - time.Minute); err != nil { + return fmt.Errorf("Error waiting for AgentPool %q to be CREATED during creation: %q", d.Get("name").(string), err) +} \ No newline at end of file diff --git a/mmv1/templates/terraform/post_create/go/bigquery_connection_id.go.tmpl b/mmv1/templates/terraform/post_create/go/bigquery_connection_id.go.tmpl new file mode 100644 index 000000000000..a9233e746abe --- /dev/null +++ b/mmv1/templates/terraform/post_create/go/bigquery_connection_id.go.tmpl @@ -0,0 +1,14 @@ +if tpgresource.IsEmptyValue(reflect.ValueOf(d.Get("connection_id"))) { + // connection id is set by API when unset and required to GET the connection + // it is set by reading the "name" field rather than a field in the response + if err := d.Set("connection_id", flattenBigqueryConnectionConnectionConnectionId("", d, config)); err != nil { + return fmt.Errorf("Error reading Connection: %s", err) + } +} + +// Reset id to make sure connection_id is not empty +id2, err := tpgresource.ReplaceVars(d, config, "projects/{{"{{"}}project{{"}}"}}/locations/{{"{{"}}location{{"}}"}}/connections/{{"{{"}}connection_id{{"}}"}}") +if err != nil { + return fmt.Errorf("Error constructing id: %s", err) +} +d.SetId(id2) \ No newline at end of file diff --git a/mmv1/templates/terraform/post_create/go/bigquery_dataset_access.go.tmpl b/mmv1/templates/terraform/post_create/go/bigquery_dataset_access.go.tmpl new file mode 100644 index 000000000000..553c0eb479b1 --- /dev/null +++ b/mmv1/templates/terraform/post_create/go/bigquery_dataset_access.go.tmpl @@ -0,0 +1,40 @@ +{{- /* + The license inside this block applies to this file + Copyright 2024 Google Inc. + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/}} + +// by default, we are not updating the member +if err := d.Set("api_updated_member", false); err != nil { + return fmt.Errorf("Error setting api_updated_member: %s", err) +} + +// iam_member is a generalized attribute, if the API can map it to a different member type on the backend, it will return +// the correct member_type in the response. If it cannot be mapped to a different member type, it will stay in iam_member. +if iamMemberProp != "" { + member_type, member, err := resourceBigQueryDatasetAccessReassignIamMemberInNestedObjectList(d, meta, res["access"].([]interface{})) + if err != nil { + fmt.Println(err) + } + + // if the member type changed, we set that member_type in state (it's already in the response) and we clear iam_member + // and we set "api_updated_member" to true to acknowledge that we are making this change + if member_type != "" { + if err := d.Set(member_type, member.(string)); err != nil { + return fmt.Errorf("Error setting member_type: %s", err) + } + if err := d.Set("iam_member", ""); err != nil { + return fmt.Errorf("Error setting iam_member: %s", err) + } + if err := d.Set("api_updated_member", true); err != nil { + return fmt.Errorf("Error setting api_updated_member: %s", err) + } + } +} \ No newline at end of file diff --git a/mmv1/templates/terraform/post_create/go/cloud_asset_feed.go.tmpl b/mmv1/templates/terraform/post_create/go/cloud_asset_feed.go.tmpl new file mode 100644 index 000000000000..ea3cf4fe41b0 --- /dev/null +++ b/mmv1/templates/terraform/post_create/go/cloud_asset_feed.go.tmpl @@ -0,0 +1,2 @@ +// Restore the original value of user_project_override. +config.UserProjectOverride = origUserProjectOverride \ No newline at end of file diff --git a/mmv1/templates/terraform/post_create/go/cloud_scheduler.go.tmpl b/mmv1/templates/terraform/post_create/go/cloud_scheduler.go.tmpl new file mode 100644 index 000000000000..19881b2c60bd --- /dev/null +++ b/mmv1/templates/terraform/post_create/go/cloud_scheduler.go.tmpl @@ -0,0 +1,29 @@ +endpoint := "resume" // Default to enabled +logSuccessMsg := "Job state has been set to ENABLED" +if paused, pausedOk := d.GetOk("paused"); pausedOk && paused.(bool) { + endpoint = "pause" + logSuccessMsg = "Job state has been set to PAUSED" +} + +linkTmpl := fmt.Sprintf("{{"{{"}}CloudSchedulerBasePath{{"}}"}}projects/{{"{{"}}project{{"}}"}}/locations/{{"{{"}}region{{"}}"}}/jobs/{{"{{"}}name{{"}}"}}:%s", endpoint) +url, err = tpgresource.ReplaceVars(d, config, linkTmpl) +if err != nil { + return err +} + +emptyReqBody := make(map[string]interface{}) + +_, err = transport_tpg.SendRequest(transport_tpg.SendRequestOptions{ + Config: config, + Method: "POST", + Project: billingProject, + RawURL: url, + UserAgent: userAgent, + Body: emptyReqBody, + Timeout: d.Timeout(schema.TimeoutUpdate), +}) +if err != nil { + return fmt.Errorf("Error setting Cloud Scheduler Job status: %s", err) +} + +log.Printf("[DEBUG] Finished updating Job %q status: %s", d.Id(), logSuccessMsg) \ No newline at end of file diff --git a/mmv1/templates/terraform/post_create/go/cloudbuild_bitbucketserver_config.go.tmpl b/mmv1/templates/terraform/post_create/go/cloudbuild_bitbucketserver_config.go.tmpl new file mode 100644 index 000000000000..49f026ce494f --- /dev/null +++ b/mmv1/templates/terraform/post_create/go/cloudbuild_bitbucketserver_config.go.tmpl @@ -0,0 +1,50 @@ +log.Printf("[DEBUG] Finished creating BitbucketServerConfig without connected repos: %q: %#v", d.Id(), res) + +if v, ok := d.GetOkExists("connected_repositories"); !tpgresource.IsEmptyValue(reflect.ValueOf(connectedRepositoriesProp)) && (ok || !reflect.DeepEqual(v, connectedRepositoriesProp)) { + connectedReposPropArray, ok := connectedRepositoriesProp.([]interface{}) + if !ok { + return fmt.Errorf("Error reading connected_repositories") + } + + requests := make([]interface{}, len(connectedReposPropArray)) + for i := 0; i < len(connectedReposPropArray); i++ { + connectedRepo := make(map[string]interface{}) + connectedRepo["parent"] = id + connectedRepo["repo"] = connectedReposPropArray[i] + + connectedRepoRequest := make(map[string]interface{}) + connectedRepoRequest["parent"] = id + connectedRepoRequest["bitbucketServerConnectedRepository"] = connectedRepo + + requests[i] = connectedRepoRequest + } + obj = make(map[string]interface{}) + obj["requests"] = requests + + url, err = tpgresource.ReplaceVars(d, config, "{{"{{"}}CloudBuildBasePath{{"}}"}}projects/{{"{{"}}project{{"}}"}}/locations/{{"{{"}}location{{"}}"}}/bitbucketServerConfigs/{{"{{"}}config_id{{"}}"}}/connectedRepositories:batchCreate") + if err != nil { + return err + } + + res, err = transport_tpg.SendRequest(transport_tpg.SendRequestOptions{ + Config: config, + Method: "POST", + Project: billingProject, + RawURL: url, + UserAgent: userAgent, + Body: obj, + Timeout: d.Timeout(schema.TimeoutCreate), + }) + if err != nil { + return fmt.Errorf("Error creating connected_repositories: %s", err) + } + + err = CloudBuildOperationWaitTime( + config, res, project, "Creating connected_repositories on BitbucketServerConfig", userAgent, + d.Timeout(schema.TimeoutCreate)) + if err != nil { + return fmt.Errorf("Error waiting to create connected_repositories: %s", err) + } +} else { + log.Printf("[DEBUG] No connected repositories found to create: %#v", connectedRepositoriesProp) +} diff --git a/mmv1/templates/terraform/post_create/go/cloudbuild_trigger_id.go.tmpl b/mmv1/templates/terraform/post_create/go/cloudbuild_trigger_id.go.tmpl new file mode 100644 index 000000000000..e14ecb55adc9 --- /dev/null +++ b/mmv1/templates/terraform/post_create/go/cloudbuild_trigger_id.go.tmpl @@ -0,0 +1,18 @@ +// `name` is autogenerated from the api so needs to be set post-create +triggerId, ok := res["id"] +if !ok { + return fmt.Errorf("Create response didn't contain id. Create may not have succeeded.") +} +if err := d.Set("trigger_id", triggerId.(string)); err != nil { + return fmt.Errorf("Error setting trigger_id: %s", err) +} + +// Store the ID now. We tried to set it before and it failed because +// trigger_id didn't exist yet. +id, err = tpgresource.ReplaceVars(d, config, "projects/{{"{{"}}project{{"}}"}}/locations/{{"{{"}}location{{"}}"}}/triggers/{{"{{"}}trigger_id{{"}}"}}") +if err != nil { + return fmt.Errorf("Error constructing id: %s", err) +} +// Force legacy id format for global triggers. +id = strings.ReplaceAll(id, "/locations/global/", "/") +d.SetId(id) diff --git a/mmv1/templates/terraform/post_create/go/clouddomains_registration.go.tmpl b/mmv1/templates/terraform/post_create/go/clouddomains_registration.go.tmpl new file mode 100644 index 000000000000..e4dbffadddf0 --- /dev/null +++ b/mmv1/templates/terraform/post_create/go/clouddomains_registration.go.tmpl @@ -0,0 +1,3 @@ +if err := waitForRegistrationActive(d, config, d.Timeout(schema.TimeoutCreate)-time.Minute); err != nil { + return fmt.Errorf("Error waiting for Registration %q to be ACTIVE during creation: %q", d.Get("name").(string), err) +} \ No newline at end of file diff --git a/mmv1/templates/terraform/post_create/go/compute_backend_bucket_security_policy.go.tmpl b/mmv1/templates/terraform/post_create/go/compute_backend_bucket_security_policy.go.tmpl new file mode 100644 index 000000000000..204e0d6f8c12 --- /dev/null +++ b/mmv1/templates/terraform/post_create/go/compute_backend_bucket_security_policy.go.tmpl @@ -0,0 +1,19 @@ +// security_policy isn't set by Create / Update +if o, n := d.GetChange("edge_security_policy"); o.(string) != n.(string) { + pol, err := tpgresource.ParseSecurityPolicyFieldValue(n.(string), d, config) + if err != nil { + return errwrap.Wrapf("Error parsing Backend Service security policy: {{"{{"}}err{{"}}"}}", err) + } + + spr := emptySecurityPolicyReference() + spr.SecurityPolicy = pol.RelativeLink() + op, err := config.NewComputeClient(userAgent).BackendBuckets.SetEdgeSecurityPolicy(project, obj["name"].(string), spr).Do() + if err != nil { + return errwrap.Wrapf("Error setting Backend Service security policy: {{"{{"}}err{{"}}"}}", err) + } + // This uses the create timeout for simplicity, though technically this code appears in both create and update + waitErr := ComputeOperationWaitTime(config, op, project, "Setting Backend Service Security Policy", userAgent, d.Timeout(schema.TimeoutCreate)) + if waitErr != nil { + return waitErr + } +} diff --git a/mmv1/templates/terraform/post_create/go/compute_backend_service_security_policy.go.tmpl b/mmv1/templates/terraform/post_create/go/compute_backend_service_security_policy.go.tmpl new file mode 100644 index 000000000000..0d70f9a5e16e --- /dev/null +++ b/mmv1/templates/terraform/post_create/go/compute_backend_service_security_policy.go.tmpl @@ -0,0 +1,38 @@ +// security_policy isn't set by Create / Update +if o, n := d.GetChange("security_policy"); o.(string) != n.(string) { + pol, err := tpgresource.ParseSecurityPolicyFieldValue(n.(string), d, config) + if err != nil { + return errwrap.Wrapf("Error parsing Backend Service security policy: {{"{{"}}err{{"}}"}}", err) + } + + spr := emptySecurityPolicyReference() + spr.SecurityPolicy = pol.RelativeLink() + op, err := config.NewComputeClient(userAgent).BackendServices.SetSecurityPolicy(project, obj["name"].(string), spr).Do() + if err != nil { + return errwrap.Wrapf("Error setting Backend Service security policy: {{"{{"}}err{{"}}"}}", err) + } + // This uses the create timeout for simplicity, though technically this code appears in both create and update + waitErr := ComputeOperationWaitTime(config, op, project, "Setting Backend Service Security Policy", userAgent, d.Timeout(schema.TimeoutCreate)) + if waitErr != nil { + return waitErr + } +} +// edge security_policy isn't set by Create / Update +if o, n := d.GetChange("edge_security_policy"); o.(string) != n.(string) { + pol, err := tpgresource.ParseSecurityPolicyFieldValue(n.(string), d, config) + if err != nil { + return errwrap.Wrapf("Error parsing Backend Service edge security policy: {{"{{"}}err{{"}}"}}", err) + } + + spr := emptySecurityPolicyReference() + spr.SecurityPolicy = pol.RelativeLink() + op, err := config.NewComputeClient(userAgent).BackendServices.SetEdgeSecurityPolicy(project, obj["name"].(string), spr).Do() + if err != nil { + return errwrap.Wrapf("Error setting Backend Service edge security policy: {{"{{"}}err{{"}}"}}", err) + } + // This uses the create timeout for simplicity, though technically this code appears in both create and update + waitErr := ComputeOperationWaitTime(config, op, project, "Setting Backend Service Edge Security Policy", userAgent, d.Timeout(schema.TimeoutCreate)) + if waitErr != nil { + return waitErr + } +} \ No newline at end of file diff --git a/mmv1/templates/terraform/post_create/go/compute_network_delete_default_route.tmpl b/mmv1/templates/terraform/post_create/go/compute_network_delete_default_route.tmpl new file mode 100644 index 000000000000..9d9ddbbb33ee --- /dev/null +++ b/mmv1/templates/terraform/post_create/go/compute_network_delete_default_route.tmpl @@ -0,0 +1,31 @@ +if d.Get("delete_default_routes_on_create").(bool) { + token := "" + for paginate := true; paginate; { + network, err := config.NewComputeClient(userAgent).Networks.Get(project, d.Get("name").(string)).Do() + if err != nil { + return fmt.Errorf("Error finding network in proj: %s", err) + } + filter := fmt.Sprintf("(network=\"%s\") AND (destRange=\"0.0.0.0/0\")", network.SelfLink) + log.Printf("[DEBUG] Getting routes for network %q with filter '%q'", d.Get("name").(string), filter) + resp, err := config.NewComputeClient(userAgent).Routes.List(project).Filter(filter).Do() + if err != nil { + return fmt.Errorf("Error listing routes in proj: %s", err) + } + + log.Printf("[DEBUG] Found %d routes rules in %q network", len(resp.Items), d.Get("name").(string)) + + for _, route := range resp.Items { + op, err := config.NewComputeClient(userAgent).Routes.Delete(project, route.Name).Do() + if err != nil { + return fmt.Errorf("Error deleting route: %s", err) + } + err = ComputeOperationWaitTime(config, op, project, "Deleting Route", userAgent, d.Timeout(schema.TimeoutCreate)) + if err != nil { + return err + } + } + + token = resp.NextPageToken + paginate = token != "" + } +} diff --git a/mmv1/templates/terraform/post_create/go/compute_region_backend_service_security_policy.go.tmpl b/mmv1/templates/terraform/post_create/go/compute_region_backend_service_security_policy.go.tmpl new file mode 100644 index 000000000000..e83d020220b5 --- /dev/null +++ b/mmv1/templates/terraform/post_create/go/compute_region_backend_service_security_policy.go.tmpl @@ -0,0 +1,39 @@ +{{- if ne $.TargetVersionName "ga" }} +// security_policy isn't set by Create +if v, ok := d.GetOkExists("security_policy"); !tpgresource.IsEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, securityPolicyProp)) { + err = resourceComputeRegionBackendServiceRead(d, meta) + if err != nil { + return err + } + + obj := make(map[string]interface{}) + securityPolicyProp, err := expandComputeRegionBackendServiceSecurityPolicy(v, d, config) + if err != nil { + return err + } + obj["security_policy"] = securityPolicyProp + + url, err := tpgresource.ReplaceVars(d, config, "{{"{{"}}ComputeBasePath{{"}}"}}projects/{{"{{"}}project{{"}}"}}/regions/{{"{{"}}region{{"}}"}}/backendServices/{{"{{"}}name{{"}}"}}/setSecurityPolicy") + if err != nil { + return err + } + + res, err = transport_tpg.SendRequest(transport_tpg.SendRequestOptions{ + Config: config, + Method: "POST", + Project: project, + RawURL: url, + UserAgent: userAgent, + Body: obj, + }) + + if err != nil { + return fmt.Errorf("Error adding SecurityPolicy to RegionBackendService %q: %s", d.Id(), err) + } + + err = ComputeOperationWaitTime(config, res, project, "Updating RegionBackendService SecurityPolicy", userAgent, d.Timeout(schema.TimeoutUpdate)) + if err != nil { + return err + } +} +{{- end }} diff --git a/mmv1/templates/terraform/post_create/go/compute_target_instance_security_policy.go.tmpl b/mmv1/templates/terraform/post_create/go/compute_target_instance_security_policy.go.tmpl new file mode 100644 index 000000000000..e26b30970c46 --- /dev/null +++ b/mmv1/templates/terraform/post_create/go/compute_target_instance_security_policy.go.tmpl @@ -0,0 +1,34 @@ +{{- if ne $.TargetVersionName "ga" }} +// security_policy isn't set by Create +if v, ok := d.GetOkExists("security_policy"); !tpgresource.IsEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, securityPolicyProp)) { + obj := make(map[string]interface{}) + securityPolicyProp, err := expandComputeTargetInstanceSecurityPolicy(v, d, config) + if err != nil { + return err + } + obj["security_policy"] = securityPolicyProp + + url, err := tpgresource.ReplaceVars(d, config, "{{"{{"}}ComputeBasePath{{"}}"}}projects/{{"{{"}}project{{"}}"}}/zones/{{"{{"}}zone{{"}}"}}/targetInstances/{{"{{"}}name{{"}}"}}/setSecurityPolicy") + if err != nil { + return err + } + + res, err = transport_tpg.SendRequest(transport_tpg.SendRequestOptions{ + Config: config, + Method: "POST", + Project: project, + RawURL: url, + UserAgent: userAgent, + Body: obj, + }) + + if err != nil { + return fmt.Errorf("Error adding SecurityPolicy to TargetInstance %q: %s", d.Id(), err) + } + + err = ComputeOperationWaitTime(config, res, project, "Updating TargetInstance SecurityPolicy", userAgent, d.Timeout(schema.TimeoutUpdate)) + if err != nil { + return err + } +} +{{- end }} \ No newline at end of file diff --git a/mmv1/templates/terraform/post_create/go/datastream_stream.go.tmpl b/mmv1/templates/terraform/post_create/go/datastream_stream.go.tmpl new file mode 100644 index 000000000000..057721e7f21a --- /dev/null +++ b/mmv1/templates/terraform/post_create/go/datastream_stream.go.tmpl @@ -0,0 +1,22 @@ +{{- /* + The license inside this block applies to this file + Copyright 2024 Google Inc. + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/}} +if err := waitForDatastreamStreamReady(d, config, d.Timeout(schema.TimeoutCreate) - time.Minute); err != nil { + return fmt.Errorf("Error waiting for Stream %q to be NOT_STARTED or RUNNING during creation: %q", d.Get("name").(string), err) +} + +if d.Get("state") != d.Get("desired_state") { + log.Printf("[DEBUG] Desired state %s not equal to state = %s, updating stream %q", d.Get("desired_state"), d.Get("state"), d.Id()) + if err = resourceDatastreamStreamUpdate(d, meta); err != nil { + return fmt.Errorf("Error updating Stream %q during creation: %q", d.Get("name").(string), err) + } +} diff --git a/mmv1/templates/terraform/post_create/go/firebase_database_instance.go.tmpl b/mmv1/templates/terraform/post_create/go/firebase_database_instance.go.tmpl new file mode 100644 index 000000000000..a9edcacbcac1 --- /dev/null +++ b/mmv1/templates/terraform/post_create/go/firebase_database_instance.go.tmpl @@ -0,0 +1,20 @@ +{{- /* + The license inside this block applies to this file + Copyright 2024 Google Inc. + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/}} + +// start of customized code +if p, ok := d.GetOk("desired_state"); ok && p.(string) == "DISABLED" { + if err := disableRTDB(config, d, project, billingProject, userAgent); err != nil { + return err + } +} +// end of customized code diff --git a/mmv1/templates/terraform/post_create/go/firebasehosting_custom_domain_wait_dns_verification.tmpl b/mmv1/templates/terraform/post_create/go/firebasehosting_custom_domain_wait_dns_verification.tmpl new file mode 100644 index 000000000000..3772581bc2bc --- /dev/null +++ b/mmv1/templates/terraform/post_create/go/firebasehosting_custom_domain_wait_dns_verification.tmpl @@ -0,0 +1,14 @@ +if d.Get("wait_dns_verification") == true { + // Wait for the creation operation to complete before treating the resource + // as created + var opRes map[string]interface{} + err = FirebaseHostingOperationWaitTimeWithResponse( + config, res, &opRes, project, "Creating CustomDomain", userAgent, + d.Timeout(schema.TimeoutCreate)) + if err != nil { + // The resource didn't actually create + d.SetId("") + + return fmt.Errorf("Error waiting to create CustomDomain: %s", err) + } +} \ No newline at end of file diff --git a/mmv1/templates/terraform/post_create/go/firebasehosting_release.tmpl b/mmv1/templates/terraform/post_create/go/firebasehosting_release.tmpl new file mode 100644 index 000000000000..0c1463abb1c4 --- /dev/null +++ b/mmv1/templates/terraform/post_create/go/firebasehosting_release.tmpl @@ -0,0 +1,6 @@ +// Store the name as ID +d.SetId(res["name"].(string)) + +if err = d.Set("release_id", tpgresource.GetResourceNameFromSelfLink(res["name"].(string))); err != nil { + return fmt.Errorf("Error setting release_id: %s", err) +} \ No newline at end of file diff --git a/mmv1/templates/terraform/post_create/go/firebasehosting_version_immediate_finalize.tmpl b/mmv1/templates/terraform/post_create/go/firebasehosting_version_immediate_finalize.tmpl new file mode 100644 index 000000000000..21fa8b8d9611 --- /dev/null +++ b/mmv1/templates/terraform/post_create/go/firebasehosting_version_immediate_finalize.tmpl @@ -0,0 +1,39 @@ + // Store the name as ID + d.SetId(res["name"].(string)) + + if err = d.Set("version_id", tpgresource.GetResourceNameFromSelfLink(res["name"].(string))); err != nil { + return fmt.Errorf("Error setting version_id: %s", err) + } + + obj = make(map[string]interface{}) + obj["status"] = "FINALIZED" + + url, err = tpgresource.ReplaceVars(d, config, "{{"{{"}}FirebaseHostingBasePath{{"}}"}}{{"{{"}}name{{"}}"}}") + if err != nil { + return err + } + + log.Printf("[DEBUG] Updating Version %q: %#v", d.Id(), obj) + updateMask := []string{} + + updateMask = append(updateMask, "status") + url, err = transport_tpg.AddQueryParams(url, map[string]string{"updateMask": strings.Join(updateMask, ",")}) + if err != nil { + return err + } + + res, err = transport_tpg.SendRequest(transport_tpg.SendRequestOptions{ + Config: config, + Method: "PATCH", + Project: billingProject, + RawURL: url, + UserAgent: userAgent, + Body: obj, + Timeout: d.Timeout(schema.TimeoutUpdate), + }) + + if err != nil { + return fmt.Errorf("Error finalizing Version %q: %s", d.Id(), err) + } else { + log.Printf("[DEBUG] Finished finalizing Version %q: %#v", d.Id(), res) + } \ No newline at end of file diff --git a/mmv1/templates/terraform/post_create/go/gcip_tenant.go.tmpl b/mmv1/templates/terraform/post_create/go/gcip_tenant.go.tmpl new file mode 100644 index 000000000000..e9a0de49ec1d --- /dev/null +++ b/mmv1/templates/terraform/post_create/go/gcip_tenant.go.tmpl @@ -0,0 +1,14 @@ +// `name` is autogenerated from the api so needs to be set post-create +name, ok := res["name"] +if !ok { + return fmt.Errorf("Create response didn't contain critical fields. Create may not have succeeded.") +} +if err := d.Set("name", tpgresource.GetResourceNameFromSelfLink(name.(string))); err != nil { + return fmt.Errorf("Error setting name: %s", err) +} +// Store the ID now that we have set the computed name +id, err = tpgresource.ReplaceVars(d, config, "projects/{{"{{"}}project{{"}}"}}/tenants/{{"{{"}}name{{"}}"}}") +if err != nil { + return fmt.Errorf("Error constructing id: %s", err) +} +d.SetId(id) diff --git a/mmv1/templates/terraform/post_create/go/global_network_endpoint_group.go.tmpl b/mmv1/templates/terraform/post_create/go/global_network_endpoint_group.go.tmpl new file mode 100644 index 000000000000..6731a58c4df7 --- /dev/null +++ b/mmv1/templates/terraform/post_create/go/global_network_endpoint_group.go.tmpl @@ -0,0 +1,33 @@ +endpointObj := make(map[string]interface{}) +if v, ok := d.GetOkExists("fqdn"); !tpgresource.IsEmptyValue(reflect.ValueOf(fqdnProp)) && (ok || !reflect.DeepEqual(v, fqdnProp)) { + endpointObj["fqdn"] = fqdnProp +} +if v, ok := d.GetOkExists("port"); !tpgresource.IsEmptyValue(reflect.ValueOf(portProp)) && (ok || !reflect.DeepEqual(v, portProp)) { + endpointObj["port"] = portProp +} +if v, ok := d.GetOkExists("ip_address"); !tpgresource.IsEmptyValue(reflect.ValueOf(ipAddressProp)) && (ok || !reflect.DeepEqual(v, ipAddressProp)) { + endpointObj["ipAddress"] = ipAddressProp +} + +wrappedReq := map[string]interface{}{ + "networkEndpoints": []interface{}{endpointObj}, +} + +attachUrl, err := tpgresource.ReplaceVars(d, config, "{{"{{"}}ComputeBasePath{{"}}"}}projects/{{"{{"}}project{{"}}"}}/global/networkEndpointGroups/{{"{{"}}name{{"}}"}}/attachNetworkEndpoints") +if err != nil { + return err +} + +log.Printf("[DEBUG] Creating new GlobalNetworkEndpoint: %#v", wrappedReq) +_, err = transport_tpg.SendRequest(transport_tpg.SendRequestOptions{ + Config: config, + Method: "POST", + Project: project, + RawURL: attachUrl, + UserAgent: userAgent, + Body: wrappedReq, + Timeout: d.Timeout(schema.TimeoutCreate), +}) +if err != nil { + return fmt.Errorf("Error creating GlobalNetworkEndpoint: %s", err) +} \ No newline at end of file diff --git a/mmv1/templates/terraform/post_create/go/group.tmpl b/mmv1/templates/terraform/post_create/go/group.tmpl new file mode 100644 index 000000000000..158d4b5021e6 --- /dev/null +++ b/mmv1/templates/terraform/post_create/go/group.tmpl @@ -0,0 +1,4 @@ +d.SetId(flattenMonitoringGroupName(res["name"]).(string)) +if err := d.Set("name", flattenMonitoringGroupName(res["name"])); err != nil { + return fmt.Errorf("Error setting name: %s", err) +} \ No newline at end of file diff --git a/mmv1/templates/terraform/post_create/go/iam_workforce_pool_provider.go.tmpl b/mmv1/templates/terraform/post_create/go/iam_workforce_pool_provider.go.tmpl new file mode 100644 index 000000000000..25aaf9eb73b5 --- /dev/null +++ b/mmv1/templates/terraform/post_create/go/iam_workforce_pool_provider.go.tmpl @@ -0,0 +1,17 @@ +createdClientSecret := d.Get("oidc.0.client_secret.0.value.0.plain_text") +if createdClientSecret != nil && createdClientSecret != "" { + // After the create, reading from the API returns a new thumbprint + // for the client secret value, which clears the plain_text. We set the plain_text since + // this case should not warrant a diff. + if err := resourceIAMWorkforcePoolWorkforcePoolProviderRead(d, meta); err != nil { + return err + } + oidc := d.Get("oidc") + clientSecret := oidc.([]interface{})[0].(map[string]interface{})["client_secret"] + clientSecretValue := clientSecret.([]interface{})[0].(map[string]interface{})["value"] + clientSecretValue.([]interface{})[0].(map[string]interface{})["plain_text"] = createdClientSecret + if err := d.Set("oidc", oidc); err != nil { + return err + } + return nil +} diff --git a/mmv1/templates/terraform/post_create/go/iap_client.go.tmpl b/mmv1/templates/terraform/post_create/go/iap_client.go.tmpl new file mode 100644 index 000000000000..391bc3c6488c --- /dev/null +++ b/mmv1/templates/terraform/post_create/go/iap_client.go.tmpl @@ -0,0 +1,7 @@ +brand := d.Get("brand") +clientId := flattenIapClientClientId(res["name"], d, config) + +if err := d.Set("client_id", clientId); err != nil { + return fmt.Errorf("Error setting client_id: %s", err) +} +d.SetId(fmt.Sprintf("%s/identityAwareProxyClients/%s", brand, clientId)) diff --git a/mmv1/templates/terraform/post_create/go/index.go.tmpl b/mmv1/templates/terraform/post_create/go/index.go.tmpl new file mode 100644 index 000000000000..46b8313ae398 --- /dev/null +++ b/mmv1/templates/terraform/post_create/go/index.go.tmpl @@ -0,0 +1,21 @@ +{{- /* + The license inside this block applies to this file + Copyright 2024 Google Inc. + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/}} +// The operation for this resource contains the generated name that we need +// in order to perform a READ. +metadata := res["metadata"].(map[string]interface{}) +name := metadata["index"].(string) +log.Printf("[DEBUG] Setting Index name, id to %s", name) +if err := d.Set("name", name); err != nil { + return fmt.Errorf("Error setting name: %s", err) +} +d.SetId(name) diff --git a/mmv1/templates/terraform/post_create/go/integration_connectors_connection.go.tmpl b/mmv1/templates/terraform/post_create/go/integration_connectors_connection.go.tmpl new file mode 100644 index 000000000000..07fd1790b3d6 --- /dev/null +++ b/mmv1/templates/terraform/post_create/go/integration_connectors_connection.go.tmpl @@ -0,0 +1,3 @@ +if err := waitforConnectionReady(d, config, d.Timeout(schema.TimeoutCreate) - time.Minute); err != nil { + return fmt.Errorf("Error waiting for Connection %q to finish being in CREATING state during creation: %q", d.Get("name").(string), err) +} \ No newline at end of file diff --git a/mmv1/templates/terraform/post_create/go/interconnect_attachment.go.tmpl b/mmv1/templates/terraform/post_create/go/interconnect_attachment.go.tmpl new file mode 100644 index 000000000000..03e41d0e5da3 --- /dev/null +++ b/mmv1/templates/terraform/post_create/go/interconnect_attachment.go.tmpl @@ -0,0 +1,3 @@ +if err := waitForAttachmentToBeProvisioned(d, config, d.Timeout(schema.TimeoutCreate)); err != nil { + return fmt.Errorf("Error waiting for InterconnectAttachment %q to be provisioned: %q", d.Get("name").(string), err) +} diff --git a/mmv1/templates/terraform/post_create/go/kms_secret_ciphertext.go.tmpl b/mmv1/templates/terraform/post_create/go/kms_secret_ciphertext.go.tmpl new file mode 100644 index 000000000000..112605b2f1a4 --- /dev/null +++ b/mmv1/templates/terraform/post_create/go/kms_secret_ciphertext.go.tmpl @@ -0,0 +1,14 @@ +// we don't set anything on read and instead do it all in create +ciphertext, ok := res["ciphertext"] +if !ok { + return fmt.Errorf("Create response didn't contain critical fields. Create may not have succeeded.") +} +if err := d.Set("ciphertext", ciphertext.(string)); err != nil { + return fmt.Errorf("Error setting ciphertext: %s", err) +} + +id, err = tpgresource.ReplaceVars(d, config, "{{"{{"}}crypto_key{{"}}"}}/{{"{{"}}ciphertext{{"}}"}}") +if err != nil { + return fmt.Errorf("Error constructing id: %s", err) +} +d.SetId(id) diff --git a/mmv1/templates/terraform/post_create/go/labels.tmpl b/mmv1/templates/terraform/post_create/go/labels.tmpl new file mode 100644 index 000000000000..427d911cee87 --- /dev/null +++ b/mmv1/templates/terraform/post_create/go/labels.tmpl @@ -0,0 +1,67 @@ +{{- if $.HasLabelsField }} +if v, ok := d.GetOkExists("effective_labels"); !tpgresource.IsEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, labelsProp)) { + labels := d.Get("labels") + terraformLables := d.Get("terraform_labels") + + // Labels cannot be set in a create. We'll have to set them here. + err = resource{{$.ResourceName}}Read(d, meta) + if err != nil { + return err + } + + obj := make(map[string]interface{}) + // d.Get("effective_labels") will have been overridden by the Read call. + labelsProp, err := expand{{$.ResourceName}}EffectiveLabels(v, d, config) + if err != nil { + return err + } + obj["labels"] = labelsProp + labelFingerprintProp := d.Get("label_fingerprint") + obj["labelFingerprint"] = labelFingerprintProp + + url, err = tpgresource.ReplaceVars(d, config, "{{"{{"}}{{$.ProductMetadata.Name}}BasePath{{"}}"}}{{$.SelfLinkUri}}/setLabels") + if err != nil { + return err + } + res, err = transport_tpg.SendRequest(transport_tpg.SendRequestOptions{ + Config: config, + Method: "POST", + Project: project, + RawURL: url, + UserAgent: userAgent, + Body: obj, + {{- if $.ErrorRetryPredicates }} + ErrorRetryPredicates: []transport_tpg.RetryErrorPredicateFunc{ {{- join $.ErrorRetryPredicates "," -}} }, + {{- end }} + {{- if $.ErrorAbortPredicates }} + ErrorAbortPredicates: []transport_tpg.RetryErrorPredicateFunc{ {{- join $.ErrorAbortPredicates "," -}} }, + {{- end }} + }) + if err != nil { + return fmt.Errorf("Error adding labels to {{$.ResourceName}} %q: %s", d.Id(), err) + } + + err = ComputeOperationWaitTime( + config, res, project, "Updating {{$.ResourceName}} Labels", userAgent, + d.Timeout(schema.TimeoutUpdate)) + + if err != nil { + return err + } + + // Set back the labels field, as it is needed to decide the value of "labels" in the state in the read function. + if err := d.Set("labels", labels); err != nil { + return fmt.Errorf("Error setting back labels: %s", err) + } + + // Set back the terraform_labels field, as it is needed to decide the value of "terraform_labels" in the state in the read function. + if err := d.Set("terraform_labels", terraformLables); err != nil { + return fmt.Errorf("Error setting back terraform_labels: %s", err) + } + + // Set back the effective_labels field, as it is needed to decide the value of "effective_labels" in the state in the read function. + if err := d.Set("effective_labels", v); err != nil { + return fmt.Errorf("Error setting back effective_labels: %s", err) + } +} +{{- end }} diff --git a/mmv1/templates/terraform/post_create/go/lien.tmpl b/mmv1/templates/terraform/post_create/go/lien.tmpl new file mode 100644 index 000000000000..466d699b1129 --- /dev/null +++ b/mmv1/templates/terraform/post_create/go/lien.tmpl @@ -0,0 +1,11 @@ +// This resource is unusual - instead of returning an Operation from +// Create, it returns the created object itself. We don't parse +// any of the values there, preferring to centralize that logic in +// Read(). In this resource, Read is also unusual - it requires +// us to know the server-side generated name of the object we're +// trying to fetch, and the only way to know that is to capture +// it here. The following two lines do that. +d.SetId(flattenNestedResourceManagerLienName(res["name"], d, config).(string)) +if err := d.Set("name", flattenNestedResourceManagerLienName(res["name"], d, config)); err != nil { + return fmt.Errorf("Error setting name: %s", err) +} diff --git a/mmv1/templates/terraform/post_create/go/netapp_volume_replication_post_create.go.tmpl b/mmv1/templates/terraform/post_create/go/netapp_volume_replication_post_create.go.tmpl new file mode 100644 index 000000000000..b2d44a9c063e --- /dev/null +++ b/mmv1/templates/terraform/post_create/go/netapp_volume_replication_post_create.go.tmpl @@ -0,0 +1,7 @@ +if d.Get("wait_for_mirror").(bool) == true { + // Wait for mirrorState=MIRRORED before treating the resource as created + err = NetAppVolumeReplicationWaitForMirror(d, meta, "MIRRORED") + if err != nil { + return fmt.Errorf("Error waiting for volume replication to reach mirror_state==MIRRORED: %s", err) + } +} \ No newline at end of file diff --git a/mmv1/templates/terraform/post_create/go/notebooks_instance.go.tmpl b/mmv1/templates/terraform/post_create/go/notebooks_instance.go.tmpl new file mode 100644 index 000000000000..a70d7cb313a5 --- /dev/null +++ b/mmv1/templates/terraform/post_create/go/notebooks_instance.go.tmpl @@ -0,0 +1,13 @@ +if err := waitForNotebooksInstanceActive(d, config, d.Timeout(schema.TimeoutCreate) - time.Minute); err != nil { + return fmt.Errorf("Notebook instance %q did not reach ACTIVE state: %q", d.Get("name").(string), err) +} + +if p, ok := d.GetOk("desired_state"); ok && p.(string) == "STOPPED" { + dRes, err := modifyNotebooksInstanceState(config, d, project, billingProject, userAgent, "stop") + if err != nil { + return err + } + if err := waitForNotebooksOperation(config, d, project, billingProject, userAgent, dRes); err != nil { + return fmt.Errorf("Error stopping Notebook Instance: %s", err) + } +} diff --git a/mmv1/templates/terraform/post_create/go/org_security_policy.go.tmpl b/mmv1/templates/terraform/post_create/go/org_security_policy.go.tmpl new file mode 100644 index 000000000000..fe59801b201e --- /dev/null +++ b/mmv1/templates/terraform/post_create/go/org_security_policy.go.tmpl @@ -0,0 +1,26 @@ +parent := d.Get("parent").(string) +var opRes map[string]interface{} +err = ComputeOrgOperationWaitTimeWithResponse( + config, res, &opRes, parent, "Creating OrganizationSecurityPolicy", userAgent, + d.Timeout(schema.TimeoutCreate)) + +if err != nil { + // The resource didn't actually create + d.SetId("") + return fmt.Errorf("Error waiting to create OrganizationSecurityPolicy: %s", err) +} + +policyId, ok := opRes["targetId"] +if !ok { + return fmt.Errorf("Create response didn't contain targetId. Create may not have succeeded.") +} +if err := d.Set("policy_id", policyId.(string)); err != nil { + return fmt.Errorf("Error setting policy_id: %s", err) +} + +// Store the ID now. +id, err = tpgresource.ReplaceVars(d, config, "locations/global/securityPolicies/{{"{{"}}policy_id{{"}}"}}") +if err != nil { + return fmt.Errorf("Error constructing id: %s", err) +} +d.SetId(id) diff --git a/mmv1/templates/terraform/post_create/go/org_security_policy_association.go.tmpl b/mmv1/templates/terraform/post_create/go/org_security_policy_association.go.tmpl new file mode 100644 index 000000000000..6a2f47f6eefd --- /dev/null +++ b/mmv1/templates/terraform/post_create/go/org_security_policy_association.go.tmpl @@ -0,0 +1,29 @@ +// `parent` is needed to poll the asynchronous operations but its available only on the policy. + +policyUrl := fmt.Sprintf("{{"{{"}}ComputeBasePath{{"}}"}}%s", d.Get("policy_id")) +url, err = tpgresource.ReplaceVars(d, config, policyUrl) +if err != nil { + return err +} + +policyRes, err := transport_tpg.SendRequest(transport_tpg.SendRequestOptions{ + Config: config, + Method: "GET", + RawURL: url, + UserAgent: userAgent, +}) +if err != nil { + return transport_tpg.HandleNotFoundError(err, d, fmt.Sprintf("ComputeOrganizationSecurityPolicy %q", d.Get("policy_id"))) +} + +parent := flattenComputeOrganizationSecurityPolicyParent(policyRes["parent"], d, config) +var opRes map[string]interface{} +err = ComputeOrgOperationWaitTimeWithResponse( + config, res, &opRes, parent.(string), "Creating OrganizationSecurityPolicyAssociation", userAgent, + d.Timeout(schema.TimeoutCreate)) + +if err != nil { + // The resource didn't actually create + d.SetId("") + return fmt.Errorf("Error waiting to create OrganizationSecurityPolicyAssociation: %s", err) +} diff --git a/mmv1/templates/terraform/post_create/go/org_security_policy_rule.go.tmpl b/mmv1/templates/terraform/post_create/go/org_security_policy_rule.go.tmpl new file mode 100644 index 000000000000..201ad072e5f3 --- /dev/null +++ b/mmv1/templates/terraform/post_create/go/org_security_policy_rule.go.tmpl @@ -0,0 +1,29 @@ +// `parent` is needed to poll the asynchronous operations but its available only on the policy. + +policyUrl := fmt.Sprintf("{{"{{"}}ComputeBasePath{{"}}"}}%s", d.Get("policy_id")) +url, err = tpgresource.ReplaceVars(d, config, policyUrl) +if err != nil { + return err +} + +policyRes, err := transport_tpg.SendRequest(transport_tpg.SendRequestOptions{ + Config: config, + Method: "GET", + RawURL: url, + UserAgent: userAgent, +}) +if err != nil { + return transport_tpg.HandleNotFoundError(err, d, fmt.Sprintf("ComputeOrganizationSecurityPolicy %q", d.Get("policy_id"))) +} + +parent := flattenComputeOrganizationSecurityPolicyParent(policyRes["parent"], d, config) +var opRes map[string]interface{} +err = ComputeOrgOperationWaitTimeWithResponse( + config, res, &opRes, parent.(string), "Creating OrganizationSecurityPolicyRule", userAgent, + d.Timeout(schema.TimeoutCreate)) + +if err != nil { + // The resource didn't actually create + d.SetId("") + return fmt.Errorf("Error waiting to create OrganizationSecurityPolicyRule: %s", err) +} diff --git a/mmv1/templates/terraform/post_create/go/private_connection.go.tmpl b/mmv1/templates/terraform/post_create/go/private_connection.go.tmpl new file mode 100644 index 000000000000..7bd986d100bb --- /dev/null +++ b/mmv1/templates/terraform/post_create/go/private_connection.go.tmpl @@ -0,0 +1,3 @@ +if err := waitForPrivateConnectionReady(d, config, d.Timeout(schema.TimeoutCreate) - time.Minute); err != nil { + return fmt.Errorf("Error waiting for PrivateConnection %q to be CREATED. %q", d.Get("name").(string), err) +} diff --git a/mmv1/templates/terraform/post_create/go/privateca_certificate_authority.go.tmpl b/mmv1/templates/terraform/post_create/go/privateca_certificate_authority.go.tmpl new file mode 100644 index 000000000000..fac4ffece9ef --- /dev/null +++ b/mmv1/templates/terraform/post_create/go/privateca_certificate_authority.go.tmpl @@ -0,0 +1,24 @@ +staged := d.Get("type").(string) == "SELF_SIGNED" + +if d.Get("type").(string) == "SUBORDINATE" { + if _, ok := d.GetOk("subordinate_config"); ok { + // First party issuer + log.Printf("[DEBUG] Activating CertificateAuthority with first party issuer") + if err := activateSubCAWithFirstPartyIssuer(config, d, project, billingProject, userAgent); err != nil { + return fmt.Errorf("Error activating subordinate CA with first party issuer: %v", err) + } + staged = true + log.Printf("[DEBUG] CertificateAuthority activated") + } +} + + +// Enable the CA if `desired_state` is unspecified or specified as `ENABLED`. +if p, ok := d.GetOk("desired_state"); !ok || p.(string) == "ENABLED" { + // Skip enablement on SUBORDINATE CA for backward compatible. + if staged { + if err := enableCA(config, d, project, billingProject, userAgent); err != nil { + return fmt.Errorf("Error enabling CertificateAuthority: %v", err) + } + } +} diff --git a/mmv1/templates/terraform/post_create/go/secret_version.go.tmpl b/mmv1/templates/terraform/post_create/go/secret_version.go.tmpl new file mode 100644 index 000000000000..a718b67bee3a --- /dev/null +++ b/mmv1/templates/terraform/post_create/go/secret_version.go.tmpl @@ -0,0 +1,14 @@ +// `name` is autogenerated from the api so needs to be set post-create +name, ok := res["name"] +if !ok { + return fmt.Errorf("Create response didn't contain critical fields. Create may not have succeeded.") +} +if err := d.Set("name", name.(string)); err != nil { + return fmt.Errorf("Error setting name: %s", err) +} +d.SetId(name.(string)) + +_, err = expandSecretManagerSecretVersionEnabled(d.Get("enabled"), d, config) +if err != nil { + return err +} \ No newline at end of file diff --git a/mmv1/templates/terraform/post_create/go/set_computed_name.tmpl b/mmv1/templates/terraform/post_create/go/set_computed_name.tmpl new file mode 100644 index 000000000000..bd3ed030748b --- /dev/null +++ b/mmv1/templates/terraform/post_create/go/set_computed_name.tmpl @@ -0,0 +1,17 @@ +// `name` is autogenerated from the api so needs to be set post-create +name, ok := res["name"] +if !ok { + respBody, ok := res["response"] + if !ok { + return fmt.Errorf("Create response didn't contain critical fields. Create may not have succeeded.") + } + + name, ok = respBody.(map[string]interface{})["name"] + if !ok { + return fmt.Errorf("Create response didn't contain critical fields. Create may not have succeeded.") + } +} +if err := d.Set("name", name.(string)); err != nil { + return fmt.Errorf("Error setting name: %s", err) +} +d.SetId(name.(string)) diff --git a/mmv1/templates/terraform/post_create/go/sleep.go.tmpl b/mmv1/templates/terraform/post_create/go/sleep.go.tmpl new file mode 100644 index 000000000000..30b726f3bebc --- /dev/null +++ b/mmv1/templates/terraform/post_create/go/sleep.go.tmpl @@ -0,0 +1,4 @@ +// This is useful if the resource in question doesn't have a perfectly consistent API +// That is, the Operation for Create might return before the Get operation shows the +// completed state of the resource. +time.Sleep(5 * time.Second) diff --git a/mmv1/templates/terraform/post_create/go/sleep_2_min.go.tmpl b/mmv1/templates/terraform/post_create/go/sleep_2_min.go.tmpl new file mode 100644 index 000000000000..df48ca805713 --- /dev/null +++ b/mmv1/templates/terraform/post_create/go/sleep_2_min.go.tmpl @@ -0,0 +1,4 @@ +// This is useful if the resource in question doesn't have a perfectly consistent API +// That is, the Operation for Create might return before the Get operation shows the +// completed state of the resource. +time.Sleep(2 * time.Minute) diff --git a/mmv1/templates/terraform/post_create/go/source_repo_repository_update.go.tmpl b/mmv1/templates/terraform/post_create/go/source_repo_repository_update.go.tmpl new file mode 100644 index 000000000000..82a1b3402630 --- /dev/null +++ b/mmv1/templates/terraform/post_create/go/source_repo_repository_update.go.tmpl @@ -0,0 +1,5 @@ +if v, ok := d.GetOkExists("pubsub_configs"); !tpgresource.IsEmptyValue(reflect.ValueOf(pubsubConfigsProp)) && (ok || !reflect.DeepEqual(v, pubsubConfigsProp)) { + log.Printf("[DEBUG] Calling update after create to patch in pubsub_configs") + // pubsub_configs cannot be added on create + return resourceSourceRepoRepositoryUpdate(d, meta) +} \ No newline at end of file diff --git a/mmv1/templates/terraform/post_create/go/spanner_database.go.tmpl b/mmv1/templates/terraform/post_create/go/spanner_database.go.tmpl new file mode 100644 index 000000000000..b49f43559e4d --- /dev/null +++ b/mmv1/templates/terraform/post_create/go/spanner_database.go.tmpl @@ -0,0 +1,107 @@ +// Note: Databases that are created with POSTGRESQL dialect do not support extra DDL +// statements at the time of database creation. To avoid users needing to run +// `terraform apply` twice to get their desired outcome, the provider does not set +// `extraStatements` in the call to the `create` endpoint and all DDL (other than +// ) is run post-create, by calling the `updateDdl` endpoint + +_, ok := opRes["name"] +if !ok { + return fmt.Errorf("Create response didn't contain critical fields. Create may not have succeeded.") +} + +retention, retentionPeriodOk := d.GetOk("version_retention_period") +retentionPeriod := retention.(string) +ddl, ddlOk := d.GetOk("ddl") +ddlStatements := ddl.([]interface{}) + +if retentionPeriodOk || ddlOk { + + obj := make(map[string]interface{}) + updateDdls := []string{} + + if ddlOk { + for i := 0; i < len(ddlStatements); i++ { + if ddlStatements[i] != nil { + updateDdls = append(updateDdls, ddlStatements[i].(string)) + } + } + } + + if retentionPeriodOk { + dbName := d.Get("name") + retentionDdl := fmt.Sprintf("ALTER DATABASE `%s` SET OPTIONS (version_retention_period=\"%s\")", dbName, retentionPeriod) + if dialect, ok := d.GetOk("database_dialect"); ok && dialect == "POSTGRESQL" { + retentionDdl = fmt.Sprintf("ALTER DATABASE \"%s\" SET spanner.version_retention_period TO \"%s\"", dbName, retentionPeriod) + } + updateDdls = append(updateDdls, retentionDdl) + } + + // Skip API call if there are no new ddl entries (due to ignoring nil values) + if len(updateDdls) > 0 { + log.Printf("[DEBUG] Applying extra DDL statements to the new Database: %#v", updateDdls) + + obj["statements"] = updateDdls + + url, err = tpgresource.ReplaceVars(d, config, "{{"{{"}}SpannerBasePath{{"}}"}}projects/{{"{{"}}project{{"}}"}}/instances/{{"{{"}}instance{{"}}"}}/databases/{{"{{"}}name{{"}}"}}/ddl") + if err != nil { + return err + } + + res, err = transport_tpg.SendRequest(transport_tpg.SendRequestOptions{ + Config: config, + Method: "PATCH", + Project: billingProject, + RawURL: url, + UserAgent: userAgent, + Body: obj, + Timeout: d.Timeout(schema.TimeoutUpdate), + }) + if err != nil { + return fmt.Errorf("Error executing DDL statements on Database: %s", err) + } + + // Use the resource in the operation response to populate + // identity fields and d.Id() before read + var opRes map[string]interface{} + err = SpannerOperationWaitTimeWithResponse( + config, res, &opRes, project, "Creating Database", userAgent, + d.Timeout(schema.TimeoutCreate)) + if err != nil { + // The resource didn't actually create + d.SetId("") + return fmt.Errorf("Error waiting to run DDL against newly-created Database: %s", err) + } + } +} + +enableDropProtection, enableDropProtectionOk := d.GetOk("enable_drop_protection") +dropProtection := enableDropProtection.(bool) +if enableDropProtectionOk && dropProtection { + updateMask := []string{"enableDropProtection"} + url, err := tpgresource.ReplaceVars(d, config, "{{"{{"}}SpannerBasePath{{"}}"}}projects/{{"{{"}}project{{"}}"}}/instances/{{"{{"}}instance{{"}}"}}/databases/{{"{{"}}name{{"}}"}}") + if err != nil { + return err + } + // updateMask is a URL parameter but not present in the schema, so ReplaceVars + // won't set it + url, err = transport_tpg.AddQueryParams(url, map[string]string{"updateMask": strings.Join(updateMask, ",")}) + if err != nil { + return err + } + obj := map[string]interface{}{"enableDropProtection": dropProtection} + res, err := transport_tpg.SendRequest(transport_tpg.SendRequestOptions{ + Config: config, + Method: "PATCH", + Project: billingProject, + RawURL: url, + UserAgent: userAgent, + Body: obj, + Timeout: d.Timeout(schema.TimeoutUpdate), + }) + if err != nil { + return fmt.Errorf("Error updating enableDropDatabaseProtection on Database: %s", err) + } else { + log.Printf("[DEBUG] Finished updating enableDropDatabaseProtection %q: %#v", d.Id(), res) + } +} + diff --git a/mmv1/templates/terraform/post_create/go/sshkeyfingerprint.go.tmpl b/mmv1/templates/terraform/post_create/go/sshkeyfingerprint.go.tmpl new file mode 100644 index 000000000000..87964bac14b9 --- /dev/null +++ b/mmv1/templates/terraform/post_create/go/sshkeyfingerprint.go.tmpl @@ -0,0 +1,23 @@ + +loginProfile, ok := res["loginProfile"] +if !ok { + return fmt.Errorf("Create response didn't contain critical fields. Create may not have succeeded.") +} + +// `fingerprint` is autogenerated from the api so needs to be set post-create +sshPublicKeys := loginProfile.(map[string]interface{})["sshPublicKeys"] +for _,sshPublicKey := range sshPublicKeys.(map[string]interface{}) { + if sshPublicKey.(map[string]interface{})["key"].(string)== d.Get("key") { + if err := d.Set("fingerprint", sshPublicKey.(map[string]interface{})["fingerprint"].(string)); err != nil { + return fmt.Errorf("Error setting fingerprint: %s", err) + } + break + } +} + +// Store the ID now +id, err = tpgresource.ReplaceVars(d, config, "users/{{"{{"}}user{{"}}"}}/sshPublicKeys/{{"{{"}}fingerprint{{"}}"}}") +if err != nil { + return fmt.Errorf("Error constructing id: %s", err) +} +d.SetId(id) \ No newline at end of file diff --git a/mmv1/templates/terraform/post_create/go/storage_hmac_key.go.tmpl b/mmv1/templates/terraform/post_create/go/storage_hmac_key.go.tmpl new file mode 100644 index 000000000000..42999c347a67 --- /dev/null +++ b/mmv1/templates/terraform/post_create/go/storage_hmac_key.go.tmpl @@ -0,0 +1,27 @@ +// `secret` and `access_id` are generated by the API upon successful CREATE. The following +// ensures terraform has the correct values based on the Projects.hmacKeys response object. +secret, ok := res["secret"].(string) +if !ok { + return fmt.Errorf("The response to CREATE was missing an expected field. Your create did not work.") +} + +if err := d.Set("secret", secret); err != nil { + return fmt.Errorf("Error setting secret: %s", err) +} + +metadata := res["metadata"].(map[string]interface{}) +accessId, ok := metadata["accessId"].(string) +if !ok { + return fmt.Errorf("The response to CREATE was missing an expected field. Your create did not work.") +} + +if err := d.Set("access_id", accessId); err != nil { + return fmt.Errorf("Error setting access_id: %s", err) +} + +id, err = tpgresource.ReplaceVars(d, config, "projects/{{"{{"}}project{{"}}"}}/hmacKeys/{{"{{"}}access_id{{"}}"}}") +if err != nil { + return fmt.Errorf("Error constructing id: %s", err) +} + +d.SetId(id) diff --git a/mmv1/templates/terraform/post_create/go/workbench_instance.go.tmpl b/mmv1/templates/terraform/post_create/go/workbench_instance.go.tmpl new file mode 100644 index 000000000000..25128f95f821 --- /dev/null +++ b/mmv1/templates/terraform/post_create/go/workbench_instance.go.tmpl @@ -0,0 +1,13 @@ +if err := waitForWorkbenchInstanceActive(d, config, d.Timeout(schema.TimeoutCreate) - time.Minute); err != nil { + return fmt.Errorf("Workbench instance %q did not reach ACTIVE state: %q", d.Get("name").(string), err) +} + +if p, ok := d.GetOk("desired_state"); ok && p.(string) == "STOPPED" { + dRes, err := modifyWorkbenchInstanceState(config, d, project, billingProject, userAgent, "stop") + if err != nil { + return err + } + if err := waitForWorkbenchOperation(config, d, project, billingProject, userAgent, dRes); err != nil { + return fmt.Errorf("Error stopping Workbench Instance: %s", err) + } +} diff --git a/mmv1/templates/terraform/post_create/labels.erb b/mmv1/templates/terraform/post_create/labels.erb index 357979809086..f49515d97832 100644 --- a/mmv1/templates/terraform/post_create/labels.erb +++ b/mmv1/templates/terraform/post_create/labels.erb @@ -19,7 +19,7 @@ if v, ok := d.GetOkExists("effective_labels"); !tpgresource.IsEmptyValue(reflect labelFingerprintProp := d.Get("label_fingerprint") obj["labelFingerprint"] = labelFingerprintProp - url, err = tpgresource.ReplaceVars(d, config, "<%= "{{#{object.__product.name}BasePath}}#{object.self_link_uri}" -%>/setLabels") + url, err = tpgresource.ReplaceVars(d, config, "{{<%=object.__product.name-%>BasePath}}<%=object.self_link_uri-%>/setLabels") if err != nil { return err }