Skip to content

Commit 49660fb

Browse files
Update make transferJobs name field optional (#9641) (#16838)
* Update make transferJobs name field optional This commit makes transferJobs name optional + new test `TestAccStorageTransferJob_transferJobName` to testing changes. Fixes #15220 * Update transferJobs document of name field --------- [upstream:f86454beb4ace8575ab532a3e59597ddd4758936] Signed-off-by: Mohsen Mottaghi <[email protected]> Signed-off-by: Modular Magician <[email protected]>
1 parent f6dc844 commit 49660fb

File tree

4 files changed

+110
-0
lines changed

4 files changed

+110
-0
lines changed

.changelog/9641.txt

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:enhancement
2+
storagetransfer: made `name` field to be optional in resource `google_storage_transfer_job` so it can be provided by the users
3+
```

google/services/storagetransfer/resource_storage_transfer_job.go

+2
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ func ResourceStorageTransferJob() *schema.Resource {
7171
Schema: map[string]*schema.Schema{
7272
"name": {
7373
Type: schema.TypeString,
74+
Optional: true,
7475
Computed: true,
7576
Description: `The name of the Transfer Job.`,
7677
},
@@ -596,6 +597,7 @@ func resourceStorageTransferJobCreate(d *schema.ResourceData, meta interface{})
596597
}
597598

598599
transferJob := &storagetransfer.TransferJob{
600+
Name: d.Get("name").(string),
599601
Description: d.Get("description").(string),
600602
ProjectId: project,
601603
Status: d.Get("status").(string),

google/services/storagetransfer/resource_storage_transfer_job_test.go

+103
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,31 @@ func TestAccStorageTransferJob_basic(t *testing.T) {
8080
})
8181
}
8282

83+
func TestAccStorageTransferJob_transferJobName(t *testing.T) {
84+
t.Parallel()
85+
86+
testDataSourceBucketName := acctest.RandString(t, 10)
87+
testDataSinkName := acctest.RandString(t, 10)
88+
testTransferJobDescription := acctest.RandString(t, 10)
89+
testTransferJobName := fmt.Sprintf("tf-test-transfer-job-%s", acctest.RandString(t, 10))
90+
91+
acctest.VcrTest(t, resource.TestCase{
92+
PreCheck: func() { acctest.AccTestPreCheck(t) },
93+
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
94+
CheckDestroy: testAccStorageTransferJobDestroyProducer(t),
95+
Steps: []resource.TestStep{
96+
{
97+
Config: testAccStorageTransferJob_transferJobName(envvar.GetTestProjectFromEnv(), testDataSourceBucketName, testDataSinkName, testTransferJobDescription, testTransferJobName),
98+
},
99+
{
100+
ResourceName: "google_storage_transfer_job.transfer_job",
101+
ImportState: true,
102+
ImportStateVerify: true,
103+
},
104+
},
105+
})
106+
}
107+
83108
func TestAccStorageTransferJob_omitScheduleEndDate(t *testing.T) {
84109
t.Parallel()
85110

@@ -703,6 +728,84 @@ resource "google_storage_transfer_job" "transfer_job" {
703728
`, project, dataSourceBucketName, project, dataSinkBucketName, project, pubsubTopicName, transferJobDescription, project)
704729
}
705730

731+
func testAccStorageTransferJob_transferJobName(project string, dataSourceBucketName string, dataSinkBucketName string, transferJobDescription string, testTransferJobName string) string {
732+
return fmt.Sprintf(`
733+
data "google_storage_transfer_project_service_account" "default" {
734+
project = "%s"
735+
}
736+
737+
resource "google_storage_bucket" "data_source" {
738+
name = "%s"
739+
project = "%s"
740+
location = "US"
741+
force_destroy = true
742+
uniform_bucket_level_access = true
743+
}
744+
745+
resource "google_storage_bucket_iam_member" "data_source" {
746+
bucket = google_storage_bucket.data_source.name
747+
role = "roles/storage.admin"
748+
member = "serviceAccount:${data.google_storage_transfer_project_service_account.default.email}"
749+
}
750+
751+
resource "google_storage_bucket" "data_sink" {
752+
name = "%s"
753+
project = "%s"
754+
location = "US"
755+
force_destroy = true
756+
uniform_bucket_level_access = true
757+
}
758+
759+
resource "google_storage_bucket_iam_member" "data_sink" {
760+
bucket = google_storage_bucket.data_sink.name
761+
role = "roles/storage.admin"
762+
member = "serviceAccount:${data.google_storage_transfer_project_service_account.default.email}"
763+
}
764+
765+
resource "google_storage_transfer_job" "transfer_job" {
766+
name = "transferJobs/%s"
767+
description = "%s"
768+
project = "%s"
769+
770+
transfer_spec {
771+
gcs_data_source {
772+
bucket_name = google_storage_bucket.data_source.name
773+
path = "foo/bar/"
774+
}
775+
gcs_data_sink {
776+
bucket_name = google_storage_bucket.data_sink.name
777+
path = "foo/bar/"
778+
}
779+
}
780+
781+
schedule {
782+
schedule_start_date {
783+
year = 2018
784+
month = 10
785+
day = 1
786+
}
787+
schedule_end_date {
788+
year = 2019
789+
month = 10
790+
day = 1
791+
}
792+
start_time_of_day {
793+
hours = 0
794+
minutes = 30
795+
seconds = 0
796+
nanos = 0
797+
}
798+
repeat_interval = "604800s"
799+
}
800+
801+
depends_on = [
802+
google_storage_bucket_iam_member.data_source,
803+
google_storage_bucket_iam_member.data_sink,
804+
]
805+
}
806+
`, project, dataSourceBucketName, project, dataSinkBucketName, project, testTransferJobName, transferJobDescription, project)
807+
}
808+
706809
func testAccStorageTransferJob_omitScheduleEndDate(project string, dataSourceBucketName string, dataSinkBucketName string, transferJobDescription string) string {
707810
return fmt.Sprintf(`
708811
data "google_storage_transfer_project_service_account" "default" {

website/docs/r/storage_transfer_job.html.markdown

+2
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,8 @@ resource "google_storage_transfer_job" "s3-bucket-nightly-backup" {
112112

113113
The following arguments are supported:
114114

115+
* `name` - (Optional) The name of the Transfer Job. This name must start with "transferJobs/" prefix and end with a letter or a number, and should be no more than 128 characters ( `transferJobs/^(?!OPI)[A-Za-z0-9-._~]*[A-Za-z0-9]$` ). For transfers involving PosixFilesystem, this name must start with transferJobs/OPI specifically ( `transferJobs/OPI^[A-Za-z0-9-._~]*[A-Za-z0-9]$` ). For all other transfer types, this name must not start with transferJobs/OPI. Default the provider will assign a random unique name with `transferJobs/{{name}}` format, where `name` is a numeric value.
116+
115117
* `description` - (Required) Unique description to identify the Transfer Job.
116118

117119
* `transfer_spec` - (Required) Transfer specification. Structure [documented below](#nested_transfer_spec).

0 commit comments

Comments
 (0)