Skip to content

Commit

Permalink
remove long name behavior for pubsub subscriptions, clean up cu… (#2561)
Browse files Browse the repository at this point in the history
* remove long name behavior for pubsub subscriptions, clean up custom expanders

* fix build

* fix tests
  • Loading branch information
danawillow authored and rileykarson committed Nov 6, 2019
1 parent 8e4682b commit cc980e5
Show file tree
Hide file tree
Showing 22 changed files with 52 additions and 256 deletions.
2 changes: 1 addition & 1 deletion products/binaryauthorization/terraform.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ overrides: !ruby/object:Overrides::ResourceOverrides
properties:
name: !ruby/object:Overrides::Terraform::PropertyOverride
custom_flatten: 'templates/terraform/custom_flatten/name_from_self_link.erb'
custom_expand: 'templates/terraform/custom_expand/binaryauthorization_attestor_name.erb'
custom_expand: 'templates/terraform/custom_expand/shortname_to_url.go.erb'
attestationAuthorityNote.noteReference: !ruby/object:Overrides::Terraform::PropertyOverride
custom_expand: 'templates/terraform/custom_expand/container_analysis_note.erb'
diff_suppress_func: 'compareSelfLinkOrResourceName'
Expand Down
2 changes: 1 addition & 1 deletion products/cloudscheduler/terraform.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ overrides: !ruby/object:Overrides::ResourceOverrides
job_name: "test-job"
properties:
name: !ruby/object:Overrides::Terraform::PropertyOverride
custom_expand: 'templates/terraform/custom_expand/cloudscheduler_job_name.erb'
custom_expand: 'templates/terraform/custom_expand/shortname_to_url.go.erb'
custom_flatten: 'templates/terraform/custom_flatten/name_from_self_link.erb'
httpTarget.headers: !ruby/object:Overrides::Terraform::PropertyOverride
custom_flatten: 'templates/terraform/custom_flatten/http_headers.erb'
Expand Down
16 changes: 12 additions & 4 deletions products/compute/terraform.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1939,7 +1939,9 @@ overrides: !ruby/object:Overrides::ResourceOverrides
id: !ruby/object:Overrides::Terraform::PropertyOverride
name: "map_id"
defaultService: !ruby/object:Overrides::Terraform::PropertyOverride
custom_expand: 'templates/terraform/custom_expand/url_map_only_set_string.go.erb'
# ResourceRef only supports 1 type and UrlMap has references to a BackendBucket or BackendService.
# Just read the self_link string instead of extracting the name and making a self_link out of it.
custom_expand: 'templates/terraform/custom_expand/resourceref_as_string.go.erb'
description: The backend service or backend bucket to use when none of the given rules match.
hostRules: !ruby/object:Overrides::Terraform::PropertyOverride
name: "host_rule"
Expand All @@ -1949,17 +1951,23 @@ overrides: !ruby/object:Overrides::ResourceOverrides
pathMatchers: !ruby/object:Overrides::Terraform::PropertyOverride
name: "path_matcher"
pathMatchers.defaultService: !ruby/object:Overrides::Terraform::PropertyOverride
custom_expand: 'templates/terraform/custom_expand/url_map_only_set_string.go.erb'
# ResourceRef only supports 1 type and UrlMap has references to a BackendBucket or BackendService.
# Just read the self_link string instead of extracting the name and making a self_link out of it.
custom_expand: 'templates/terraform/custom_expand/resourceref_as_string.go.erb'
description: The backend service or backend bucket to use when none of the given paths match.
pathMatchers.pathRules: !ruby/object:Overrides::Terraform::PropertyOverride
name: "path_rule"
pathMatchers.pathRules.paths: !ruby/object:Overrides::Terraform::PropertyOverride
is_set: true
pathMatchers.pathRules.service: !ruby/object:Overrides::Terraform::PropertyOverride
custom_expand: 'templates/terraform/custom_expand/url_map_only_set_string.go.erb'
# ResourceRef only supports 1 type and UrlMap has references to a BackendBucket or BackendService.
# Just read the self_link string instead of extracting the name and making a self_link out of it.
custom_expand: 'templates/terraform/custom_expand/resourceref_as_string.go.erb'
description: The backend service or backend bucket to use if any of the given paths match.
tests.service: !ruby/object:Overrides::Terraform::PropertyOverride
custom_expand: 'templates/terraform/custom_expand/url_map_only_set_string.go.erb'
# ResourceRef only supports 1 type and UrlMap has references to a BackendBucket or BackendService.
# Just read the self_link string instead of extracting the name and making a self_link out of it.
custom_expand: 'templates/terraform/custom_expand/resourceref_as_string.go.erb'
description: The backend service or backend bucket link that should be matched by this test.
tests: !ruby/object:Overrides::Terraform::PropertyOverride
name: "test"
Expand Down
3 changes: 1 addition & 2 deletions products/pubsub/terraform.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,7 @@ overrides: !ruby/object:Overrides::ResourceOverrides
* `path`: Path of the subscription in the format `projects/{project}/subscriptions/{name}`
properties:
name: !ruby/object:Overrides::Terraform::PropertyOverride
diff_suppress_func: 'comparePubsubSubscriptionBasename'
custom_expand: templates/terraform/custom_expand/computed_subscription_name.erb
custom_expand: templates/terraform/custom_expand/shortname_to_url.go.erb
custom_flatten: templates/terraform/custom_flatten/name_from_self_link.erb
topic: !ruby/object:Overrides::Terraform::PropertyOverride
diff_suppress_func: 'compareSelfLinkOrResourceName'
Expand Down
2 changes: 1 addition & 1 deletion products/redis/terraform.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ overrides: !ruby/object:Overrides::ResourceOverrides
locationId: !ruby/object:Overrides::Terraform::PropertyOverride
default_from_api: true
name: !ruby/object:Overrides::Terraform::PropertyOverride
custom_expand: 'templates/terraform/custom_expand/redis_instance_name.erb'
custom_expand: 'templates/terraform/custom_expand/shortname_to_url.go.erb'
custom_flatten: 'templates/terraform/custom_flatten/name_from_self_link.erb'
redisVersion: !ruby/object:Overrides::Terraform::PropertyOverride
default_from_api: true
Expand Down
2 changes: 1 addition & 1 deletion products/sourcerepo/terraform.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ overrides: !ruby/object:Overrides::ResourceOverrides
repository_name: "my-repository"
properties:
name: !ruby/object:Overrides::Terraform::PropertyOverride
custom_expand: templates/terraform/custom_expand/repository_name_from_short_name.go.erb
custom_expand: templates/terraform/custom_expand/shortname_to_url.go.erb
custom_flatten: templates/terraform/custom_flatten/repository_short_name_from_name.go.erb
description: |
Resource name of the repository, of the form `{{repo}}`.
Expand Down
5 changes: 3 additions & 2 deletions provider/terraform/sub_template.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,11 @@ def build_flatten_method(prefix, property, object)

# Transforms a Terraform schema representation of a property into a
# representation used by the Cloud API.
def build_expand_method(prefix, property)
def build_expand_method(prefix, property, object)
compile_template 'templates/terraform/expand_property_method.erb',
prefix: prefix,
property: property
property: property,
object: object
end

def build_expand_resource_ref(var_name, property)
Expand Down

This file was deleted.

35 changes: 0 additions & 35 deletions templates/terraform/custom_expand/cloudscheduler_job_name.erb

This file was deleted.

36 changes: 0 additions & 36 deletions templates/terraform/custom_expand/computed_subscription_name.erb

This file was deleted.

26 changes: 0 additions & 26 deletions templates/terraform/custom_expand/monitoring_group_name.erb

This file was deleted.

27 changes: 0 additions & 27 deletions templates/terraform/custom_expand/redis_instance_name.erb

This file was deleted.

This file was deleted.

6 changes: 1 addition & 5 deletions templates/terraform/custom_expand/route_gateway.erb
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
func expand<%= prefix -%><%= titlelize_property(property) -%>(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) {
if v == "default-internet-gateway" {
project, err := getProject(d, config)
if err != nil {
return nil, err
}
return fmt.Sprintf("projects/%s/global/gateways/default-internet-gateway", project), nil
return replaceVars(d, config, "projects/{{project}}/global/gateways/default-internet-gateway")
} else {
return v, nil
}
Expand Down
17 changes: 17 additions & 0 deletions templates/terraform/custom_expand/shortname_to_url.go.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<%# # the license inside this if block pertains to this file
# Copyright 2019 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.
#%>
func expand<%= prefix -%><%= titlelize_property(property) -%>(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) {
return replaceVars(d, config, "<%= id_format(object) -%>")
}
27 changes: 0 additions & 27 deletions templates/terraform/custom_expand/spanner_instance_config.go

This file was deleted.

19 changes: 0 additions & 19 deletions templates/terraform/custom_expand/url_map_only_set_string.go.erb

This file was deleted.

5 changes: 3 additions & 2 deletions templates/terraform/expand_property_method.erb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
<% if property.custom_expand -%>
<%= lines(compile_template(property.custom_expand,
prefix: prefix,
property: property)) -%>
property: property,
object: object)) -%>
<% else -%>

<%# Generate expanders for Maps %>
Expand Down Expand Up @@ -176,7 +177,7 @@ func expand<%= prefix -%><%= titlelize_property(property) -%>(v interface{}, d T
<%# Map is a map from {key -> object} in the API, but Terraform can't represent that
so we treat the key as a property of the object in Terraform schema. %>
<% next if property.is_a?(Api::Type::Map) && prop.name == property.key_name -%>
<%= lines(build_expand_method(prefix + titlelize_property(property), prop), 1) -%>
<%= lines(build_expand_method(prefix + titlelize_property(property), prop, object), 1) -%>
<% end -%>
<% end -%>

Expand Down
2 changes: 1 addition & 1 deletion templates/terraform/objectlib/base.go.erb
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,6 @@ func resource<%= resource_name -%>Encoder(d TerraformResourceData, meta interfac
<% end -%>

<% object.settable_properties.each do |prop| -%>
<%= lines(build_expand_method(resource_name, prop), 1) -%>
<%= lines(build_expand_method(resource_name, prop, object), 1) -%>
<% end -%>

2 changes: 1 addition & 1 deletion templates/terraform/resource.erb
Original file line number Diff line number Diff line change
Expand Up @@ -654,7 +654,7 @@ func resource<%= resource_name -%>Import(d *schema.ResourceData, meta interface{
<% end -%>

<% object.settable_properties.each do |prop| -%>
<%= lines(build_expand_method(resource_name, prop), 1) -%>
<%= lines(build_expand_method(resource_name, prop, object), 1) -%>
<% end -%>

<% if object.custom_code.encoder -%>
Expand Down
Loading

0 comments on commit cc980e5

Please sign in to comment.