Skip to content

Commit 97273e8

Browse files
feat:(storagetransfer) added federated identity config for azure storage transfer (#14427) (#23900)
[upstream:37253ecc2343ec83233e8136677f03556fc1baeb] Signed-off-by: Modular Magician <[email protected]>
1 parent 788824d commit 97273e8

File tree

4 files changed

+95
-14
lines changed

4 files changed

+95
-14
lines changed

.changelog/14427.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 `federated_identity_config` to resource `google_storage_transfer_job`
3+
```

google/services/storagetransfer/resource_storage_transfer_job.go

Lines changed: 79 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
//
99
// This code is generated by Magic Modules using the following:
1010
//
11-
// Source file: https://github.com/GoogleCloudPlatform/magic-modules/tree/main/mmv1/third_party/terraform/services/storagetransfer/resource_storage_transfer_job.go.tmpl
11+
// Source file: https://github.com/GoogleCloudPlatform/magic-modules/tree/main/mmv1/third_party/terraform/services/storagetransfer/resource_storage_transfer_job.go
1212
//
1313
// DO NOT EDIT this file directly. Any changes made to this file will be
1414
// overwritten during the next generation cycle.
@@ -115,6 +115,11 @@ var (
115115
"transfer_spec.0.aws_s3_data_source.0.aws_access_key",
116116
"transfer_spec.0.aws_s3_data_source.0.role_arn",
117117
}
118+
azureOptionCredentials = []string{
119+
"transfer_spec.0.azure_blob_storage_data_source.0.azure_credentials",
120+
"transfer_spec.0.azure_blob_storage_data_source.0.credentials_secret",
121+
"transfer_spec.0.azure_blob_storage_data_source.0.federated_identity_config",
122+
}
118123
)
119124

120125
func ResourceStorageTransferJob() *schema.Resource {
@@ -825,9 +830,10 @@ func azureBlobStorageDataSchema() *schema.Resource {
825830
Description: `Root path to transfer objects. Must be an empty string or full path name that ends with a '/'. This field is treated as an object prefix. As such, it should generally not begin with a '/'.`,
826831
},
827832
"azure_credentials": {
828-
Type: schema.TypeList,
829-
Required: true,
830-
MaxItems: 1,
833+
Type: schema.TypeList,
834+
Optional: true,
835+
ExactlyOneOf: azureOptionCredentials,
836+
MaxItems: 1,
831837
Elem: &schema.Resource{
832838
Schema: map[string]*schema.Schema{
833839
"sas_token": {
@@ -840,6 +846,35 @@ func azureBlobStorageDataSchema() *schema.Resource {
840846
},
841847
Description: ` Credentials used to authenticate API requests to Azure.`,
842848
},
849+
"credentials_secret": {
850+
Type: schema.TypeString,
851+
Optional: true,
852+
ExactlyOneOf: azureOptionCredentials,
853+
Description: `The Resource name of a secret in Secret Manager containing SAS Credentials in JSON form. Service Agent must have permissions to access secret. If credentials_secret is specified, do not specify azure_credentials.`,
854+
},
855+
"federated_identity_config": {
856+
Type: schema.TypeList,
857+
Optional: true,
858+
ExactlyOneOf: azureOptionCredentials,
859+
MaxItems: 1,
860+
Elem: &schema.Resource{
861+
Schema: map[string]*schema.Schema{
862+
"client_id": {
863+
Type: schema.TypeString,
864+
Required: true,
865+
Sensitive: true,
866+
Description: `The client (application) ID of the application with federated credentials.`,
867+
},
868+
"tenant_id": {
869+
Type: schema.TypeString,
870+
Required: true,
871+
Sensitive: true,
872+
Description: `The tenant (directory) ID of the application with federated credentials.`,
873+
},
874+
},
875+
},
876+
Description: ` Workload Identity Details used to authenticate API requests to Azure.`,
877+
},
843878
},
844879
}
845880
}
@@ -1131,6 +1166,30 @@ func resourceStorageTransferJobStateImporter(d *schema.ResourceData, meta interf
11311166
return []*schema.ResourceData{d}, nil
11321167
}
11331168

1169+
func expandAzureFederatedIdentifyConfig(federatedIdentifyConfig []interface{}) *storagetransfer.FederatedIdentityConfig {
1170+
if len(federatedIdentifyConfig) == 0 || federatedIdentifyConfig[0] == nil {
1171+
return nil
1172+
}
1173+
1174+
federatedIdentifyCfg := federatedIdentifyConfig[0].(map[string]interface{})
1175+
return &storagetransfer.FederatedIdentityConfig{
1176+
ClientId: federatedIdentifyCfg["client_id"].(string),
1177+
TenantId: federatedIdentifyCfg["tenant_id"].(string),
1178+
}
1179+
}
1180+
1181+
func flattenAzureFederatedIdentifyConfig(d *schema.ResourceData) []map[string]interface{} {
1182+
if (d.Get("transfer_spec.0.azure_blob_storage_data_source.0.federated_identity_config.0.client_id") == "") || (d.Get("transfer_spec.0.azure_blob_storage_data_source.0.federated_identity_config.0.tenant_id") == "") {
1183+
return []map[string]interface{}{}
1184+
}
1185+
1186+
data := map[string]interface{}{
1187+
"client_id": d.Get("transfer_spec.0.azure_blob_storage_data_source.0.federated_identity_config.0.client_id"),
1188+
"tenant_id": d.Get("transfer_spec.0.azure_blob_storage_data_source.0.federated_identity_config.0.tenant_id"),
1189+
}
1190+
return []map[string]interface{}{data}
1191+
}
1192+
11341193
func expandDates(dates []interface{}) *storagetransfer.Date {
11351194
if len(dates) == 0 || dates[0] == nil {
11361195
return nil
@@ -1430,6 +1489,10 @@ func expandAzureCredentials(azureCredentials []interface{}) *storagetransfer.Azu
14301489
}
14311490

14321491
func flattenAzureCredentials(d *schema.ResourceData) []map[string]interface{} {
1492+
if d.Get("transfer_spec.0.azure_blob_storage_data_source.0.azure_credentials.0.sas_token") == "" {
1493+
return []map[string]interface{}{}
1494+
}
1495+
14331496
data := map[string]interface{}{
14341497
"sas_token": d.Get("transfer_spec.0.azure_blob_storage_data_source.0.azure_credentials.0.sas_token"),
14351498
}
@@ -1445,19 +1508,23 @@ func expandAzureBlobStorageData(azureBlobStorageDatas []interface{}) *storagetra
14451508
azureBlobStorageData := azureBlobStorageDatas[0].(map[string]interface{})
14461509

14471510
return &storagetransfer.AzureBlobStorageData{
1448-
Container: azureBlobStorageData["container"].(string),
1449-
Path: azureBlobStorageData["path"].(string),
1450-
StorageAccount: azureBlobStorageData["storage_account"].(string),
1451-
AzureCredentials: expandAzureCredentials(azureBlobStorageData["azure_credentials"].([]interface{})),
1511+
Container: azureBlobStorageData["container"].(string),
1512+
Path: azureBlobStorageData["path"].(string),
1513+
StorageAccount: azureBlobStorageData["storage_account"].(string),
1514+
AzureCredentials: expandAzureCredentials(azureBlobStorageData["azure_credentials"].([]interface{})),
1515+
CredentialsSecret: azureBlobStorageData["credentials_secret"].(string),
1516+
FederatedIdentityConfig: expandAzureFederatedIdentifyConfig(azureBlobStorageData["federated_identity_config"].([]interface{})),
14521517
}
14531518
}
14541519

14551520
func flattenAzureBlobStorageData(azureBlobStorageData *storagetransfer.AzureBlobStorageData, d *schema.ResourceData) []map[string]interface{} {
14561521
data := map[string]interface{}{
1457-
"container": azureBlobStorageData.Container,
1458-
"path": azureBlobStorageData.Path,
1459-
"storage_account": azureBlobStorageData.StorageAccount,
1460-
"azure_credentials": flattenAzureCredentials(d),
1522+
"container": azureBlobStorageData.Container,
1523+
"path": azureBlobStorageData.Path,
1524+
"storage_account": azureBlobStorageData.StorageAccount,
1525+
"azure_credentials": flattenAzureCredentials(d),
1526+
"federated_identity_config": flattenAzureFederatedIdentifyConfig(d),
1527+
"credentials_secret": azureBlobStorageData.CredentialsSecret,
14611528
}
14621529

14631530
return []map[string]interface{}{data}

google/services/storagetransfer/resource_storage_transfer_job_meta.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ fields:
5151
- field: 'transfer_spec.aws_s3_data_source.role_arn'
5252
- field: 'transfer_spec.azure_blob_storage_data_source.azure_credentials.sas_token'
5353
- field: 'transfer_spec.azure_blob_storage_data_source.container'
54+
- field: 'transfer_spec.azure_blob_storage_data_source.credentials_secret'
55+
- field: 'transfer_spec.azure_blob_storage_data_source.federated_identity_config.client_id'
56+
- field: 'transfer_spec.azure_blob_storage_data_source.federated_identity_config.tenant_id'
5457
- field: 'transfer_spec.azure_blob_storage_data_source.path'
5558
- field: 'transfer_spec.azure_blob_storage_data_source.storage_account'
5659
- field: 'transfer_spec.gcs_data_sink.bucket_name'

website/docs/r/storage_transfer_job.html.markdown

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -296,14 +296,22 @@ The `aws_access_key` block supports:
296296

297297
* `path` - (Required) Root path to transfer objects. Must be an empty string or full path name that ends with a '/'. This field is treated as an object prefix. As such, it should generally not begin with a '/'.
298298

299-
* `credentials_secret` - (Optional, [Beta](https://terraform.io/docs/providers/google/guides/provider_versions.html)) Full Resource name of a secret in Secret Manager containing [SAS Credentials in JSON form](https://cloud.google.com/storage-transfer/docs/reference/rest/v1/TransferSpec#azureblobstoragedata:~:text=begin%20with%20a%20%27/%27.-,credentialsSecret,-string). Service Agent for Storage Transfer must have permissions to access secret. If credentials_secret is specified, do not specify azure_credentials.`,
299+
* `credentials_secret` - (Optional, (https://terraform.io/docs/providers/google/guides/provider_versions.html)) Full Resource name of a secret in Secret Manager containing [SAS Credentials in JSON form](https://cloud.google.com/storage-transfer/docs/reference/rest/v1/TransferSpec#azureblobstoragedata:~:text=begin%20with%20a%20%27/%27.-,credentialsSecret,-string). Service Agent for Storage Transfer must have permissions to access secret. If credentials_secret is specified, do not specify azure_credentials.`,
300300

301-
* `azure_credentials` - (Required in GA, Optional in [Beta](https://terraform.io/docs/providers/google/guides/provider_versions.html)) Credentials used to authenticate API requests to Azure block.
301+
* `azure_credentials` - (Optional, (https://terraform.io/docs/providers/google/guides/provider_versions.html)) Credentials used to authenticate API requests to Azure block.
302+
303+
* `federated_identity_config` - (Optional) Federated identity config of a user registered Azure application. Structure [documented below](#nested_federated_identity_config).
302304

303305
The `azure_credentials` block supports:
304306

305307
* `sas_token` - (Required) Azure shared access signature. See [Grant limited access to Azure Storage resources using shared access signatures (SAS)](https://docs.microsoft.com/en-us/azure/storage/common/storage-sas-overview).
306308

309+
<a name="nested_federated_identity_config"></a>The `federated_identity_config` block supports:
310+
311+
* `client_id` - (Required) The client (application) ID of the application with federated credentials.
312+
313+
* `tenant_id` - (Required) The client (directory) ID of the application with federated credentials.
314+
307315
<a name="nested_schedule_start_end_date"></a>The `schedule_start_date` and `schedule_end_date` blocks support:
308316

309317
* `year` - (Required) Year of date. Must be from 1 to 9999.

0 commit comments

Comments
 (0)