Skip to content

Commit

Permalink
Add support for NFS and GCS mounts in Cloud Run v2 service (#9728) (#…
Browse files Browse the repository at this point in the history
…6845)

* feat: add support for NFS and GCS mounts in Cloud Run v2 service

```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.livenessProbe`
```

* fix: add required to relevant properties
[upstream:1de3c302c346c96d1313a4f3ec7e3c815bd8de59]

Signed-off-by: Modular Magician <[email protected]>
  • Loading branch information
modular-magician authored Jan 11, 2024
1 parent ff6a5fe commit 49919d8
Show file tree
Hide file tree
Showing 4 changed files with 563 additions and 0 deletions.
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-beta/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 @@ -598,6 +615,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 @@ -2036,6 +2098,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 @@ -2201,6 +2265,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 @@ -2437,6 +2531,8 @@ func flattenCloudRunV2ServiceTemplateVolumes(v interface{}, d *schema.ResourceDa
"secret": flattenCloudRunV2ServiceTemplateVolumesSecret(original["secret"], d, config),
"cloud_sql_instance": flattenCloudRunV2ServiceTemplateVolumesCloudSqlInstance(original["cloudSqlInstance"], d, config),
"empty_dir": flattenCloudRunV2ServiceTemplateVolumesEmptyDir(original["emptyDir"], d, config),
"gcs": flattenCloudRunV2ServiceTemplateVolumesGcs(original["gcs"], d, config),
"nfs": flattenCloudRunV2ServiceTemplateVolumesNfs(original["nfs"], d, config),
})
}
return transformed
Expand Down Expand Up @@ -2571,6 +2667,58 @@ func flattenCloudRunV2ServiceTemplateVolumesEmptyDirSizeLimit(v interface{}, d *
return v
}

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 @@ -3579,6 +3727,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 @@ -3720,6 +3875,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 @@ -3989,6 +4167,20 @@ func expandCloudRunV2ServiceTemplateVolumes(v interface{}, d tpgresource.Terrafo
transformed["emptyDir"] = transformedEmptyDir
}

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 @@ -4145,6 +4337,85 @@ func expandCloudRunV2ServiceTemplateVolumesEmptyDirSizeLimit(v interface{}, d tp
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

0 comments on commit 49919d8

Please sign in to comment.