From 347d15b2a9f7b7bb0e8d79068b9725f20daf30ec Mon Sep 17 00:00:00 2001 From: Modular Magician Date: Thu, 26 Mar 2020 17:51:31 +0000 Subject: [PATCH] Virtual field for `google_cloud_run_service` revision names (#3306) * Add `autogenerate_revision_name` virtual field to `google_cloud_run_service` * Add field to examples Signed-off-by: Modular Magician --- google/cloudrun_service.go | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/google/cloudrun_service.go b/google/cloudrun_service.go index c7db1f35d..e22cf400a 100644 --- a/google/cloudrun_service.go +++ b/google/cloudrun_service.go @@ -14,7 +14,20 @@ package google -import "reflect" +import ( + "fmt" + "reflect" + + "github.com/hashicorp/terraform-plugin-sdk/helper/schema" +) + +func revisionNameCustomizeDiff(diff *schema.ResourceDiff, v interface{}) error { + autogen := diff.Get("autogenerate_revision_name").(bool) + if autogen && diff.HasChange("template.0.metadata.0.name") { + return fmt.Errorf("google_cloud_run_service: `template.metadata.name` cannot be set while `autogenerate_revision_name` is true. Please remove the field or set `autogenerate_revision_name` to false.") + } + return nil +} func GetCloudRunServiceCaiObject(d TerraformResourceData, config *Config) (Asset, error) { name, err := assetName(d, config, "//cloudrun.googleapis.com/apis/serving.knative.dev/v1/namespaces/{{project}}/services/{{name}}") @@ -280,6 +293,9 @@ func expandCloudRunServiceSpecTemplateMetadataAnnotations(v interface{}, d Terra } func expandCloudRunServiceSpecTemplateMetadataName(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { + if d.Get("autogenerate_revision_name") == true { + return nil, nil + } return v, nil }