diff --git a/build/kcc/servicemappings/appengine.yaml b/build/kcc/servicemappings/appengine.yaml index d1cdb5baeadd..ee41432e73e6 100644 --- a/build/kcc/servicemappings/appengine.yaml +++ b/build/kcc/servicemappings/appengine.yaml @@ -9,10 +9,10 @@ spec: resources: - name: google_app_engine_firewall_rule kind: AppEngineFirewallRule - idTemplate: "{{project}}/{{priority}}" + idTemplate: "{{priority}}" metadataMapping: name: priority - name: google_app_engine_standard_app_version kind: AppEngineStandardAppVersion - idTemplate: "apps/{{project}}/services/{{service}}/versions/{{version_id}}" + idTemplate: "{{service}}/{{version_id}}" metadataMapping: diff --git a/build/kcc/servicemappings/bigquery.yaml b/build/kcc/servicemappings/bigquery.yaml index c0486cc62fb5..ffd6134d370c 100644 --- a/build/kcc/servicemappings/bigquery.yaml +++ b/build/kcc/servicemappings/bigquery.yaml @@ -9,7 +9,7 @@ spec: resources: - name: google_bigquery_dataset kind: BigQueryDataset - idTemplate: "{{project}}/{{dataset_id}}" + idTemplate: "{{dataset_id}}" metadataMapping: name: dataset_id labels: labels diff --git a/build/kcc/servicemappings/bigtable.yaml b/build/kcc/servicemappings/bigtable.yaml index a653d3c379bc..ef8dbb16cd2b 100644 --- a/build/kcc/servicemappings/bigtable.yaml +++ b/build/kcc/servicemappings/bigtable.yaml @@ -9,5 +9,5 @@ spec: resources: - name: google_bigtable_app_profile kind: BigtableAppProfile - idTemplate: "projects/{{project}}/instances/{{instance}}/appProfiles/{{app_profile_id}}" + idTemplate: "{{instance}}/{{app_profile_id}}" metadataMapping: diff --git a/build/kcc/servicemappings/binaryauthorization.yaml b/build/kcc/servicemappings/binaryauthorization.yaml index a279e6cbf8b9..a24910a93e46 100644 --- a/build/kcc/servicemappings/binaryauthorization.yaml +++ b/build/kcc/servicemappings/binaryauthorization.yaml @@ -9,10 +9,9 @@ spec: resources: - name: google_binary_authorization_attestor kind: BinaryAuthorizationAttestor - idTemplate: "projects/{{project}}/attestors/{{name}}" + idTemplate: "{{name}}" metadataMapping: name: name - name: google_binary_authorization_policy kind: BinaryAuthorizationPolicy - idTemplate: "projects/{{project}}" metadataMapping: diff --git a/build/kcc/servicemappings/cloudbuild.yaml b/build/kcc/servicemappings/cloudbuild.yaml index 60b00bed0ca8..4eb50ec41ce9 100644 --- a/build/kcc/servicemappings/cloudbuild.yaml +++ b/build/kcc/servicemappings/cloudbuild.yaml @@ -9,6 +9,6 @@ spec: resources: - name: google_cloudbuild_trigger kind: CloudBuildTrigger - idTemplate: "projects/{{project}}/triggers/{{trigger_id}}" + idTemplate: "{{trigger_id}}" metadataMapping: name: trigger_id diff --git a/build/kcc/servicemappings/cloudscheduler.yaml b/build/kcc/servicemappings/cloudscheduler.yaml index 56cccd95f94f..031ab1f3a9ae 100644 --- a/build/kcc/servicemappings/cloudscheduler.yaml +++ b/build/kcc/servicemappings/cloudscheduler.yaml @@ -9,6 +9,6 @@ spec: resources: - name: google_cloud_scheduler_job kind: CloudSchedulerJob - idTemplate: "projects/{{project}}/locations/{{region}}/jobs/{{name}}" + idTemplate: "{{name}}" metadataMapping: name: name diff --git a/build/kcc/servicemappings/compute.yaml b/build/kcc/servicemappings/compute.yaml index 6cc3e4bfa657..22c0e5890803 100644 --- a/build/kcc/servicemappings/compute.yaml +++ b/build/kcc/servicemappings/compute.yaml @@ -9,7 +9,7 @@ spec: resources: - name: google_compute_address kind: ComputeAddress - idTemplate: "projects/{{project}}/regions/{{region}}/addresses/{{name}}" + idTemplate: "{{name}}" metadataMapping: name: name resourceReferences: @@ -19,7 +19,7 @@ spec: required: false - name: google_compute_autoscaler kind: ComputeAutoscaler - idTemplate: "projects/{{project}}/zones/{{zone}}/autoscalers/{{name}}" + idTemplate: "{{zone}}/{{name}}" metadataMapping: name: name resourceReferences: @@ -29,31 +29,31 @@ spec: required: true - name: google_compute_backend_bucket kind: ComputeBackendBucket - idTemplate: "projects/{{project}}/global/backendBuckets/{{name}}" + idTemplate: "{{name}}" metadataMapping: name: name - name: google_compute_backend_bucket_signed_url_key kind: ComputeBackendBucketSignedUrlKey - idTemplate: "projects/{{project}}/global/backendBuckets/{{backend_bucket}}/{{name}}" + idTemplate: "{{backend_bucket}}/{{name}}" metadataMapping: - name: google_compute_backend_service kind: ComputeBackendService - idTemplate: "projects/{{project}}/global/backendServices/{{name}}" + idTemplate: "{{name}}" metadataMapping: name: name - name: google_compute_region_backend_service kind: ComputeRegionBackendService - idTemplate: "projects/{{project}}/regions/{{regionRef.name}}/backendServices/{{name}}" + idTemplate: "{{name}}" metadataMapping: name: name resourceReferences: - name: google_compute_backend_service_signed_url_key kind: ComputeBackendServiceSignedUrlKey - idTemplate: "projects/{{project}}/global/backendServices/{{backend_service}}/{{name}}" + idTemplate: "{{backend_service}}/{{name}}" metadataMapping: - name: google_compute_disk kind: ComputeDisk - idTemplate: "projects/{{project}}/zones/{{zone}}/disks/{{name}}" + idTemplate: "{{zone}}/{{name}}" metadataMapping: name: name labels: labels @@ -64,7 +64,7 @@ spec: required: false - name: google_compute_firewall kind: ComputeFirewall - idTemplate: "projects/{{project}}/global/firewalls/{{name}}" + idTemplate: "{{name}}" metadataMapping: name: name resourceReferences: @@ -74,7 +74,7 @@ spec: required: true - name: google_compute_forwarding_rule kind: ComputeForwardingRule - idTemplate: "projects/{{project}}/regions/{{region}}/forwardingRules/{{name}}" + idTemplate: "{{name}}" metadataMapping: name: name resourceReferences: @@ -96,7 +96,7 @@ spec: required: false - name: google_compute_global_address kind: ComputeGlobalAddress - idTemplate: "projects/{{project}}/global/addresses/{{name}}" + idTemplate: "{{name}}" metadataMapping: name: name resourceReferences: @@ -106,27 +106,27 @@ spec: required: false - name: google_compute_global_forwarding_rule kind: ComputeGlobalForwardingRule - idTemplate: "projects/{{project}}/global/forwardingRules/{{name}}" + idTemplate: "{{name}}" metadataMapping: name: name - name: google_compute_http_health_check kind: ComputeHttpHealthCheck - idTemplate: "projects/{{project}}/global/httpHealthChecks/{{name}}" + idTemplate: "{{name}}" metadataMapping: name: name - name: google_compute_https_health_check kind: ComputeHttpsHealthCheck - idTemplate: "projects/{{project}}/global/httpsHealthChecks/{{name}}" + idTemplate: "{{name}}" metadataMapping: name: name - name: google_compute_health_check kind: ComputeHealthCheck - idTemplate: "projects/{{project}}/global/healthChecks/{{name}}" + idTemplate: "{{name}}" metadataMapping: name: name - name: google_compute_image kind: ComputeImage - idTemplate: "projects/{{project}}/global/images/{{name}}" + idTemplate: "{{name}}" metadataMapping: name: name labels: labels @@ -137,7 +137,7 @@ spec: required: false - name: google_compute_interconnect_attachment kind: ComputeInterconnectAttachment - idTemplate: "projects/{{project}}/regions/{{region}}/interconnectAttachments/{{name}}" + idTemplate: "{{name}}" metadataMapping: name: name resourceReferences: @@ -147,12 +147,12 @@ spec: required: true - name: google_compute_network kind: ComputeNetwork - idTemplate: "projects/{{project}}/global/networks/{{name}}" + idTemplate: "{{name}}" metadataMapping: name: name - name: google_compute_network_endpoint kind: ComputeNetworkEndpoint - idTemplate: "projects/{{project}}/zones/{{zone}}/networkEndpointGroups/{{network_endpoint_group}}/{{instanceRef.name}}/{{ip_address}}/{{port}}" + idTemplate: "{{zone}}/{{network_endpoint_group}}/{{instanceRef.name}}/{{ip_address}}/{{port}}" metadataMapping: resourceReferences: - key: instanceRef @@ -161,7 +161,7 @@ spec: required: true - name: google_compute_network_endpoint_group kind: ComputeNetworkEndpointGroup - idTemplate: "projects/{{project}}/zones/{{zone}}/networkEndpointGroups/{{name}}" + idTemplate: "{{zone}}/{{name}}" metadataMapping: name: name resourceReferences: @@ -175,7 +175,7 @@ spec: required: false - name: google_compute_node_group kind: ComputeNodeGroup - idTemplate: "projects/{{project}}/zones/{{zone}}/nodeGroups/{{name}}" + idTemplate: "{{zone}}/{{name}}" metadataMapping: name: name resourceReferences: @@ -185,17 +185,17 @@ spec: required: true - name: google_compute_node_template kind: ComputeNodeTemplate - idTemplate: "projects/{{project}}/regions/{{region}}/nodeTemplates/{{name}}" + idTemplate: "{{name}}" metadataMapping: name: name - name: google_compute_region_autoscaler kind: ComputeRegionAutoscaler - idTemplate: "projects/{{project}}/regions/{{region}}/autoscalers/{{name}}" + idTemplate: "{{name}}" metadataMapping: name: name - name: google_compute_region_disk kind: ComputeRegionDisk - idTemplate: "projects/{{project}}/regions/{{region}}/disks/{{name}}" + idTemplate: "{{name}}" metadataMapping: name: name labels: labels @@ -206,7 +206,7 @@ spec: required: false - name: google_compute_route kind: ComputeRoute - idTemplate: "projects/{{project}}/global/routes/{{name}}" + idTemplate: "{{name}}" metadataMapping: name: name resourceReferences: @@ -224,7 +224,7 @@ spec: required: false - name: google_compute_router kind: ComputeRouter - idTemplate: "projects/{{project}}/regions/{{region}}/routers/{{name}}" + idTemplate: "{{name}}" metadataMapping: name: name resourceReferences: @@ -234,23 +234,23 @@ spec: required: true - name: google_compute_snapshot kind: ComputeSnapshot - idTemplate: "projects/{{project}}/global/snapshots/{{name}}" + idTemplate: "{{name}}" metadataMapping: name: name labels: labels - name: google_compute_ssl_certificate kind: ComputeSslCertificate - idTemplate: "projects/{{project}}/global/sslCertificates/{{name}}" + idTemplate: "{{name}}" metadataMapping: name: name - name: google_compute_ssl_policy kind: ComputeSslPolicy - idTemplate: "projects/{{project}}/global/sslPolicies/{{name}}" + idTemplate: "{{name}}" metadataMapping: name: name - name: google_compute_subnetwork kind: ComputeSubnetwork - idTemplate: "projects/{{project}}/regions/{{regionRef.name}}/subnetworks/{{name}}" + idTemplate: "{{name}}" metadataMapping: name: name resourceReferences: @@ -260,7 +260,7 @@ spec: required: true - name: google_compute_target_http_proxy kind: ComputeTargetHttpProxy - idTemplate: "projects/{{project}}/global/targetHttpProxies/{{name}}" + idTemplate: "{{name}}" metadataMapping: name: name resourceReferences: @@ -270,7 +270,7 @@ spec: required: true - name: google_compute_target_https_proxy kind: ComputeTargetHttpsProxy - idTemplate: "projects/{{project}}/global/targetHttpsProxies/{{name}}" + idTemplate: "{{name}}" metadataMapping: name: name resourceReferences: @@ -284,7 +284,7 @@ spec: required: true - name: google_compute_target_instance kind: ComputeTargetInstance - idTemplate: "projects/{{project}}/zones/{{zone}}/targetInstances/{{name}}" + idTemplate: "{{zone}}/{{name}}" metadataMapping: name: name resourceReferences: @@ -294,7 +294,7 @@ spec: required: true - name: google_compute_target_ssl_proxy kind: ComputeTargetSslProxy - idTemplate: "projects/{{project}}/global/targetSslProxies/{{name}}" + idTemplate: "{{name}}" metadataMapping: name: name resourceReferences: @@ -308,7 +308,7 @@ spec: required: false - name: google_compute_target_tcp_proxy kind: ComputeTargetTcpProxy - idTemplate: "projects/{{project}}/global/targetTcpProxies/{{name}}" + idTemplate: "{{name}}" metadataMapping: name: name resourceReferences: @@ -318,7 +318,7 @@ spec: required: true - name: google_compute_vpn_gateway kind: ComputeVpnGateway - idTemplate: "projects/{{project}}/regions/{{region}}/targetVpnGateways/{{name}}" + idTemplate: "{{name}}" metadataMapping: name: name resourceReferences: @@ -328,7 +328,7 @@ spec: required: true - name: google_compute_url_map kind: ComputeUrlMap - idTemplate: "projects/{{project}}/global/urlMaps/{{name}}" + idTemplate: "{{name}}" metadataMapping: name: name resourceReferences: @@ -338,7 +338,7 @@ spec: required: true - name: google_compute_vpn_tunnel kind: ComputeVpnTunnel - idTemplate: "projects/{{project}}/regions/{{region}}/vpnTunnels/{{name}}" + idTemplate: "{{name}}" metadataMapping: name: name resourceReferences: diff --git a/build/kcc/servicemappings/dns.yaml b/build/kcc/servicemappings/dns.yaml index 00e6980b5901..cd5c0f1b97d2 100644 --- a/build/kcc/servicemappings/dns.yaml +++ b/build/kcc/servicemappings/dns.yaml @@ -9,7 +9,7 @@ spec: resources: - name: google_dns_managed_zone kind: DnsManagedZone - idTemplate: "projects/{{project}}/managedZones/{{name}}" + idTemplate: "{{name}}" metadataMapping: name: name labels: labels diff --git a/build/kcc/servicemappings/filestore.yaml b/build/kcc/servicemappings/filestore.yaml index 3f028cc52cce..dd25436e2c77 100644 --- a/build/kcc/servicemappings/filestore.yaml +++ b/build/kcc/servicemappings/filestore.yaml @@ -9,7 +9,7 @@ spec: resources: - name: google_filestore_instance kind: FilestoreInstance - idTemplate: "projects/{{project}}/locations/{{zone}}/instances/{{name}}" + idTemplate: "{{zone}}/{{name}}" metadataMapping: name: name labels: labels diff --git a/build/kcc/servicemappings/kms.yaml b/build/kcc/servicemappings/kms.yaml index 874a7ff13783..a1a4c5881ceb 100644 --- a/build/kcc/servicemappings/kms.yaml +++ b/build/kcc/servicemappings/kms.yaml @@ -9,10 +9,10 @@ spec: resources: - name: google_kms_key_ring kind: KmsKeyRing - idTemplate: "projects/{{project}}/locations/{{location}}/keyRings/{{name}}" + idTemplate: "{{location}}/{{name}}" metadataMapping: - name: google_kms_crypto_key kind: KmsCryptoKey - idTemplate: "{{key_ring}}/cryptoKeys/{{name}}" + idTemplate: "{{key_ring}}/{{name}}" metadataMapping: labels: labels diff --git a/build/kcc/servicemappings/mlengine.yaml b/build/kcc/servicemappings/mlengine.yaml index 9c3f72052c40..b9642f664030 100644 --- a/build/kcc/servicemappings/mlengine.yaml +++ b/build/kcc/servicemappings/mlengine.yaml @@ -9,7 +9,7 @@ spec: resources: - name: google_ml_engine_model kind: MLEngineModel - idTemplate: "projects/{{project}}/models/{{name}}" + idTemplate: "{{name}}" metadataMapping: name: name labels: labels diff --git a/build/kcc/servicemappings/pubsub.yaml b/build/kcc/servicemappings/pubsub.yaml index 9ab928c939cf..a4281609fa95 100644 --- a/build/kcc/servicemappings/pubsub.yaml +++ b/build/kcc/servicemappings/pubsub.yaml @@ -10,13 +10,13 @@ spec: - name: google_pubsub_topic kind: PubsubTopic iamPolicyName: google_pubsub_topic_iam_policy - idTemplate: "projects/{{project}}/topics/{{name}}" + idTemplate: "{{name}}" metadataMapping: name: name labels: labels - name: google_pubsub_subscription kind: PubsubSubscription - idTemplate: "projects/{{project}}/subscriptions/{{name}}" + idTemplate: "{{name}}" metadataMapping: name: name labels: labels diff --git a/build/kcc/servicemappings/redis.yaml b/build/kcc/servicemappings/redis.yaml index 35a11548d1c2..2f1f02fd055e 100644 --- a/build/kcc/servicemappings/redis.yaml +++ b/build/kcc/servicemappings/redis.yaml @@ -9,7 +9,7 @@ spec: resources: - name: google_redis_instance kind: RedisInstance - idTemplate: "projects/{{project}}/locations/{{region}}/instances/{{name}}" + idTemplate: "{{name}}" metadataMapping: name: name labels: labels diff --git a/build/kcc/servicemappings/securitycenter.yaml b/build/kcc/servicemappings/securitycenter.yaml index 6193e313850b..65c2de7b6cec 100644 --- a/build/kcc/servicemappings/securitycenter.yaml +++ b/build/kcc/servicemappings/securitycenter.yaml @@ -9,5 +9,5 @@ spec: resources: - name: google_scc_source kind: SecurityCenterSource - idTemplate: "organizations/{{organization}}/sources/{{name}}" + idTemplate: "{{organization}}/{{name}}" metadataMapping: diff --git a/build/kcc/servicemappings/sourcerepo.yaml b/build/kcc/servicemappings/sourcerepo.yaml index 0acc1f6fad09..88f32e18b222 100644 --- a/build/kcc/servicemappings/sourcerepo.yaml +++ b/build/kcc/servicemappings/sourcerepo.yaml @@ -10,6 +10,6 @@ spec: - name: google_sourcerepo_repository kind: SourceRepoRepository iamPolicyName: google_sourcerepo_repository_iam_policy - idTemplate: "projects/{{project}}/repos/{{name}}" + idTemplate: "{{name}}" metadataMapping: name: name diff --git a/build/kcc/servicemappings/spanner.yaml b/build/kcc/servicemappings/spanner.yaml index bf24a532430d..d562bd578366 100644 --- a/build/kcc/servicemappings/spanner.yaml +++ b/build/kcc/servicemappings/spanner.yaml @@ -9,7 +9,7 @@ spec: resources: - name: google_spanner_instance kind: SpannerInstance - idTemplate: "projects/{{project}}/instances/{{name}}" + idTemplate: "{{name}}" metadataMapping: name: name labels: labels @@ -20,5 +20,5 @@ spec: required: true - name: google_spanner_database kind: SpannerDatabase - idTemplate: "projects/{{project}}/instances/{{instance}}/databases/{{name}}" + idTemplate: "{{instance}}/{{name}}" metadataMapping: diff --git a/build/kcc/servicemappings/sql.yaml b/build/kcc/servicemappings/sql.yaml index c71d6a210d16..a665d2675801 100644 --- a/build/kcc/servicemappings/sql.yaml +++ b/build/kcc/servicemappings/sql.yaml @@ -9,6 +9,6 @@ spec: resources: - name: google_sql_database kind: SqlDatabase - idTemplate: "projects/{{project}}/instances/{{instance}}/databases/{{name}}" + idTemplate: "{{instance}}/{{name}}" metadataMapping: name: name diff --git a/build/kcc/servicemappings/tpu.yaml b/build/kcc/servicemappings/tpu.yaml index e3b715c5d885..33b62d7928f7 100644 --- a/build/kcc/servicemappings/tpu.yaml +++ b/build/kcc/servicemappings/tpu.yaml @@ -9,7 +9,7 @@ spec: resources: - name: google_tpu_node kind: TpuNode - idTemplate: "projects/{{project}}/locations/{{zone}}/nodes/{{name}}" + idTemplate: "{{zone}}/{{name}}" metadataMapping: name: name labels: labels diff --git a/provider/terraform_kcc.rb b/provider/terraform_kcc.rb index d6c92cf9d5b9..da84612267e7 100644 --- a/provider/terraform_kcc.rb +++ b/provider/terraform_kcc.rb @@ -110,15 +110,19 @@ def guess_metadata_mapping_name(object) end end - def transform_refs_in_id(id_template, object) - final_id_template = id_template + def format_id_template(id_template, object) + # transform from buckets/{{bucket}} to {{bucket}} + id_template_parts = id_template.scan(/{{[[:word:]]+}}/) + id_template_parts -= ['{{project}}', '{{region}}'] + id_template_formatted = id_template_parts.join('/') + + # transform refs from {{bucket}} to {{bucketRef.name}} form prop_names = id_template.scan(/{{[[:word:]]+}}/).map{ |p| p.gsub('{{', '').gsub('}}', '') } # probably won't catch overriden names - object.properties.reject{ |p| p.name == 'region' }.select { |p| p.is_a?(Api::Type::ResourceRef) && prop_names.include?(p.name) }.each do |prop| - puts "saw #{prop.name}" - final_id_template = final_id_template.gsub("{{#{prop.name}}}", "{{#{prop.name}Ref.name}}") + object.properties.select { |p| p.is_a?(Api::Type::ResourceRef) && prop_names.include?(p.name) }.each do |prop| + id_template_formatted = id_template_formatted.gsub("{{#{prop.name}}}", "{{#{prop.name}Ref.name}}") end - final_id_template + id_template_formatted end end end diff --git a/templates/kcc/product/service_mapping.yaml.erb b/templates/kcc/product/service_mapping.yaml.erb index d944d90e726f..286f675a33bc 100644 --- a/templates/kcc/product/service_mapping.yaml.erb +++ b/templates/kcc/product/service_mapping.yaml.erb @@ -45,10 +45,12 @@ spec: # idTemplate is an import id fed into the provider, which is (slightly) # distinct from a Terraform id. # Select the first format, which will generally be the long form. - id_template = import_id_formats(object)[0] + id_template = format_id_template(import_id_formats(object)[0], object) name = guess_metadata_mapping_name(object) -%> - idTemplate: "<%= transform_refs_in_id(id_template, object) %>" +<% if id_template != nil && id_template != "" -%> + idTemplate: "<%= id_template %>" +<% end -%> metadataMapping: <% if name != nil -%> name: <%= name %>