Skip to content

Commit

Permalink
Make cloudrunv2 containers' env a set (#11199) (#7812)
Browse files Browse the repository at this point in the history
[upstream:a33654d57d620bb7a07e2a79e6b1c01ddfa2326d]

Signed-off-by: Modular Magician <[email protected]>
  • Loading branch information
modular-magician authored Jul 25, 2024
1 parent 9fcc29d commit dd55066
Show file tree
Hide file tree
Showing 4 changed files with 124 additions and 94 deletions.
3 changes: 3 additions & 0 deletions .changelog/11199.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:breaking-change
cloudrunv2: retyped `containers.env` to SET from ARRAY for `google_cloud_run_v2_service` and `google_cloud_run_v2_job`.
```
100 changes: 53 additions & 47 deletions google-beta/services/cloudrunv2/resource_cloud_run_v2_job.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,53 +112,11 @@ func ResourceCloudRunV2Job() *schema.Resource {
},
},
"env": {
Type: schema.TypeList,
Type: schema.TypeSet,
Optional: true,
Description: `List of environment variables to set in the container.`,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"name": {
Type: schema.TypeString,
Required: true,
Description: `Name of the environment variable. Must be a C_IDENTIFIER, and mnay not exceed 32768 characters.`,
},
"value": {
Type: schema.TypeString,
Optional: true,
Description: `Variable references $(VAR_NAME) are expanded using the previous defined environment variables in the container and any route environment variables. If a variable cannot be resolved, the reference in the input string will be unchanged. The $(VAR_NAME) syntax can be escaped with a double $$, ie: $$(VAR_NAME). Escaped references will never be expanded, regardless of whether the variable exists or not. Defaults to "", and the maximum length is 32768 bytes`,
},
"value_source": {
Type: schema.TypeList,
Optional: true,
Description: `Source for the environment variable's value.`,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"secret_key_ref": {
Type: schema.TypeList,
Optional: true,
Description: `Selects a secret and a specific version from Cloud Secret Manager.`,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"secret": {
Type: schema.TypeString,
Required: true,
Description: `The name of the secret in Cloud Secret Manager. Format: {secretName} if the secret is in the same project. projects/{project}/secrets/{secretName} if the secret is in a different project.`,
},
"version": {
Type: schema.TypeString,
Required: true,
Description: `The Cloud Secret Manager secret version. Can be 'latest' for the latest value or an integer for a specific version.`,
},
},
},
},
},
},
},
},
},
Elem: cloudrunv2JobTemplateTemplateContainersContainersEnvSchema(),
// Default schema.HashSchema is used.
},
"name": {
Type: schema.TypeString,
Expand Down Expand Up @@ -809,6 +767,53 @@ A timestamp in RFC3339 UTC "Zulu" format, with nanosecond resolution and up to n
}
}

func cloudrunv2JobTemplateTemplateContainersContainersEnvSchema() *schema.Resource {
return &schema.Resource{
Schema: map[string]*schema.Schema{
"name": {
Type: schema.TypeString,
Required: true,
Description: `Name of the environment variable. Must be a C_IDENTIFIER, and mnay not exceed 32768 characters.`,
},
"value": {
Type: schema.TypeString,
Optional: true,
Description: `Variable references $(VAR_NAME) are expanded using the previous defined environment variables in the container and any route environment variables. If a variable cannot be resolved, the reference in the input string will be unchanged. The $(VAR_NAME) syntax can be escaped with a double $$, ie: $$(VAR_NAME). Escaped references will never be expanded, regardless of whether the variable exists or not. Defaults to "", and the maximum length is 32768 bytes`,
},
"value_source": {
Type: schema.TypeList,
Optional: true,
Description: `Source for the environment variable's value.`,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"secret_key_ref": {
Type: schema.TypeList,
Optional: true,
Description: `Selects a secret and a specific version from Cloud Secret Manager.`,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"secret": {
Type: schema.TypeString,
Required: true,
Description: `The name of the secret in Cloud Secret Manager. Format: {secretName} if the secret is in the same project. projects/{project}/secrets/{secretName} if the secret is in a different project.`,
},
"version": {
Type: schema.TypeString,
Required: true,
Description: `The Cloud Secret Manager secret version. Can be 'latest' for the latest value or an integer for a specific version.`,
},
},
},
},
},
},
},
},
}
}

func resourceCloudRunV2JobCreate(d *schema.ResourceData, meta interface{}) error {
config := meta.(*transport_tpg.Config)
userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent)
Expand Down Expand Up @@ -1492,14 +1497,14 @@ func flattenCloudRunV2JobTemplateTemplateContainersEnv(v interface{}, d *schema.
return v
}
l := v.([]interface{})
transformed := make([]interface{}, 0, len(l))
transformed := schema.NewSet(schema.HashResource(cloudrunv2JobTemplateTemplateContainersContainersEnvSchema()), []interface{}{})
for _, raw := range l {
original := raw.(map[string]interface{})
if len(original) < 1 {
// Do not include empty json objects coming back from the api
continue
}
transformed = append(transformed, map[string]interface{}{
transformed.Add(map[string]interface{}{
"name": flattenCloudRunV2JobTemplateTemplateContainersEnvName(original["name"], d, config),
"value": flattenCloudRunV2JobTemplateTemplateContainersEnvValue(original["value"], d, config),
"value_source": flattenCloudRunV2JobTemplateTemplateContainersEnvValueSource(original["valueSource"], d, config),
Expand Down Expand Up @@ -2422,6 +2427,7 @@ func expandCloudRunV2JobTemplateTemplateContainersArgs(v interface{}, d tpgresou
}

func expandCloudRunV2JobTemplateTemplateContainersEnv(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
v = v.(*schema.Set).List()
l := v.([]interface{})
req := make([]interface{}, 0, len(l))
for _, raw := range l {
Expand Down
100 changes: 53 additions & 47 deletions google-beta/services/cloudrunv2/resource_cloud_run_v2_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,53 +123,11 @@ This field follows Kubernetes annotations' namespacing, limits, and rules.`,
},
},
"env": {
Type: schema.TypeList,
Type: schema.TypeSet,
Optional: true,
Description: `List of environment variables to set in the container.`,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"name": {
Type: schema.TypeString,
Required: true,
Description: `Name of the environment variable. Must be a C_IDENTIFIER, and mnay not exceed 32768 characters.`,
},
"value": {
Type: schema.TypeString,
Optional: true,
Description: `Variable references $(VAR_NAME) are expanded using the previous defined environment variables in the container and any route environment variables. If a variable cannot be resolved, the reference in the input string will be unchanged. The $(VAR_NAME) syntax can be escaped with a double $$, ie: $$(VAR_NAME). Escaped references will never be expanded, regardless of whether the variable exists or not. Defaults to "", and the maximum length is 32768 bytes`,
},
"value_source": {
Type: schema.TypeList,
Optional: true,
Description: `Source for the environment variable's value.`,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"secret_key_ref": {
Type: schema.TypeList,
Optional: true,
Description: `Selects a secret and a specific version from Cloud Secret Manager.`,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"secret": {
Type: schema.TypeString,
Required: true,
Description: `The name of the secret in Cloud Secret Manager. Format: {secretName} if the secret is in the same project. projects/{project}/secrets/{secretName} if the secret is in a different project.`,
},
"version": {
Type: schema.TypeString,
Optional: true,
Description: `The Cloud Secret Manager secret version. Can be 'latest' for the latest value or an integer for a specific version.`,
},
},
},
},
},
},
},
},
},
Elem: cloudrunv2ServiceTemplateContainersContainersEnvSchema(),
// Default schema.HashSchema is used.
},
"liveness_probe": {
Type: schema.TypeList,
Expand Down Expand Up @@ -1149,6 +1107,53 @@ If reconciliation failed, trafficStatuses, observedGeneration, and latestReadyRe
}
}

func cloudrunv2ServiceTemplateContainersContainersEnvSchema() *schema.Resource {
return &schema.Resource{
Schema: map[string]*schema.Schema{
"name": {
Type: schema.TypeString,
Required: true,
Description: `Name of the environment variable. Must be a C_IDENTIFIER, and mnay not exceed 32768 characters.`,
},
"value": {
Type: schema.TypeString,
Optional: true,
Description: `Variable references $(VAR_NAME) are expanded using the previous defined environment variables in the container and any route environment variables. If a variable cannot be resolved, the reference in the input string will be unchanged. The $(VAR_NAME) syntax can be escaped with a double $$, ie: $$(VAR_NAME). Escaped references will never be expanded, regardless of whether the variable exists or not. Defaults to "", and the maximum length is 32768 bytes`,
},
"value_source": {
Type: schema.TypeList,
Optional: true,
Description: `Source for the environment variable's value.`,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"secret_key_ref": {
Type: schema.TypeList,
Optional: true,
Description: `Selects a secret and a specific version from Cloud Secret Manager.`,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"secret": {
Type: schema.TypeString,
Required: true,
Description: `The name of the secret in Cloud Secret Manager. Format: {secretName} if the secret is in the same project. projects/{project}/secrets/{secretName} if the secret is in a different project.`,
},
"version": {
Type: schema.TypeString,
Optional: true,
Description: `The Cloud Secret Manager secret version. Can be 'latest' for the latest value or an integer for a specific version.`,
},
},
},
},
},
},
},
},
}
}

func resourceCloudRunV2ServiceCreate(d *schema.ResourceData, meta interface{}) error {
config := meta.(*transport_tpg.Config)
userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent)
Expand Down Expand Up @@ -2012,14 +2017,14 @@ func flattenCloudRunV2ServiceTemplateContainersEnv(v interface{}, d *schema.Reso
return v
}
l := v.([]interface{})
transformed := make([]interface{}, 0, len(l))
transformed := schema.NewSet(schema.HashResource(cloudrunv2ServiceTemplateContainersContainersEnvSchema()), []interface{}{})
for _, raw := range l {
original := raw.(map[string]interface{})
if len(original) < 1 {
// Do not include empty json objects coming back from the api
continue
}
transformed = append(transformed, map[string]interface{}{
transformed.Add(map[string]interface{}{
"name": flattenCloudRunV2ServiceTemplateContainersEnvName(original["name"], d, config),
"value": flattenCloudRunV2ServiceTemplateContainersEnvValue(original["value"], d, config),
"value_source": flattenCloudRunV2ServiceTemplateContainersEnvValueSource(original["valueSource"], d, config),
Expand Down Expand Up @@ -3571,6 +3576,7 @@ func expandCloudRunV2ServiceTemplateContainersArgs(v interface{}, d tpgresource.
}

func expandCloudRunV2ServiceTemplateContainersEnv(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
v = v.(*schema.Set).List()
l := v.([]interface{})
req := make([]interface{}, 0, len(l))
for _, raw := range l {
Expand Down
15 changes: 15 additions & 0 deletions website/docs/guides/version_6_upgrade.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -120,12 +120,27 @@ Removed in favor of field `settings.ip_configuration.ssl_mode`.

An empty value means the setting should be cleared.

## Resource: `google_cloud_run_v2_job`

### retyped `containers.env` to SET from ARRAY

Previously, `containers.env` was a list, making it order-dependent. It is now a set.

If you were relying on accessing an individual environment variable by index (for example, `google_cloud_run_v2_job.template.containers.0.env.0.name`), then that will now need to by hash (for example, `google_cloud_run_v2_job.template.containers.0.env.<some-hash>.name`).

## Resource: `google_cloud_run_v2_service`

### `liveness_probe` no longer defaults from API

Cloud Run does not provide a default value for liveness probe. Now removing this field
will remove the liveness probe from the Cloud Run service.

### retyped `containers.env` to SET from ARRAY

Previously, `containers.env` was a list, making it order-dependent. It is now a set.

If you were relying on accessing an individual environment variable by index (for example, `google_cloud_run_v2_service.template.containers.0.env.0.name`), then that will now need to by hash (for example, `google_cloud_run_v2_service.template.containers.0.env.<some-hash>.name`).

## Resource: `google_compute_backend_service`

## Resource: `google_compute_region_backend_service`
Expand Down

0 comments on commit dd55066

Please sign in to comment.