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

Virtual field for google_cloud_run_service revision names #405

Merged
Changes from all 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
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