Skip to content

Commit

Permalink
feat: add version guard for credentials_secret as in preview
Browse files Browse the repository at this point in the history
  • Loading branch information
kumailkermalli-datatonic committed Oct 16, 2023
1 parent db4af1a commit b4efb58
Showing 1 changed file with 17 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<% autogen_exception -%>
package storagetransfer

import (
Expand Down Expand Up @@ -50,10 +51,12 @@ var (
"transfer_spec.0.aws_s3_data_source.0.aws_access_key",
"transfer_spec.0.aws_s3_data_source.0.role_arn",
}
<% unless version == 'ga' -%>
azureOptionCredentials = []string{
"transfer_spec.0.azure_blob_storage_data_source.0.azure_credentials",
"transfer_spec.0.azure_blob_storage_data_source.0.credentials_secret",
}
<% end -%>
)

func ResourceStorageTransferJob() *schema.Resource {
Expand Down Expand Up @@ -563,9 +566,13 @@ func azureBlobStorageDataSchema() *schema.Resource {
},
"azure_credentials": {
Type: schema.TypeList,
<% unless version == 'ga' -%>
Optional: true,
MaxItems: 1,
ExactlyOneOf: azureOptionCredentials,
<% else -%>
Required: true,
<% end -%>
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"sas_token": {
Expand All @@ -578,12 +585,14 @@ func azureBlobStorageDataSchema() *schema.Resource {
},
Description: ` Credentials used to authenticate API requests to Azure.`,
},
<% unless version == 'ga' -%>
"credentials_secret": {
Optional: true,
Type: schema.TypeString,
Description: `Optional. The Resource name of a secret in Secret Manager.`,
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.`,
ExactlyOneOf: azureOptionCredentials,
},
<% end -%>
},
}
}
Expand Down Expand Up @@ -1108,9 +1117,11 @@ func expandAzureCredentials(azureCredentials []interface{}) *storagetransfer.Azu
}

func flattenAzureCredentials(d *schema.ResourceData) []map[string]interface{} {
<% unless version == 'ga' -%>
if d.Get("transfer_spec.0.azure_blob_storage_data_source.0.azure_credentials.0.sas_token") == "" {
return []map[string]interface{}{}
}
<% end -%>
data := map[string]interface{}{
"sas_token": d.Get("transfer_spec.0.azure_blob_storage_data_source.0.azure_credentials.0.sas_token"),
}
Expand All @@ -1130,7 +1141,9 @@ func expandAzureBlobStorageData(azureBlobStorageDatas []interface{}) *storagetra
Path: azureBlobStorageData["path"].(string),
StorageAccount: azureBlobStorageData["storage_account"].(string),
AzureCredentials: expandAzureCredentials(azureBlobStorageData["azure_credentials"].([]interface{})),
<% unless version == 'ga' -%>
CredentialsSecret: azureBlobStorageData["credentials_secret"].(string),
<% end -%>
}
}

Expand All @@ -1140,7 +1153,9 @@ func flattenAzureBlobStorageData(azureBlobStorageData *storagetransfer.AzureBlob
"path": azureBlobStorageData.Path,
"storage_account": azureBlobStorageData.StorageAccount,
"azure_credentials": flattenAzureCredentials(d),
<% unless version == 'ga' -%>
"credentials_secret": azureBlobStorageData.CredentialsSecret,
<% end -%>
}

return []map[string]interface{}{data}
Expand Down

0 comments on commit b4efb58

Please sign in to comment.