Skip to content

Commit c62beea

Browse files
add nfs support to cloudrun v2 jobs in beta (#10220) (#7169)
[upstream:ddf25605fc2a7c763a9e57c891223c20bfe45171] Signed-off-by: Modular Magician <[email protected]>
1 parent a8d1df6 commit c62beea

File tree

4 files changed

+193
-0
lines changed

4 files changed

+193
-0
lines changed

.changelog/10220.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:enhancement
2+
cloudrunv2: added `template.volumes.nfs` field to `google_cloud_run_v2_job` resource (beta)
3+
```

google-beta/services/cloudrunv2/resource_cloud_run_v2_job.go

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,31 @@ A duration in seconds with up to nine fractional digits, ending with 's'. Exampl
333333
},
334334
},
335335
},
336+
"nfs": {
337+
Type: schema.TypeList,
338+
Optional: true,
339+
Description: `NFS share mounted as a volume. This feature requires the launch stage to be set to ALPHA or BETA.`,
340+
MaxItems: 1,
341+
Elem: &schema.Resource{
342+
Schema: map[string]*schema.Schema{
343+
"server": {
344+
Type: schema.TypeString,
345+
Required: true,
346+
Description: `Hostname or IP address of the NFS server.`,
347+
},
348+
"path": {
349+
Type: schema.TypeString,
350+
Optional: true,
351+
Description: `Path that is exported by the NFS server.`,
352+
},
353+
"read_only": {
354+
Type: schema.TypeBool,
355+
Optional: true,
356+
Description: `If true, mount this volume as read-only in all mounts.`,
357+
},
358+
},
359+
},
360+
},
336361
"secret": {
337362
Type: schema.TypeList,
338363
Optional: true,
@@ -1569,6 +1594,7 @@ func flattenCloudRunV2JobTemplateTemplateVolumes(v interface{}, d *schema.Resour
15691594
"cloud_sql_instance": flattenCloudRunV2JobTemplateTemplateVolumesCloudSqlInstance(original["cloudSqlInstance"], d, config),
15701595
"empty_dir": flattenCloudRunV2JobTemplateTemplateVolumesEmptyDir(original["emptyDir"], d, config),
15711596
"gcs": flattenCloudRunV2JobTemplateTemplateVolumesGcs(original["gcs"], d, config),
1597+
"nfs": flattenCloudRunV2JobTemplateTemplateVolumesNfs(original["nfs"], d, config),
15721598
})
15731599
}
15741600
return transformed
@@ -1723,6 +1749,35 @@ func flattenCloudRunV2JobTemplateTemplateVolumesGcsReadOnly(v interface{}, d *sc
17231749
return v
17241750
}
17251751

1752+
func flattenCloudRunV2JobTemplateTemplateVolumesNfs(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
1753+
if v == nil {
1754+
return nil
1755+
}
1756+
original := v.(map[string]interface{})
1757+
if len(original) == 0 {
1758+
return nil
1759+
}
1760+
transformed := make(map[string]interface{})
1761+
transformed["server"] =
1762+
flattenCloudRunV2JobTemplateTemplateVolumesNfsServer(original["server"], d, config)
1763+
transformed["path"] =
1764+
flattenCloudRunV2JobTemplateTemplateVolumesNfsPath(original["path"], d, config)
1765+
transformed["read_only"] =
1766+
flattenCloudRunV2JobTemplateTemplateVolumesNfsReadOnly(original["readOnly"], d, config)
1767+
return []interface{}{transformed}
1768+
}
1769+
func flattenCloudRunV2JobTemplateTemplateVolumesNfsServer(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
1770+
return v
1771+
}
1772+
1773+
func flattenCloudRunV2JobTemplateTemplateVolumesNfsPath(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
1774+
return v
1775+
}
1776+
1777+
func flattenCloudRunV2JobTemplateTemplateVolumesNfsReadOnly(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
1778+
return v
1779+
}
1780+
17261781
func flattenCloudRunV2JobTemplateTemplateTimeout(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
17271782
return v
17281783
}
@@ -2545,6 +2600,13 @@ func expandCloudRunV2JobTemplateTemplateVolumes(v interface{}, d tpgresource.Ter
25452600
transformed["gcs"] = transformedGcs
25462601
}
25472602

2603+
transformedNfs, err := expandCloudRunV2JobTemplateTemplateVolumesNfs(original["nfs"], d, config)
2604+
if err != nil {
2605+
return nil, err
2606+
} else if val := reflect.ValueOf(transformedNfs); val.IsValid() && !tpgresource.IsEmptyValue(val) {
2607+
transformed["nfs"] = transformedNfs
2608+
}
2609+
25482610
req = append(req, transformed)
25492611
}
25502612
return req, nil
@@ -2734,6 +2796,51 @@ func expandCloudRunV2JobTemplateTemplateVolumesGcsReadOnly(v interface{}, d tpgr
27342796
return v, nil
27352797
}
27362798

2799+
func expandCloudRunV2JobTemplateTemplateVolumesNfs(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
2800+
l := v.([]interface{})
2801+
if len(l) == 0 || l[0] == nil {
2802+
return nil, nil
2803+
}
2804+
raw := l[0]
2805+
original := raw.(map[string]interface{})
2806+
transformed := make(map[string]interface{})
2807+
2808+
transformedServer, err := expandCloudRunV2JobTemplateTemplateVolumesNfsServer(original["server"], d, config)
2809+
if err != nil {
2810+
return nil, err
2811+
} else if val := reflect.ValueOf(transformedServer); val.IsValid() && !tpgresource.IsEmptyValue(val) {
2812+
transformed["server"] = transformedServer
2813+
}
2814+
2815+
transformedPath, err := expandCloudRunV2JobTemplateTemplateVolumesNfsPath(original["path"], d, config)
2816+
if err != nil {
2817+
return nil, err
2818+
} else if val := reflect.ValueOf(transformedPath); val.IsValid() && !tpgresource.IsEmptyValue(val) {
2819+
transformed["path"] = transformedPath
2820+
}
2821+
2822+
transformedReadOnly, err := expandCloudRunV2JobTemplateTemplateVolumesNfsReadOnly(original["read_only"], d, config)
2823+
if err != nil {
2824+
return nil, err
2825+
} else if val := reflect.ValueOf(transformedReadOnly); val.IsValid() && !tpgresource.IsEmptyValue(val) {
2826+
transformed["readOnly"] = transformedReadOnly
2827+
}
2828+
2829+
return transformed, nil
2830+
}
2831+
2832+
func expandCloudRunV2JobTemplateTemplateVolumesNfsServer(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
2833+
return v, nil
2834+
}
2835+
2836+
func expandCloudRunV2JobTemplateTemplateVolumesNfsPath(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
2837+
return v, nil
2838+
}
2839+
2840+
func expandCloudRunV2JobTemplateTemplateVolumesNfsReadOnly(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
2841+
return v, nil
2842+
}
2843+
27372844
func expandCloudRunV2JobTemplateTemplateTimeout(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
27382845
return v, nil
27392846
}

google-beta/services/cloudrunv2/resource_cloud_run_v2_job_test.go

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -386,3 +386,67 @@ func testAccCloudRunV2Job_cloudrunv2JobWithGcsVolume(context map[string]interfac
386386
}
387387
`, context)
388388
}
389+
390+
func TestAccCloudRunV2Job_cloudrunv2JobWithNfsUpdate(t *testing.T) {
391+
t.Parallel()
392+
393+
jobName := fmt.Sprintf("tf-test-cloudrun-service%s", acctest.RandString(t, 10))
394+
context := map[string]interface{}{
395+
"job_name": jobName,
396+
}
397+
398+
acctest.VcrTest(t, resource.TestCase{
399+
PreCheck: func() { acctest.AccTestPreCheck(t) },
400+
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
401+
CheckDestroy: testAccCheckCloudRunV2JobDestroyProducer(t),
402+
Steps: []resource.TestStep{
403+
{
404+
Config: testAccCloudRunV2Job_cloudrunv2JobWithNoVolume(context),
405+
},
406+
{
407+
ResourceName: "google_cloud_run_v2_job.default",
408+
ImportState: true,
409+
ImportStateVerify: true,
410+
ImportStateVerifyIgnore: []string{"location", "launch_stage"},
411+
},
412+
{
413+
Config: testAccCloudRunV2Job_cloudrunv2JobWithNfsVolume(context),
414+
},
415+
{
416+
ResourceName: "google_cloud_run_v2_job.default",
417+
ImportState: true,
418+
ImportStateVerify: true,
419+
ImportStateVerifyIgnore: []string{"location", "launch_stage"},
420+
},
421+
},
422+
})
423+
}
424+
425+
func testAccCloudRunV2Job_cloudrunv2JobWithNfsVolume(context map[string]interface{}) string {
426+
return acctest.Nprintf(`
427+
resource "google_cloud_run_v2_job" "default" {
428+
name = "%{job_name}"
429+
location = "us-central1"
430+
launch_stage = "BETA"
431+
template {
432+
template {
433+
containers {
434+
image = "us-docker.pkg.dev/cloudrun/container/job"
435+
volume_mounts {
436+
name = "nfs"
437+
mount_path = "/mnt/nfs"
438+
}
439+
}
440+
volumes {
441+
name = "nfs"
442+
nfs {
443+
server = "10.0.10.10"
444+
path = "/"
445+
read_only = true
446+
}
447+
}
448+
}
449+
}
450+
}
451+
`, context)
452+
}

website/docs/r/cloud_run_v2_job.html.markdown

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -561,6 +561,11 @@ The following arguments are supported:
561561
Cloud Storage bucket mounted as a volume using GCSFuse. This feature requires the launch stage to be set to ALPHA or BETA.
562562
Structure is [documented below](#nested_gcs).
563563

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

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

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

628+
<a name="nested_nfs"></a>The `nfs` block supports:
629+
630+
* `server` -
631+
(Required)
632+
Hostname or IP address of the NFS server.
633+
634+
* `path` -
635+
(Optional)
636+
Path that is exported by the NFS server.
637+
638+
* `read_only` -
639+
(Optional)
640+
If true, mount this volume as read-only in all mounts.
641+
623642
<a name="nested_vpc_access"></a>The `vpc_access` block supports:
624643

625644
* `connector` -

0 commit comments

Comments
 (0)