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 nfs support to cloudrun v2 jobs in beta #7169

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
3 changes: 3 additions & 0 deletions .changelog/10220.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
cloudrunv2: added `template.volumes.nfs` field to `google_cloud_run_v2_job` resource (beta)
```
107 changes: 107 additions & 0 deletions google-beta/services/cloudrunv2/resource_cloud_run_v2_job.go
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,31 @@ A duration in seconds with up to nine fractional digits, ending with 's'. Exampl
},
},
},
"nfs": {
Type: schema.TypeList,
Optional: true,
Description: `NFS share mounted as a volume. This feature requires the launch stage to be set to ALPHA or BETA.`,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"server": {
Type: schema.TypeString,
Required: true,
Description: `Hostname or IP address of the NFS server.`,
},
"path": {
Type: schema.TypeString,
Optional: true,
Description: `Path that is exported by the NFS server.`,
},
"read_only": {
Type: schema.TypeBool,
Optional: true,
Description: `If true, mount this volume as read-only in all mounts.`,
},
},
},
},
"secret": {
Type: schema.TypeList,
Optional: true,
Expand Down Expand Up @@ -1569,6 +1594,7 @@ func flattenCloudRunV2JobTemplateTemplateVolumes(v interface{}, d *schema.Resour
"cloud_sql_instance": flattenCloudRunV2JobTemplateTemplateVolumesCloudSqlInstance(original["cloudSqlInstance"], d, config),
"empty_dir": flattenCloudRunV2JobTemplateTemplateVolumesEmptyDir(original["emptyDir"], d, config),
"gcs": flattenCloudRunV2JobTemplateTemplateVolumesGcs(original["gcs"], d, config),
"nfs": flattenCloudRunV2JobTemplateTemplateVolumesNfs(original["nfs"], d, config),
})
}
return transformed
Expand Down Expand Up @@ -1723,6 +1749,35 @@ func flattenCloudRunV2JobTemplateTemplateVolumesGcsReadOnly(v interface{}, d *sc
return v
}

func flattenCloudRunV2JobTemplateTemplateVolumesNfs(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"] =
flattenCloudRunV2JobTemplateTemplateVolumesNfsServer(original["server"], d, config)
transformed["path"] =
flattenCloudRunV2JobTemplateTemplateVolumesNfsPath(original["path"], d, config)
transformed["read_only"] =
flattenCloudRunV2JobTemplateTemplateVolumesNfsReadOnly(original["readOnly"], d, config)
return []interface{}{transformed}
}
func flattenCloudRunV2JobTemplateTemplateVolumesNfsServer(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
return v
}

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

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

func flattenCloudRunV2JobTemplateTemplateTimeout(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
return v
}
Expand Down Expand Up @@ -2545,6 +2600,13 @@ func expandCloudRunV2JobTemplateTemplateVolumes(v interface{}, d tpgresource.Ter
transformed["gcs"] = transformedGcs
}

transformedNfs, err := expandCloudRunV2JobTemplateTemplateVolumesNfs(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 @@ -2734,6 +2796,51 @@ func expandCloudRunV2JobTemplateTemplateVolumesGcsReadOnly(v interface{}, d tpgr
return v, nil
}

func expandCloudRunV2JobTemplateTemplateVolumesNfs(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 := expandCloudRunV2JobTemplateTemplateVolumesNfsServer(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 := expandCloudRunV2JobTemplateTemplateVolumesNfsPath(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 := expandCloudRunV2JobTemplateTemplateVolumesNfsReadOnly(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 expandCloudRunV2JobTemplateTemplateVolumesNfsServer(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
return v, nil
}

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

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

func expandCloudRunV2JobTemplateTemplateTimeout(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
return v, nil
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -386,3 +386,67 @@ func testAccCloudRunV2Job_cloudrunv2JobWithGcsVolume(context map[string]interfac
}
`, context)
}

func TestAccCloudRunV2Job_cloudrunv2JobWithNfsUpdate(t *testing.T) {
t.Parallel()

jobName := fmt.Sprintf("tf-test-cloudrun-service%s", acctest.RandString(t, 10))
context := map[string]interface{}{
"job_name": jobName,
}

acctest.VcrTest(t, resource.TestCase{
PreCheck: func() { acctest.AccTestPreCheck(t) },
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
CheckDestroy: testAccCheckCloudRunV2JobDestroyProducer(t),
Steps: []resource.TestStep{
{
Config: testAccCloudRunV2Job_cloudrunv2JobWithNoVolume(context),
},
{
ResourceName: "google_cloud_run_v2_job.default",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"location", "launch_stage"},
},
{
Config: testAccCloudRunV2Job_cloudrunv2JobWithNfsVolume(context),
},
{
ResourceName: "google_cloud_run_v2_job.default",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"location", "launch_stage"},
},
},
})
}

func testAccCloudRunV2Job_cloudrunv2JobWithNfsVolume(context map[string]interface{}) string {
return acctest.Nprintf(`
resource "google_cloud_run_v2_job" "default" {
name = "%{job_name}"
location = "us-central1"
launch_stage = "BETA"
template {
template {
containers {
image = "us-docker.pkg.dev/cloudrun/container/job"
volume_mounts {
name = "nfs"
mount_path = "/mnt/nfs"
}
}
volumes {
name = "nfs"
nfs {
server = "10.0.10.10"
path = "/"
read_only = true
}
}
}
}
}
`, context)
}
19 changes: 19 additions & 0 deletions website/docs/r/cloud_run_v2_job.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -561,6 +561,11 @@ The following arguments are supported:
Cloud Storage bucket mounted as a volume using GCSFuse. This feature requires the launch stage to be set to ALPHA or BETA.
Structure is [documented below](#nested_gcs).

* `nfs` -
(Optional, [Beta](https://terraform.io/docs/providers/google/guides/provider_versions.html))
NFS share mounted as a volume. This feature requires the launch stage to be set to ALPHA or BETA.
Structure is [documented below](#nested_nfs).


<a name="nested_secret"></a>The `secret` block supports:

Expand Down Expand Up @@ -620,6 +625,20 @@ The following arguments are supported:
(Optional)
If true, mount this volume as read-only in all mounts. If false, mount this volume as read-write.

<a name="nested_nfs"></a>The `nfs` block supports:

* `server` -
(Required)
Hostname or IP address of the NFS server.

* `path` -
(Optional)
Path that is exported by the NFS server.

* `read_only` -
(Optional)
If true, mount this volume as read-only in all mounts.

<a name="nested_vpc_access"></a>The `vpc_access` block supports:

* `connector` -
Expand Down