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

Allow google_container_cluster.id reference for the value for the gke_cluster of a google_gke_hub_membership #4985

Merged
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion mmv1/products/gkehub/api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,8 @@ objects:
Self-link of the GCP resource for the GKE cluster.
For example: `//container.googleapis.com/projects/my-project/zones/us-west1-a/clusters/my-cluster`.
It can be at the most 1000 characters in length. If the cluster is provisioned with Terraform,
this is `"//container.googleapis.com/${google_container_cluster.my-cluster.id}"`.
this can be `"//container.googleapis.com/${google_container_cluster.my-cluster.id}"` or
`google_container_cluster.my-cluster.id`.
input: true
required: true
- !ruby/object:Api::Type::NestedObject
Expand Down
8 changes: 7 additions & 1 deletion mmv1/products/gkehub/terraform.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,13 @@ overrides: !ruby/object:Overrides::ResourceOverrides
# Skip sweeper gen since this is a child resource.
skip_sweeper: true
id_format: "{{name}}"
import_format: ["{{%name}}"]
import_format: ["{{name}}"]
upodroid marked this conversation as resolved.
Show resolved Hide resolved
properties:
endpoint.gkeCluster.resourceLink: !ruby/object:Overrides::Terraform::PropertyOverride
diff_suppress_func: suppressGkeHubEndpointSelfLinkDiff
custom_expand: 'templates/terraform/custom_expand/gke_hub_membership.erb'
custom_code: !ruby/object:Provider::Terraform::CustomCode
constants: templates/terraform/constants/gke_hub_membership_diff.go
# This is for copying files over
files: !ruby/object:Provider::Config::Files
# These files have templating (ERB) code that will be run.
Expand Down
9 changes: 9 additions & 0 deletions mmv1/templates/terraform/constants/gke_hub_membership_diff.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
func suppressGkeHubEndpointSelfLinkDiff(_, old, new string, _ *schema.ResourceData) bool {
// The custom expander injects //container.googleapis.com/ if a selflink is supplied.
selfLink := strings.TrimPrefix(old, "//container.googleapis.com/")
if selfLink == new {
return true
}

return false
}
22 changes: 22 additions & 0 deletions mmv1/templates/terraform/custom_expand/gke_hub_membership.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<%# The license inside this block applies to this file.
# Copyright 2021 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) {
if strings.HasPrefix(v.(string), "//container.googleapis.com/") {
Copy link
Member

Choose a reason for hiding this comment

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

Can we change this guard to just //? //container.googleapis.com/ is the only environment most users will interact with, but isn't necessarily the only environment.

Copy link
Contributor

Choose a reason for hiding this comment

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

should we revert?

Copy link
Member

Choose a reason for hiding this comment

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

Seems fine to fix forward

return v, nil
} else {
v = "//container.googleapis.com/" + v.(string)
return v, nil
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ resource "google_gke_hub_membership" "membership" {
membership_id = "<%= ctx[:vars]['name'] %>"
endpoint {
gke_cluster {
resource_link = "//container.googleapis.com/${google_container_cluster.primary.id}"
resource_link = google_container_cluster.primary.id
}
}
authority {
Expand Down