Skip to content

Commit

Permalink
Use parameters in references too. Exclude zone.
Browse files Browse the repository at this point in the history
  • Loading branch information
rileykarson committed Aug 28, 2019
1 parent 928c1e5 commit 01ca0da
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 8 deletions.
7 changes: 6 additions & 1 deletion build/kcc/servicemappings/appengine.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,10 @@ spec:
name: priority
- name: google_app_engine_standard_app_version
kind: AppEngineStandardAppVersion
idTemplate: "{{service}}/{{version_id}}"
idTemplate: "{{serviceRef.name}}/{{version_id}}"
metadataMapping:
resourceReferences:
- key: serviceRef
tfField: service
kind: AppEngineService
required: false
28 changes: 27 additions & 1 deletion build/kcc/servicemappings/compute.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ spec:
kind: ComputeBackendBucketSignedUrlKey
idTemplate: "{{backend_bucket}}/{{name}}"
metadataMapping:
resourceReferences:
- key: backendBucketRef
tfField: backendBucket
kind: ComputeBackendBucket
required: true
- name: google_compute_backend_service
kind: ComputeBackendService
idTemplate: "{{name}}"
Expand All @@ -46,11 +51,15 @@ spec:
idTemplate: "{{name}}"
metadataMapping:
name: name
resourceReferences:
- name: google_compute_backend_service_signed_url_key
kind: ComputeBackendServiceSignedUrlKey
idTemplate: "{{backend_service}}/{{name}}"
metadataMapping:
resourceReferences:
- key: backendServiceRef
tfField: backendService
kind: ComputeBackendService
required: true
- name: google_compute_disk
kind: ComputeDisk
idTemplate: "{{zone}}/{{name}}"
Expand All @@ -62,6 +71,10 @@ spec:
tfField: type
kind: ComputeDiskType
required: false
- key: snapshotRef
tfField: snapshot
kind: ComputeSnapshot
required: false
- name: google_compute_firewall
kind: ComputeFirewall
idTemplate: "{{name}}"
Expand Down Expand Up @@ -159,6 +172,10 @@ spec:
tfField: instance
kind: ComputeInstance
required: true
- key: networkEndpointGroupRef
tfField: networkEndpointGroup
kind: ComputeNetworkEndpointGroup
required: true
- name: google_compute_network_endpoint_group
kind: ComputeNetworkEndpointGroup
idTemplate: "{{zone}}/{{name}}"
Expand Down Expand Up @@ -204,6 +221,10 @@ spec:
tfField: type
kind: ComputeRegionDiskType
required: false
- key: snapshotRef
tfField: snapshot
kind: ComputeSnapshot
required: false
- name: google_compute_route
kind: ComputeRoute
idTemplate: "{{name}}"
Expand Down Expand Up @@ -238,6 +259,11 @@ spec:
metadataMapping:
name: name
labels: labels
resourceReferences:
- key: sourceDiskRef
tfField: sourceDisk
kind: ComputeDisk
required: true
- name: google_compute_ssl_certificate
kind: ComputeSslCertificate
idTemplate: "{{name}}"
Expand Down
7 changes: 6 additions & 1 deletion build/kcc/servicemappings/spanner.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,10 @@ spec:
required: true
- name: google_spanner_database
kind: SpannerDatabase
idTemplate: "{{instance}}/{{name}}"
idTemplate: "{{instanceRef.name}}/{{name}}"
metadataMapping:
resourceReferences:
- key: instanceRef
tfField: instance
kind: SpannerInstance
required: true
4 changes: 2 additions & 2 deletions provider/terraform_kcc.rb
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,8 @@ def format_id_template(id_template, object)
# 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.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}}")
object.all_properties.reject { |p| p.name == 'zone' }.select { |p| p.is_a?(Api::Type::ResourceRef) && (prop_names.include?(p.name) || prop_names.include?(p.name.camelize(:lower))) }.each do |prop|
id_template_formatted = id_template_formatted.gsub("{{#{prop.name}}}", "{{#{prop.name}Ref.name}}").gsub("{{#{prop.name.camelize(:lower)}}}", "{{#{prop.name}Ref.name}}")
end
id_template_formatted
end
Expand Down
6 changes: 3 additions & 3 deletions templates/kcc/product/service_mapping.yaml.erb
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,15 @@ spec:
<% if name != nil -%>
name: <%= name %>
<% end -%>
<% if object.properties.map(&:name).include?("labels") -%>
<% if object.all_user_properties.map(&:name).include?("labels") -%>
labels: labels
<% end -%>
<%-
references = object.properties.select { |p| p.is_a?(Api::Type::ResourceRef) }
references = object.all_user_properties.select { |p| p.is_a?(Api::Type::ResourceRef) }.reject { |p| p.name == 'region' || p.name == 'zone' }
unless references.empty?
-%>
resourceReferences:
<%- references.reject { |p| p.name == 'region' }.each do |property| -%>
<%- references.each do |property| -%>
- key: <%= property.name.camelize(:lower) %>Ref
tfField: <%= property.name %>
kind: <%= "#{product.name}#{property.resource}" %>
Expand Down

0 comments on commit 01ca0da

Please sign in to comment.