Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

azurerm_data_factory_linked_service_azure_file_storage: Add support for key_vault_password #11436

Merged
merged 1 commit into from
Apr 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,27 @@ func resourceDataFactoryLinkedServiceAzureFileStorage() *schema.Resource {
ValidateFunc: validation.StringIsNotEmpty,
},

"key_vault_password": {
Type: schema.TypeList,
Optional: true,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"linked_service_name": {
Type: schema.TypeString,
Required: true,
ValidateFunc: validation.StringIsNotEmpty,
},

"secret_name": {
Type: schema.TypeString,
Required: true,
ValidateFunc: validation.StringIsNotEmpty,
},
},
},
},

"parameters": {
Type: schema.TypeMap,
Optional: true,
Expand Down Expand Up @@ -177,6 +198,11 @@ func resourceDataFactoryLinkedServiceAzureFileStorageCreateUpdate(d *schema.Reso
fileStorageLinkedService.ConnectVia = expandDataFactoryLinkedServiceIntegrationRuntime(v.(string))
}

if v, ok := d.GetOk("key_vault_password"); ok {
password := v.([]interface{})
fileStorageProperties.Password = expandAzureKeyVaultPassword(password)
}

if v, ok := d.GetOk("additional_properties"); ok {
fileStorageLinkedService.AdditionalProperties = v.(map[string]interface{})
}
Expand Down Expand Up @@ -243,6 +269,14 @@ func resourceDataFactoryLinkedServiceAzureFileStorageRead(d *schema.ResourceData
d.Set("additional_properties", fileStorage.AdditionalProperties)
d.Set("description", fileStorage.Description)

if password := fileStorage.Password; password != nil {
if keyVaultPassword, ok := password.AsAzureKeyVaultSecretReference(); ok {
if err := d.Set("key_vault_password", flattenAzureKeyVaultPassword(keyVaultPassword)); err != nil {
return fmt.Errorf("setting `key_vault_password`: %+v", err)
}
}
}

annotations := flattenDataFactoryAnnotations(fileStorage.Annotations)
if err := d.Set("annotations", annotations); err != nil {
return fmt.Errorf("Error setting `annotations` for Data Factory Linked Service Azure File Storage %q (Data Factory %q) / Resource Group %q): %+v", name, dataFactoryName, resourceGroup, err)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,24 @@ func TestAccDataFactoryLinkedServiceAzureFileStorage_file_share_name(t *testing.
})
}

func TestAccDataFactoryLinkedServiceAzureFileStorage_KeyVaultReference(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_data_factory_linked_service_azure_file_storage", "test")
r := LinkedServiceAzureFileStorageResource{}

data.ResourceTest(t, r, []resource.TestStep{
{
Config: r.key_vault_reference(data),
Check: resource.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
check.That(data.ResourceName).Key("connection_string").Exists(),
check.That(data.ResourceName).Key("key_vault_password.0.linked_service_name").HasValue("linkkv"),
check.That(data.ResourceName).Key("key_vault_password.0.secret_name").HasValue("secret"),
),
},
data.ImportStep("connection_string"),
})
}

func (t LinkedServiceAzureFileStorageResource) Exists(ctx context.Context, clients *clients.Client, state *terraform.InstanceState) (*bool, error) {
id, err := azure.ParseAzureResourceID(state.ID)
if err != nil {
Expand Down Expand Up @@ -223,3 +241,45 @@ resource "azurerm_data_factory_linked_service_azure_file_storage" "test" {
}
`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger)
}

func (LinkedServiceAzureFileStorageResource) key_vault_reference(data acceptance.TestData) string {
return fmt.Sprintf(`
provider "azurerm" {
features {}
}
data "azurerm_client_config" "current" {}
resource "azurerm_resource_group" "test" {
name = "acctestRG-df-%d"
location = "%s"
}
resource "azurerm_key_vault" "test" {
name = "acctkv%d"
location = azurerm_resource_group.test.location
resource_group_name = azurerm_resource_group.test.name
tenant_id = data.azurerm_client_config.current.tenant_id
sku_name = "standard"
}
resource "azurerm_data_factory" "test" {
name = "acctestdf%d"
location = azurerm_resource_group.test.location
resource_group_name = azurerm_resource_group.test.name
}
resource "azurerm_data_factory_linked_service_key_vault" "test" {
name = "linkkv"
resource_group_name = azurerm_resource_group.test.name
data_factory_name = azurerm_data_factory.test.name
key_vault_id = azurerm_key_vault.test.id
}
resource "azurerm_data_factory_linked_service_azure_file_storage" "test" {
name = "acctestlsblob%d"
resource_group_name = azurerm_resource_group.test.name
data_factory_name = azurerm_data_factory.test.name
connection_string = "DefaultEndpointsProtocol=https;AccountName=foo;AccountKey=bar"
file_share = "myshare"
key_vault_password {
linked_service_name = azurerm_data_factory_linked_service_key_vault.test.name
secret_name = "secret"
}
}
`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger)
}
2 changes: 1 addition & 1 deletion website/docs/d/postgresql_flexible_server.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,4 @@ In addition to the Arguments listed above - the following Attributes are exporte

The `timeouts` block allows you to specify [timeouts](https://www.terraform.io/docs/configuration/resources.html#timeouts) for certain actions:

* `read` - (Defaults to 5 minutes) Used when retrieving the PostgreSQL Flexible Server.
* `read` - (Defaults to 5 minutes) Used when retrieving the PostgreSQL Flexible Server.
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,18 @@ The following supported arguments are specific to Azure File Storage Linked Serv

* `file_share` - (Optional) The name of the file share.

* `key_vault_password` - (Optional) A `key_vault_password` block as defined below. Use this argument to store Azure File Storage password in an existing Key Vault. It needs an existing Key Vault Data Factory Linked Service.

---

A `key_vault_password` block supports the following:

* `linked_service_name` - (Required) Specifies the name of an existing Key Vault Data Factory Linked Service.

* `secret_name` - (Required) Specifies the secret name in Azure Key Vault that stores Azure File Storage password.

---

## Attributes Reference

The following attributes are exported:
Expand Down