Skip to content

Commit 740a957

Browse files
modular-magicianAnuhya P
andauthored
add support to reference cross-project agent pool in storagetransfer (#7306) (#5262)
Signed-off-by: Modular Magician <[email protected]> Co-authored-by: Anuhya P <[email protected]>
1 parent a50a71f commit 740a957

File tree

4 files changed

+59
-10
lines changed

4 files changed

+59
-10
lines changed

.changelog/7306.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:enhancement
2+
storagetransfer: added general field `sink_agent_pool_name` and `source_agent_pool_name` to `google_storage_transfer_job`
3+
```

google-beta/resource_storage_transfer_job.go

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,20 @@ func ResourceStorageTransferJob() *schema.Resource {
8282
Schema: map[string]*schema.Schema{
8383
"object_conditions": objectConditionsSchema(),
8484
"transfer_options": transferOptionsSchema(),
85+
"source_agent_pool_name": {
86+
Type: schema.TypeString,
87+
Optional: true,
88+
Computed: true,
89+
ForceNew: true,
90+
Description: `Specifies the agent pool name associated with the posix data source. When unspecified, the default name is used.`,
91+
},
92+
"sink_agent_pool_name": {
93+
Type: schema.TypeString,
94+
Optional: true,
95+
Computed: true,
96+
ForceNew: true,
97+
Description: `Specifies the agent pool name associated with the posix data source. When unspecified, the default name is used.`,
98+
},
8599
"gcs_data_sink": {
86100
Type: schema.TypeList,
87101
Optional: true,
@@ -1064,6 +1078,8 @@ func expandTransferSpecs(transferSpecs []interface{}) *storagetransfer.TransferS
10641078

10651079
transferSpec := transferSpecs[0].(map[string]interface{})
10661080
return &storagetransfer.TransferSpec{
1081+
SourceAgentPoolName: transferSpec["source_agent_pool_name"].(string),
1082+
SinkAgentPoolName: transferSpec["sink_agent_pool_name"].(string),
10671083
GcsDataSink: expandGcsData(transferSpec["gcs_data_sink"].([]interface{})),
10681084
PosixDataSink: expandPosixData(transferSpec["posix_data_sink"].([]interface{})),
10691085
ObjectConditions: expandObjectConditions(transferSpec["object_conditions"].([]interface{})),
@@ -1076,8 +1092,13 @@ func expandTransferSpecs(transferSpecs []interface{}) *storagetransfer.TransferS
10761092
}
10771093
}
10781094

1079-
func flattenTransferSpec(transferSpec *storagetransfer.TransferSpec, d *schema.ResourceData) []map[string][]map[string]interface{} {
1080-
data := map[string][]map[string]interface{}{}
1095+
func flattenTransferSpec(transferSpec *storagetransfer.TransferSpec, d *schema.ResourceData) []map[string]interface{} {
1096+
1097+
data := map[string]interface{}{}
1098+
1099+
data["sink_agent_pool_name"] = transferSpec.SinkAgentPoolName
1100+
data["source_agent_pool_name"] = transferSpec.SourceAgentPoolName
1101+
10811102
if transferSpec.GcsDataSink != nil {
10821103
data["gcs_data_sink"] = flattenGcsData(transferSpec.GcsDataSink)
10831104
}
@@ -1105,7 +1126,7 @@ func flattenTransferSpec(transferSpec *storagetransfer.TransferSpec, d *schema.R
11051126
data["posix_data_source"] = flattenPosixData(transferSpec.PosixDataSource)
11061127
}
11071128

1108-
return []map[string][]map[string]interface{}{data}
1129+
return []map[string]interface{}{data}
11091130
}
11101131

11111132
func usingPosix(transferSpec *storagetransfer.TransferSpec) bool {

google-beta/resource_storage_transfer_job_test.go

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -105,14 +105,15 @@ func TestAccStorageTransferJob_posixSource(t *testing.T) {
105105

106106
testDataSinkName := randString(t, 10)
107107
testTransferJobDescription := randString(t, 10)
108+
testSourceAgentPoolName := fmt.Sprintf("tf-test-source-agent-pool-%s", randString(t, 10))
108109

109110
vcrTest(t, resource.TestCase{
110111
PreCheck: func() { testAccPreCheck(t) },
111112
Providers: testAccProviders,
112113
CheckDestroy: testAccStorageTransferJobDestroyProducer(t),
113114
Steps: []resource.TestStep{
114115
{
115-
Config: testAccStorageTransferJob_posixSource(getTestProjectFromEnv(), testDataSinkName, testTransferJobDescription),
116+
Config: testAccStorageTransferJob_posixSource(getTestProjectFromEnv(), testDataSinkName, testTransferJobDescription, testSourceAgentPoolName),
116117
},
117118
{
118119
ResourceName: "google_storage_transfer_job.transfer_job",
@@ -122,20 +123,20 @@ func TestAccStorageTransferJob_posixSource(t *testing.T) {
122123
},
123124
})
124125
}
125-
126126
func TestAccStorageTransferJob_posixSink(t *testing.T) {
127127
t.Parallel()
128128

129129
testDataSourceName := randString(t, 10)
130130
testTransferJobDescription := randString(t, 10)
131+
testSinkAgentPoolName := fmt.Sprintf("tf-test-sink-agent-pool-%s", randString(t, 10))
131132

132133
vcrTest(t, resource.TestCase{
133134
PreCheck: func() { testAccPreCheck(t) },
134135
Providers: testAccProviders,
135136
CheckDestroy: testAccStorageTransferJobDestroyProducer(t),
136137
Steps: []resource.TestStep{
137138
{
138-
Config: testAccStorageTransferJob_posixSink(getTestProjectFromEnv(), testDataSourceName, testTransferJobDescription),
139+
Config: testAccStorageTransferJob_posixSink(getTestProjectFromEnv(), testDataSourceName, testTransferJobDescription, testSinkAgentPoolName),
139140
},
140141
{
141142
ResourceName: "google_storage_transfer_job.transfer_job",
@@ -580,7 +581,7 @@ resource "google_storage_transfer_job" "transfer_job" {
580581
`, project, dataSourceBucketName, project, dataSinkBucketName, project, transferJobDescription, project)
581582
}
582583

583-
func testAccStorageTransferJob_posixSource(project string, dataSinkBucketName string, transferJobDescription string) string {
584+
func testAccStorageTransferJob_posixSource(project string, dataSinkBucketName string, transferJobDescription string, sourceAgentPoolName string) string {
584585
return fmt.Sprintf(`
585586
data "google_storage_transfer_project_service_account" "default" {
586587
project = "%s"
@@ -605,11 +606,21 @@ resource "google_project_iam_member" "pubsub" {
605606
member = "serviceAccount:${data.google_storage_transfer_project_service_account.default.email}"
606607
}
607608
609+
resource "google_storage_transfer_agent_pool" "foo" {
610+
name = "%s"
611+
bandwidth_limit {
612+
limit_mbps = "120"
613+
}
614+
615+
depends_on = [google_project_iam_member.pubsub]
616+
}
617+
608618
resource "google_storage_transfer_job" "transfer_job" {
609619
description = "%s"
610620
project = "%s"
611621
612622
transfer_spec {
623+
source_agent_pool_name = google_storage_transfer_agent_pool.foo.id
613624
posix_data_source {
614625
root_directory = "/some/path"
615626
}
@@ -643,10 +654,10 @@ resource "google_storage_transfer_job" "transfer_job" {
643654
google_project_iam_member.pubsub
644655
]
645656
}
646-
`, project, dataSinkBucketName, project, transferJobDescription, project)
657+
`, project, dataSinkBucketName, project, transferJobDescription, sourceAgentPoolName, project)
647658
}
648659

649-
func testAccStorageTransferJob_posixSink(project string, dataSourceBucketName string, transferJobDescription string) string {
660+
func testAccStorageTransferJob_posixSink(project string, dataSourceBucketName string, transferJobDescription string, sinkAgentPoolName string) string {
650661
return fmt.Sprintf(`
651662
data "google_storage_transfer_project_service_account" "default" {
652663
project = "%s"
@@ -671,11 +682,21 @@ resource "google_project_iam_member" "pubsub" {
671682
member = "serviceAccount:${data.google_storage_transfer_project_service_account.default.email}"
672683
}
673684
685+
resource "google_storage_transfer_agent_pool" "foo" {
686+
name = "%s"
687+
bandwidth_limit {
688+
limit_mbps = "120"
689+
}
690+
691+
depends_on = [google_project_iam_member.pubsub]
692+
}
693+
674694
resource "google_storage_transfer_job" "transfer_job" {
675695
description = "%s"
676696
project = "%s"
677697
678698
transfer_spec {
699+
sink_agent_pool_name = google_storage_transfer_agent_pool.foo.id
679700
posix_data_sink {
680701
root_directory = "/some/path"
681702
}
@@ -708,7 +729,7 @@ resource "google_storage_transfer_job" "transfer_job" {
708729
google_project_iam_member.pubsub
709730
]
710731
}
711-
`, project, dataSourceBucketName, project, transferJobDescription, project)
732+
`, project, dataSourceBucketName, project, sinkAgentPoolName, transferJobDescription, project)
712733
}
713734

714735
func testAccStorageTransferJob_transferOptions(project string, dataSourceBucketName string, dataSinkBucketName string, transferJobDescription string, overwriteObjectsAlreadyExistingInSink bool, deleteObjectsUniqueInSink bool, deleteObjectsFromSourceAfterTransfer bool, overwriteWhenVal string, pubSubTopicName string) string {

website/docs/r/storage_transfer_job.html.markdown

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,10 @@ The following arguments are supported:
129129

130130
<a name="nested_transfer_spec"></a>The `transfer_spec` block supports:
131131

132+
* `source_agent_pool_name` - (Optional) Specifies the agent pool name associated with the posix data source. When unspecified, the default name is used.
133+
134+
* `sink_agent_pool_name` - (Optional) Specifies the agent pool name associated with the posix data sink. When unspecified, the default name is used.
135+
132136
* `gcs_data_sink` - (Optional) A Google Cloud Storage data sink. Structure [documented below](#nested_gcs_data_sink).
133137

134138
* `posix_data_sink` - (Optional) A POSIX data sink. Structure [documented below](#nested_posix_data_sink).

0 commit comments

Comments
 (0)