Skip to content

Commit

Permalink
Allow Cloud Run metadata block to be optional (#2793)
Browse files Browse the repository at this point in the history
Merged PR #2793.
  • Loading branch information
chrisst authored and modular-magician committed Dec 6, 2019
1 parent c6509ff commit 5eb989d
Show file tree
Hide file tree
Showing 9 changed files with 12 additions and 17 deletions.
2 changes: 1 addition & 1 deletion build/terraform
2 changes: 1 addition & 1 deletion build/terraform-beta
2 changes: 1 addition & 1 deletion build/terraform-mapper
2 changes: 1 addition & 1 deletion products/cloudrun/api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ objects:
name: namespace
description: |-
In Cloud Run the namespace must be equal to either the
project ID or project number.
project ID or project number. It will default to the resource's project.
- !ruby/object:Api::Type::KeyValuePairs
name: annotations
description: |-
Expand Down
4 changes: 4 additions & 0 deletions products/cloudrun/terraform.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,10 @@ overrides: !ruby/object:Overrides::ResourceOverrides
spec.template.metadata.namespace: !ruby/object:Overrides::Terraform::PropertyOverride
default_from_api: true
custom_expand: "templates/terraform/custom_expand/default_to_project.go.erb"
# Terraform autofills the only required field in metadata
metadata: !ruby/object:Overrides::Terraform::PropertyOverride
default_from_api: true
required: false
metadata.namespace: !ruby/object:Overrides::Terraform::PropertyOverride
# marking namepsace as optional so that 1) it can be inferred from the provider
# project and 2) so customizeDiff can clear the diff when projectNumber == projectName
Expand Down
5 changes: 4 additions & 1 deletion templates/terraform/encoders/cloud_run_service.go.erb
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,13 @@
# limitations under the License.
-%>
name := d.Get("name").(string)
if obj["metadata"] == nil {
obj["metadata"] = make(map[string]interface{})
}
metadata := obj["metadata"].(map[string]interface{})
metadata["name"] = name

// The only acceptable version/kind right now
obj["apiVersion"] = "serving.knative.dev/v1"
obj["kind"] = "<%= "#{object.name}" -%>"
obj["kind"] = "Service"
return obj, nil
4 changes: 0 additions & 4 deletions templates/terraform/examples/cloud_run_service_basic.tf.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@ resource "google_cloud_run_service" "<%= ctx[:primary_resource_id] %>" {
name = "<%= ctx[:vars]['cloud_run_service_name'] %>"
location = "us-central1"

metadata {
namespace = "<%= ctx[:test_env_vars]['namespace'] %>"
}

template {
spec {
containers {
Expand Down
4 changes: 0 additions & 4 deletions templates/terraform/examples/cloud_run_service_noauth.tf.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@ resource "google_cloud_run_service" "<%= ctx[:primary_resource_id] %>" {
name = "<%= ctx[:vars]['cloud_run_service_name'] %>"
location = "us-central1"

metadata {
namespace = "<%= ctx[:test_env_vars]['project'] %>"
}

template {
spec {
containers {
Expand Down
4 changes: 0 additions & 4 deletions templates/terraform/examples/cloud_run_service_sql.tf.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@ resource "google_cloud_run_service" "<%= ctx[:primary_resource_id] %>" {
name = "<%= ctx[:vars]['cloud_run_service_name'] %>"
location = "us-central1"

metadata {
namespace = "<%= ctx[:test_env_vars]['project'] %>"
}

template {
spec {
containers {
Expand Down

0 comments on commit 5eb989d

Please sign in to comment.