Skip to content

Commit

Permalink
Updates to generated id formats (#2460)
Browse files Browse the repository at this point in the history
* Update ID fields for various MM-generated resources
  • Loading branch information
slevenick authored and rileykarson committed Oct 15, 2019
1 parent 08d2288 commit c0f8511
Show file tree
Hide file tree
Showing 22 changed files with 27 additions and 40 deletions.
8 changes: 3 additions & 5 deletions products/appengine/terraform.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@
--- !ruby/object:Provider::Terraform::Config
overrides: !ruby/object:Overrides::ResourceOverrides
FirewallRule: !ruby/object:Overrides::Terraform::ResourceOverride
id_format: "{{project}}/{{priority}}"
import_format: ["{{project}}/{{priority}}"]
import_format: ["apps/{{project}}/firewall/ingressRules/{{priority}}"]
examples:
- !ruby/object:Provider::Terraform::Examples
name: "app_engine_firewall_rule_basic"
Expand All @@ -25,7 +24,6 @@ overrides: !ruby/object:Overrides::ResourceOverrides
test_env_vars:
org_id: :ORG_ID
StandardAppVersion: !ruby/object:Overrides::Terraform::ResourceOverride
id_format: "apps/{{project}}/services/{{service}}/versions/{{version_id}}"
import_format: ["apps/{{project}}/services/{{service}}/versions/{{version_id}}"]
mutex: "apps/{{project}}/services/{{service}}"
parameters:
Expand Down Expand Up @@ -73,8 +71,8 @@ overrides: !ruby/object:Overrides::ResourceOverrides
exclude: true
DomainMapping: !ruby/object:Overrides::Terraform::ResourceOverride
self_link: 'apps/{{project}}/domainMappings/{{domain_name}}'
id_format: "{{domain_name}}"
import_format: ["{{domain_name}}"]
id_format: 'apps/{{project}}/domainMappings/{{domain_name}}'
import_format: ['apps/{{project}}/domainMappings/{{domain_name}}']
examples:
- !ruby/object:Provider::Terraform::Examples
name: "app_engine_domain_mapping_basic"
Expand Down
3 changes: 1 addition & 2 deletions products/bigquery/terraform.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@
legacy_name: 'bigquery'
overrides: !ruby/object:Overrides::ResourceOverrides
Dataset: !ruby/object:Overrides::Terraform::ResourceOverride
id_format: "{{project}}:{{dataset_id}}"
import_format: ["{{project}}:{{dataset_id}}", "{{project}}/{{dataset_id}}", "{{dataset_id}}"]
import_format: ["projects/{{project}}/datasets/{{dataset_id}}"]
delete_url: projects/{{project}}/datasets/{{dataset_id}}?deleteContents={{delete_contents_on_destroy}}
examples:
- !ruby/object:Provider::Terraform::Examples
Expand Down
2 changes: 1 addition & 1 deletion products/bigtable/terraform.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
--- !ruby/object:Provider::Terraform::Config
overrides: !ruby/object:Overrides::ResourceOverrides
AppProfile: !ruby/object:Overrides::Terraform::ResourceOverride
id_format: "{{project}}/{{instance}}/{{app_profile_id}}"
id_format: "projects/{{project}}/instances/{{instance}}/appProfiles/{{app_profile_id}}"
import_format: ["projects/{{project}}/instances/{{instance}}/appProfiles/{{app_profile_id}}"]
examples:
- !ruby/object:Provider::Terraform::Examples
Expand Down
3 changes: 1 addition & 2 deletions products/binaryauthorization/terraform.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
overrides: !ruby/object:Overrides::ResourceOverrides
Attestor: !ruby/object:Overrides::Terraform::ResourceOverride
import_format: ["projects/{{project}}/attestors/{{name}}"]
id_format: "{{project}}/{{name}}"
examples:
- !ruby/object:Provider::Terraform::Examples
name: "binary_authorization_attestor_basic"
Expand Down Expand Up @@ -54,7 +53,7 @@ overrides: !ruby/object:Overrides::ResourceOverrides
attestationAuthorityNote.publicKeys.id: !ruby/object:Overrides::Terraform::PropertyOverride
default_from_api: true
Policy: !ruby/object:Overrides::Terraform::ResourceOverride
id_format: "{{project}}"
id_format: "projects/{{project}}"
import_format: ["projects/{{project}}"]
custom_code: !ruby/object:Provider::Terraform::CustomCode
constants: 'templates/terraform/constants/binaryauthorization_policy.erb'
Expand Down
2 changes: 1 addition & 1 deletion products/cloudbuild/terraform.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ overrides: !ruby/object:Overrides::ResourceOverrides
Trigger: !ruby/object:Overrides::Terraform::ResourceOverride
# import by default only works with old-style self links ending in a name
import_format: ["projects/{{project}}/triggers/{{trigger_id}}"]
id_format: '{{project}}/{{trigger_id}}'
id_format: 'projects/{{project}}/triggers/{{trigger_id}}'
self_link: 'projects/{{project}}/triggers/{{trigger_id}}'
examples:
- !ruby/object:Provider::Terraform::Examples
Expand Down
2 changes: 1 addition & 1 deletion products/cloudfunctions/terraform.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ legacy_name: 'cloudfunctions'
overrides: !ruby/object:Overrides::ResourceOverrides
CloudFunction: !ruby/object:Overrides::Terraform::ResourceOverride
legacy_name: 'google_cloudfunctions_function'
id_format: '{{project}}/{{region}}/{{cloud_function}}'
id_format: 'projects/{{project}}/locations/{{region}}/functions/{{cloud_function}}'
base_url: projects/{{project}}/locations/{{region}}/functions
import_format: ["projects/{{project}}/locations/{{region}}/functions/{{cloud_function}}"]
exclude_resource: true
Expand Down
1 change: 1 addition & 0 deletions products/cloudscheduler/terraform.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
--- !ruby/object:Provider::Terraform::Config
overrides: !ruby/object:Overrides::ResourceOverrides
Job: !ruby/object:Overrides::Terraform::ResourceOverride
id_format: 'projects/{{project}}/locations/{{region}}/jobs/{{name}}'
custom_code: !ruby/object:Provider::Terraform::CustomCode
constants: templates/terraform/constants/scheduler_auth.erb
resource_definition: templates/terraform/resource_definition/scheduler_auth.erb
Expand Down
5 changes: 0 additions & 5 deletions products/compute/terraform.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
--- !ruby/object:Provider::Terraform::Config
overrides: !ruby/object:Overrides::ResourceOverrides
Address: !ruby/object:Overrides::Terraform::ResourceOverride
id_format: "{{project}}/{{region}}/{{name}}"
examples:
- !ruby/object:Provider::Terraform::Examples
name: "address_basic"
Expand Down Expand Up @@ -71,7 +70,6 @@ overrides: !ruby/object:Overrides::ResourceOverrides
custom_code: !ruby/object:Provider::Terraform::CustomCode
post_create: templates/terraform/post_create/labels.erb
Autoscaler: !ruby/object:Overrides::Terraform::ResourceOverride
id_format: "{{zone}}/{{name}}"
examples:
- !ruby/object:Provider::Terraform::Examples
name: "autoscaler_single_instance"
Expand Down Expand Up @@ -1019,7 +1017,6 @@ overrides: !ruby/object:Overrides::ResourceOverrides
Region: !ruby/object:Overrides::Terraform::ResourceOverride
exclude: true
RegionAutoscaler: !ruby/object:Overrides::Terraform::ResourceOverride
id_format: "{{region}}/{{name}}"
examples:
- !ruby/object:Provider::Terraform::Examples
name: "region_autoscaler_beta"
Expand Down Expand Up @@ -1332,7 +1329,6 @@ overrides: !ruby/object:Overrides::ResourceOverrides
`next_hop_instance`. Omit if `next_hop_instance` is specified as
a URL.
Router: !ruby/object:Overrides::Terraform::ResourceOverride
id_format: "{{region}}/{{name}}"
mutex: router/{{region}}/{{name}}
examples:
- !ruby/object:Provider::Terraform::Examples
Expand Down Expand Up @@ -1642,7 +1638,6 @@ overrides: !ruby/object:Overrides::ResourceOverrides
insert_minutes: 6
update_minutes: 6
delete_minutes: 6
id_format: "{{region}}/{{name}}"
properties:
id: !ruby/object:Overrides::Terraform::PropertyOverride
exclude: true
Expand Down
1 change: 1 addition & 0 deletions products/containeranalysis/terraform.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
--- !ruby/object:Provider::Terraform::Config
overrides: !ruby/object:Overrides::ResourceOverrides
Note: !ruby/object:Overrides::Terraform::ResourceOverride
id_format: "projects/{{project}}/notes/{{name}}"
import_format: ["projects/{{project}}/notes/{{name}}"]
custom_code: !ruby/object:Provider::Terraform::CustomCode
pre_update: 'templates/terraform/pre_update/containeranalysis_note.erb'
Expand Down
2 changes: 2 additions & 0 deletions products/dns/terraform.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
--- !ruby/object:Provider::Terraform::Config
overrides: !ruby/object:Overrides::ResourceOverrides
ManagedZone: !ruby/object:Overrides::Terraform::ResourceOverride
id_format: 'projects/{{project}}/managedZones/{{name}}'
examples:
- !ruby/object:Provider::Terraform::Examples
name: "dns_managed_zone_basic"
Expand Down Expand Up @@ -94,6 +95,7 @@ overrides: !ruby/object:Overrides::ResourceOverrides
diff_suppress_func: 'caseDiffSuppress'
custom_flatten: templates/terraform/custom_flatten/default_if_empty.erb
Policy: !ruby/object:Overrides::Terraform::ResourceOverride
id_format: 'projects/{{project}}/policies/{{name}}'
examples:
- !ruby/object:Provider::Terraform::Examples
name: "dns_policy_basic"
Expand Down
2 changes: 0 additions & 2 deletions products/filestore/terraform.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ overrides: !ruby/object:Overrides::ResourceOverrides
update_minutes: 6
delete_minutes: 6
autogen_async: true
id_format: "{{project}}/{{zone}}/{{name}}"
import_format: ["projects/{{project}}/locations/{{zone}}/instances/{{name}}"]
examples:
- !ruby/object:Provider::Terraform::Examples
name: "filestore_instance_basic"
Expand Down
2 changes: 0 additions & 2 deletions products/pubsub/terraform.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
--- !ruby/object:Provider::Terraform::Config
overrides: !ruby/object:Overrides::ResourceOverrides
Topic: !ruby/object:Overrides::Terraform::ResourceOverride
id_format: "projects/{{project}}/topics/{{name}}"
error_retry_predicates: ["pubsubTopicProjectNotReady"]
iam_policy: !ruby/object:Api::Resource::IamPolicy
parent_resource_attribute: 'topic'
Expand Down Expand Up @@ -48,7 +47,6 @@ overrides: !ruby/object:Overrides::ResourceOverrides
encoder: templates/terraform/encoders/no_send_name.go.erb
update_encoder: templates/terraform/update_encoder/pubsub_topic.erb
Subscription: !ruby/object:Overrides::Terraform::ResourceOverride
id_format: "projects/{{project}}/subscriptions/{{name}}"
examples:
- !ruby/object:Provider::Terraform::Examples
name: "pubsub_subscription_push"
Expand Down
2 changes: 0 additions & 2 deletions products/redis/terraform.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ overrides: !ruby/object:Overrides::ResourceOverrides
update_minutes: 10
delete_minutes: 10
autogen_async: true
id_format: "{{project}}/{{region}}/{{name}}"
import_format: ["projects/{{project}}/locations/{{region}}/instances/{{name}}"]
custom_code: !ruby/object:Provider::Terraform::CustomCode
encoder: templates/terraform/encoders/redis_location_id_for_fallback_zone.go.erb
examples:
Expand Down
1 change: 0 additions & 1 deletion products/runtimeconfig/terraform.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ legacy_name: runtimeconfig
overrides: !ruby/object:Overrides::ResourceOverrides
Config: !ruby/object:Overrides::Terraform::ResourceOverride
exclude_resource: true
id_format: 'projects/{{project}}/configs/{{config}}'
import_format: ["projects/{{project}}/configs/{{config}}"]
examples:
- !ruby/object:Provider::Terraform::Examples
Expand Down
1 change: 0 additions & 1 deletion products/securityscanner/terraform.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
--- !ruby/object:Provider::Terraform::Config
overrides: !ruby/object:Overrides::ResourceOverrides
ScanConfig: !ruby/object:Overrides::Terraform::ResourceOverride
import_format: ["{{name}}"]
examples:
- !ruby/object:Provider::Terraform::Examples
name: "scan_config_basic"
Expand Down
1 change: 0 additions & 1 deletion products/sourcerepo/terraform.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ overrides: !ruby/object:Overrides::ResourceOverrides
exclude: false
method_name_separator: ':'
parent_resource_attribute: 'repository'
id_format: '{{project}}/{{name}}'
examples:
- !ruby/object:Provider::Terraform::Examples
name: "sourcerepo_repository_basic"
Expand Down
1 change: 0 additions & 1 deletion products/spanner/terraform.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
overrides: !ruby/object:Overrides::ResourceOverrides
Database: !ruby/object:Overrides::Terraform::ResourceOverride
autogen_async: true
id_format: "{{project}}/{{instance}}/{{name}}"
import_format:
- "projects/{{project}}/instances/{{instance}}/databases/{{name}}"
- "instances/{{instance}}/databases/{{name}}"
Expand Down
3 changes: 0 additions & 3 deletions products/sql/terraform.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,9 @@ client_name: 'SqlAdmin'
overrides: !ruby/object:Overrides::ResourceOverrides
Database: !ruby/object:Overrides::Terraform::ResourceOverride
mutex: "google-sql-database-instance-{{project}}-{{instance}}"
id_format: "{{instance}}:{{name}}"
import_format: ["projects/{{project}}/instances/{{instance}}/databases/{{name}}",
"{{project}}/{{instance}}/{{name}}",
"instances/{{instance}}/databases/{{name}}",
# support for a legacy import format
"{{instance}}:{{name}}",
"{{instance}}/{{name}}",
"{{name}}"]
examples:
Expand Down
2 changes: 0 additions & 2 deletions products/tpu/terraform.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ overrides: !ruby/object:Overrides::ResourceOverrides
insert_minutes: 15
update_minutes: 15
delete_minutes: 15
id_format: "{{project}}/{{zone}}/{{name}}"
import_format: ["projects/{{project}}/locations/{{zone}}/nodes/{{name}}"]
autogen_async: true
examples:
- !ruby/object:Provider::Terraform::Examples
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,7 @@ func resourceBigQueryTableCreate(d *schema.ResourceData, meta interface{}) error

log.Printf("[INFO] BigQuery table %s has been created", res.Id)

d.SetId(fmt.Sprintf("%s:%s.%s", res.TableReference.ProjectId, res.TableReference.DatasetId, res.TableReference.TableId))
d.SetId(fmt.Sprintf("projects/%s/datasets/%s/tables/%s", res.TableReference.ProjectId, res.TableReference.DatasetId, res.TableReference.TableId))

return resourceBigQueryTableRead(d, meta)
}
Expand Down Expand Up @@ -847,12 +847,11 @@ type bigQueryTableId struct {
}

func parseBigQueryTableId(id string) (*bigQueryTableId, error) {
// Expected format is "PROJECT:DATASET.TABLE", but the project can itself have . and : in it.
// Those characters are not valid dataset or table components, so just split on the last two.
matchRegex := regexp.MustCompile("^(.+):([^:.]+)\\.([^:.]+)$")
// Expected format is "projects/{{project}}/datasets/{{dataset}}/tables/{{table}}"
matchRegex := regexp.MustCompile("^projects/(.+)/datasets/(.+)/tables/(.+)$")
subMatches := matchRegex.FindStringSubmatch(id)
if subMatches == nil {
return nil, fmt.Errorf("Invalid BigQuery table specifier. Expecting {project}:{dataset-id}.{table-id}, got %s", id)
return nil, fmt.Errorf("Invalid BigQuery table specifier. Expecting projects/{{project}}/datasets/{{dataset}}/tables/{{table}}, got %s", id)
}
return &bigQueryTableId{
Project: subMatches[1],
Expand Down
8 changes: 6 additions & 2 deletions third_party/terraform/resources/resource_bigtable_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,11 @@ func resourceBigtableInstanceCreate(d *schema.ResourceData, meta interface{}) er
return fmt.Errorf("Error creating instance. %s", err)
}

d.SetId(conf.InstanceID)
id, err := replaceVars(d, config, "projects/{{project}}/instances/{{name}}")
if err != nil {
return fmt.Errorf("Error constructing id: %s", err)
}
d.SetId(id)

return resourceBigtableInstanceRead(d, meta)
}
Expand Down Expand Up @@ -371,7 +375,7 @@ func resourceBigtableInstanceImport(d *schema.ResourceData, meta interface{}) ([
}

// Replace import id for the resource id
id, err := replaceVars(d, config, "{{name}}")
id, err := replaceVars(d, config, "projects/{{project}}/instances/{{name}}")
if err != nil {
return nil, fmt.Errorf("Error constructing id: %s", err)
}
Expand Down
6 changes: 5 additions & 1 deletion third_party/terraform/resources/resource_bigtable_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,11 @@ func resourceBigtableTableCreate(d *schema.ResourceData, meta interface{}) error
}
}

d.SetId(name)
id, err := replaceVars(d, config, "projects/{{project}}/instances/{{instance_id}}/tables/{{name}}")
if err != nil {
return fmt.Errorf("Error constructing id: %s", err)
}
d.SetId(id)

return resourceBigtableTableRead(d, meta)
}
Expand Down

0 comments on commit c0f8511

Please sign in to comment.