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

Add support for NFS and GCS mounts in Cloud Run v2 service #16972

Merged
Show file tree
Hide file tree
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
5 changes: 5 additions & 0 deletions .changelog/9728.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
```release-note:enhancement
cloudrunv2: added `nfs` field to `google_cloud_run_v2_service.template.volumes`
cloudrunv2: added `gcs` field to `google_cloud_run_v2_service.template.volumes`
cloudrunv2: adding `tcpSocket` field to `google_cloud_run_v2.template.containers.liveness_probe`
```
271 changes: 271 additions & 0 deletions google/services/cloudrunv2/resource_cloud_run_v2_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,23 @@ If not specified, defaults to the same value as container.ports[0].containerPort
Description: `How often (in seconds) to perform the probe. Default to 10 seconds. Minimum value is 1. Maximum value for liveness probe is 3600. Maximum value for startup probe is 240. Must be greater or equal than timeoutSeconds`,
Default: 10,
},
"tcp_socket": {
Type: schema.TypeList,
Optional: true,
Description: `TCPSocketAction describes an action based on opening a socket`,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"port": {
Type: schema.TypeInt,
Required: true,
Description: `Port number to access on the container. Must be in the range 1 to 65535.
If not specified, defaults to the exposed port of the container, which
is the value of container.ports[0].containerPort.`,
},
},
},
},
"timeout_seconds": {
Type: schema.TypeInt,
Optional: true,
Expand Down Expand Up @@ -576,6 +593,51 @@ A duration in seconds with up to nine fractional digits, ending with 's'. Exampl
},
},
},
"gcs": {
Type: schema.TypeList,
Optional: true,
Description: `Represents a GCS Bucket mounted as a volume.`,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"bucket": {
Type: schema.TypeString,
Required: true,
Description: `GCS Bucket name`,
},
"read_only": {
Type: schema.TypeBool,
Optional: true,
Description: `If true, mount the GCS bucket as read-only`,
},
},
},
},
"nfs": {
Type: schema.TypeList,
Optional: true,
Description: `Represents an NFS mount.`,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"path": {
Type: schema.TypeString,
Required: true,
Description: `Path that is exported by the NFS server.`,
},
"server": {
Type: schema.TypeString,
Required: true,
Description: `Hostname or IP address of the NFS server`,
},
"read_only": {
Type: schema.TypeBool,
Optional: true,
Description: `If true, mount the NFS volume as read only`,
},
},
},
},
"secret": {
Type: schema.TypeList,
Optional: true,
Expand Down Expand Up @@ -2014,6 +2076,8 @@ func flattenCloudRunV2ServiceTemplateContainersLivenessProbe(v interface{}, d *s
flattenCloudRunV2ServiceTemplateContainersLivenessProbeHttpGet(original["httpGet"], d, config)
transformed["grpc"] =
flattenCloudRunV2ServiceTemplateContainersLivenessProbeGrpc(original["grpc"], d, config)
transformed["tcp_socket"] =
flattenCloudRunV2ServiceTemplateContainersLivenessProbeTcpSocket(original["tcpSocket"], d, config)
return []interface{}{transformed}
}
func flattenCloudRunV2ServiceTemplateContainersLivenessProbeInitialDelaySeconds(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
Expand Down Expand Up @@ -2179,6 +2243,36 @@ func flattenCloudRunV2ServiceTemplateContainersLivenessProbeGrpcService(v interf
return v
}

func flattenCloudRunV2ServiceTemplateContainersLivenessProbeTcpSocket(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
if v == nil {
return nil
}
original := v.(map[string]interface{})
if len(original) == 0 {
return nil
}
transformed := make(map[string]interface{})
transformed["port"] =
flattenCloudRunV2ServiceTemplateContainersLivenessProbeTcpSocketPort(original["port"], d, config)
return []interface{}{transformed}
}
func flattenCloudRunV2ServiceTemplateContainersLivenessProbeTcpSocketPort(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
// Handles the string fixed64 format
if strVal, ok := v.(string); ok {
if intVal, err := tpgresource.StringToFixed64(strVal); err == nil {
return intVal
}
}

// number values are represented as float64
if floatVal, ok := v.(float64); ok {
intVal := int(floatVal)
return intVal
}

return v // let terraform core handle it otherwise
}

func flattenCloudRunV2ServiceTemplateContainersStartupProbe(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
if v == nil {
return nil
Expand Down Expand Up @@ -2414,6 +2508,8 @@ func flattenCloudRunV2ServiceTemplateVolumes(v interface{}, d *schema.ResourceDa
"name": flattenCloudRunV2ServiceTemplateVolumesName(original["name"], d, config),
"secret": flattenCloudRunV2ServiceTemplateVolumesSecret(original["secret"], d, config),
"cloud_sql_instance": flattenCloudRunV2ServiceTemplateVolumesCloudSqlInstance(original["cloudSqlInstance"], d, config),
"gcs": flattenCloudRunV2ServiceTemplateVolumesGcs(original["gcs"], d, config),
"nfs": flattenCloudRunV2ServiceTemplateVolumesNfs(original["nfs"], d, config),
})
}
return transformed
Expand Down Expand Up @@ -2525,6 +2621,58 @@ func flattenCloudRunV2ServiceTemplateVolumesCloudSqlInstanceInstances(v interfac
return schema.NewSet(schema.HashString, v.([]interface{}))
}

func flattenCloudRunV2ServiceTemplateVolumesGcs(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
if v == nil {
return nil
}
original := v.(map[string]interface{})
if len(original) == 0 {
return nil
}
transformed := make(map[string]interface{})
transformed["bucket"] =
flattenCloudRunV2ServiceTemplateVolumesGcsBucket(original["bucket"], d, config)
transformed["read_only"] =
flattenCloudRunV2ServiceTemplateVolumesGcsReadOnly(original["readOnly"], d, config)
return []interface{}{transformed}
}
func flattenCloudRunV2ServiceTemplateVolumesGcsBucket(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
return v
}

func flattenCloudRunV2ServiceTemplateVolumesGcsReadOnly(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
return v
}

func flattenCloudRunV2ServiceTemplateVolumesNfs(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
if v == nil {
return nil
}
original := v.(map[string]interface{})
if len(original) == 0 {
return nil
}
transformed := make(map[string]interface{})
transformed["server"] =
flattenCloudRunV2ServiceTemplateVolumesNfsServer(original["server"], d, config)
transformed["path"] =
flattenCloudRunV2ServiceTemplateVolumesNfsPath(original["path"], d, config)
transformed["read_only"] =
flattenCloudRunV2ServiceTemplateVolumesNfsReadOnly(original["readOnly"], d, config)
return []interface{}{transformed}
}
func flattenCloudRunV2ServiceTemplateVolumesNfsServer(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
return v
}

func flattenCloudRunV2ServiceTemplateVolumesNfsPath(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
return v
}

func flattenCloudRunV2ServiceTemplateVolumesNfsReadOnly(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
return v
}

func flattenCloudRunV2ServiceTemplateExecutionEnvironment(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
return v
}
Expand Down Expand Up @@ -3533,6 +3681,13 @@ func expandCloudRunV2ServiceTemplateContainersLivenessProbe(v interface{}, d tpg
transformed["grpc"] = transformedGrpc
}

transformedTcpSocket, err := expandCloudRunV2ServiceTemplateContainersLivenessProbeTcpSocket(original["tcp_socket"], d, config)
if err != nil {
return nil, err
} else if val := reflect.ValueOf(transformedTcpSocket); val.IsValid() && !tpgresource.IsEmptyValue(val) {
transformed["tcpSocket"] = transformedTcpSocket
}

return transformed, nil
}

Expand Down Expand Up @@ -3674,6 +3829,29 @@ func expandCloudRunV2ServiceTemplateContainersLivenessProbeGrpcService(v interfa
return v, nil
}

func expandCloudRunV2ServiceTemplateContainersLivenessProbeTcpSocket(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
l := v.([]interface{})
if len(l) == 0 || l[0] == nil {
return nil, nil
}
raw := l[0]
original := raw.(map[string]interface{})
transformed := make(map[string]interface{})

transformedPort, err := expandCloudRunV2ServiceTemplateContainersLivenessProbeTcpSocketPort(original["port"], d, config)
if err != nil {
return nil, err
} else if val := reflect.ValueOf(transformedPort); val.IsValid() && !tpgresource.IsEmptyValue(val) {
transformed["port"] = transformedPort
}

return transformed, nil
}

func expandCloudRunV2ServiceTemplateContainersLivenessProbeTcpSocketPort(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
return v, nil
}

func expandCloudRunV2ServiceTemplateContainersStartupProbe(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
l := v.([]interface{})
if len(l) == 0 || l[0] == nil {
Expand Down Expand Up @@ -3936,6 +4114,20 @@ func expandCloudRunV2ServiceTemplateVolumes(v interface{}, d tpgresource.Terrafo
transformed["cloudSqlInstance"] = transformedCloudSqlInstance
}

transformedGcs, err := expandCloudRunV2ServiceTemplateVolumesGcs(original["gcs"], d, config)
if err != nil {
return nil, err
} else if val := reflect.ValueOf(transformedGcs); val.IsValid() && !tpgresource.IsEmptyValue(val) {
transformed["gcs"] = transformedGcs
}

transformedNfs, err := expandCloudRunV2ServiceTemplateVolumesNfs(original["nfs"], d, config)
if err != nil {
return nil, err
} else if val := reflect.ValueOf(transformedNfs); val.IsValid() && !tpgresource.IsEmptyValue(val) {
transformed["nfs"] = transformedNfs
}

req = append(req, transformed)
}
return req, nil
Expand Down Expand Up @@ -4058,6 +4250,85 @@ func expandCloudRunV2ServiceTemplateVolumesCloudSqlInstanceInstances(v interface
return v, nil
}

func expandCloudRunV2ServiceTemplateVolumesGcs(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
l := v.([]interface{})
if len(l) == 0 || l[0] == nil {
return nil, nil
}
raw := l[0]
original := raw.(map[string]interface{})
transformed := make(map[string]interface{})

transformedBucket, err := expandCloudRunV2ServiceTemplateVolumesGcsBucket(original["bucket"], d, config)
if err != nil {
return nil, err
} else if val := reflect.ValueOf(transformedBucket); val.IsValid() && !tpgresource.IsEmptyValue(val) {
transformed["bucket"] = transformedBucket
}

transformedReadOnly, err := expandCloudRunV2ServiceTemplateVolumesGcsReadOnly(original["read_only"], d, config)
if err != nil {
return nil, err
} else if val := reflect.ValueOf(transformedReadOnly); val.IsValid() && !tpgresource.IsEmptyValue(val) {
transformed["readOnly"] = transformedReadOnly
}

return transformed, nil
}

func expandCloudRunV2ServiceTemplateVolumesGcsBucket(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
return v, nil
}

func expandCloudRunV2ServiceTemplateVolumesGcsReadOnly(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
return v, nil
}

func expandCloudRunV2ServiceTemplateVolumesNfs(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
l := v.([]interface{})
if len(l) == 0 || l[0] == nil {
return nil, nil
}
raw := l[0]
original := raw.(map[string]interface{})
transformed := make(map[string]interface{})

transformedServer, err := expandCloudRunV2ServiceTemplateVolumesNfsServer(original["server"], d, config)
if err != nil {
return nil, err
} else if val := reflect.ValueOf(transformedServer); val.IsValid() && !tpgresource.IsEmptyValue(val) {
transformed["server"] = transformedServer
}

transformedPath, err := expandCloudRunV2ServiceTemplateVolumesNfsPath(original["path"], d, config)
if err != nil {
return nil, err
} else if val := reflect.ValueOf(transformedPath); val.IsValid() && !tpgresource.IsEmptyValue(val) {
transformed["path"] = transformedPath
}

transformedReadOnly, err := expandCloudRunV2ServiceTemplateVolumesNfsReadOnly(original["read_only"], d, config)
if err != nil {
return nil, err
} else if val := reflect.ValueOf(transformedReadOnly); val.IsValid() && !tpgresource.IsEmptyValue(val) {
transformed["readOnly"] = transformedReadOnly
}

return transformed, nil
}

func expandCloudRunV2ServiceTemplateVolumesNfsServer(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
return v, nil
}

func expandCloudRunV2ServiceTemplateVolumesNfsPath(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
return v, nil
}

func expandCloudRunV2ServiceTemplateVolumesNfsReadOnly(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
return v, nil
}

func expandCloudRunV2ServiceTemplateExecutionEnvironment(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
return v, nil
}
Expand Down
Loading