Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Forwarding rule bugfix #310

Merged
merged 10 commits into from
Jun 27, 2018
1 change: 1 addition & 0 deletions products/compute/terraform.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@ overrides: !ruby/object:Provider::ResourceOverrides
default_from_api: true
target: !ruby/object:Provider::Terraform::PropertyOverride
diff_suppress_func: 'compareSelfLinkRelativePaths'
custom_expand: 'templates/terraform/custom_expand/self_link_from_name.erb'
ports: !ruby/object:Provider::Terraform::PropertyOverride
is_set: true
custom_expand: 'templates/terraform/custom_expand/set_to_list.erb'
Expand Down
21 changes: 10 additions & 11 deletions templates/terraform/custom_expand/self_link_from_name.erb
Original file line number Diff line number Diff line change
Expand Up @@ -13,29 +13,28 @@
# limitations under the License.
<% end -%>
func expand<%= prefix -%><%= titlelize_property(property) -%>(v interface{}, d *schema.ResourceData, config *Config) (interface{}, error) {
<% url_name = String.new(prefix)
url_name[0] = url_name[0].downcase
-%>
// This method returns a full self link from a partial self link.
if v == nil || v.(string) == "" {
// It does not try to construct anything from empty.
return "", nil
} else if strings.HasPrefix(v.(string), "https://") {
// Anything that starts with a URL scheme is assumed to be a self link worth using.
return v, nil
} else if strings.HasPrefix(v.(string), "projects/") {
// If the self link references a project, we'll just stuck the compute v1 prefix on it.
return "https://www.googleapis.com/compute/v1/" + v.(string), nil
} else if strings.HasPrefix(v.(string), "regions/") {
} else if strings.HasPrefix(v.(string), "regions/") || strings.HasPrefix(v.(string), "zones/") {
// For regional or zonal resources which include their region or zone, just put the project in front.
url, err := replaceVars(d, config, "https://www.googleapis.com/compute/v1/projects/{{project}}/")
if err != nil {
return nil, err
}
return url + v.(string), nil
} else if strings.HasPrefix(v.(string), "<%= url_name -%>") {
url, err := replaceVars(d, config, "https://www.googleapis.com/compute/v1/projects/{{project}}/regions/{{region}}/")
if err != nil {
return nil, err
}
return url + v.(string), nil
}
url, err := replaceVars(d, config, "https://www.googleapis.com/compute/v1/projects/{{project}}/regions/{{region}}/<%= url_name -%>/")
// Anything else is assumed to be a regional resource, with a partial link that begins with the resource name.
// This isn't very likely - it's a last-ditch effort to extract something useful here. We can do a better job
// as soon as MultiResourceRefs are working since we'll know the types that this field is supposed to point to.
url, err := replaceVars(d, config, "https://www.googleapis.com/compute/v1/projects/{{project}}/regions/{{region}}/")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Won't this just give us a URL that doesn't point to a specific resource type?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've added a comment to explain, but yes.

if err != nil {
return nil, err
}
Expand Down