Skip to content

Commit

Permalink
Virtual field for google_cloud_run_service revision names (#3306) (#…
Browse files Browse the repository at this point in the history
…405)

* Add `autogenerate_revision_name` virtual field to `google_cloud_run_service`

* Add field to examples

Signed-off-by: Modular Magician <[email protected]>
  • Loading branch information
modular-magician authored Mar 26, 2020
1 parent 5b1ca3f commit 26dd4b9
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion google/cloudrun_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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}}")
Expand Down Expand Up @@ -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
}

Expand Down

0 comments on commit 26dd4b9

Please sign in to comment.