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_integration_runtime_azure_ssis support for the credential_name property #24458

Merged
merged 6 commits into from
Jan 24, 2024
Merged
Show file tree
Hide file tree
Changes from 5 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 @@ -107,6 +107,12 @@ func resourceDataFactoryIntegrationRuntimeAzureSsis() *pluginsdk.Resource {
ValidateFunc: validation.IntBetween(1, 16),
},

"credential_user_assigned_identity_name": {
Type: pluginsdk.TypeString,
Optional: true,
ValidateFunc: validation.StringIsNotEmpty,
},

"edition": {
Type: pluginsdk.TypeString,
Optional: true,
Expand Down Expand Up @@ -564,6 +570,10 @@ func resourceDataFactoryIntegrationRuntimeAzureSsisRead(d *pluginsdk.ResourceDat
return fmt.Errorf("setting `catalog_info`: %+v", err)
}

if err := d.Set("credential_user_assigned_identity_name", ssisProps.Credential.ReferenceName); err != nil {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is causing tests to panic, we probably want to nil check this

Suggested change
if err := d.Set("credential_user_assigned_identity_name", ssisProps.Credential.ReferenceName); err != nil {
credentialName := ""
if ssisProps.Credential != nil && ssisProps.Credential.ReferenceName != nil {
credentialName = *ssisProps.Credential.ReferenceName
}
if err := d.Set("credential_user_assigned_identity_name", credentialName); err != nil {

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting, I never ran into any issues locally. I'll get this fixed up and resubmitted.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@stephybun

I added a nil check similar to other nested properties and all tests were passing locally against a test subscription.

return fmt.Errorf("setting `credential_user_assigned_identity_name`: %+v", err)
}

if err := d.Set("custom_setup_script", flattenDataFactoryIntegrationRuntimeAzureSsisCustomSetupScript(ssisProps.CustomSetupScriptProperties, d)); err != nil {
return fmt.Errorf("setting `custom_setup_script`: %+v", err)
}
Expand Down Expand Up @@ -648,6 +658,13 @@ func expandDataFactoryIntegrationRuntimeAzureSsisProperties(d *pluginsdk.Resourc
PackageStores: expandDataFactoryIntegrationRuntimeAzureSsisPackageStore(d.Get("package_store").([]interface{})),
}

if credentialName := d.Get("credential_user_assigned_identity_name"); credentialName.(string) != "" {
ssisProperties.Credential = &datafactory.CredentialReference{
ReferenceName: utils.String(credentialName.(string)),
Type: utils.String("CredentialReference"),
}
}

if catalogInfos, ok := d.GetOk("catalog_info"); ok && len(catalogInfos.([]interface{})) > 0 {
catalogInfo := catalogInfos.([]interface{})[0].(map[string]interface{})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,21 @@ func TestAccDataFactoryIntegrationRuntimeManagedSsis_aadAuth(t *testing.T) {
})
}

func TestAccDataFactoryIntegrationRuntimeManagedSsis_userAssignedManagedCredentials(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_data_factory_integration_runtime_azure_ssis", "test")
r := IntegrationRuntimeManagedSsisResource{}

data.ResourceTest(t, r, []acceptance.TestStep{
{
Config: r.userAssignedManagedCredentials(data),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
},
data.ImportStep(),
})
}

func TestAccDataFactoryIntegrationRuntimeManagedSsis_expressVnetInjection(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_data_factory_integration_runtime_azure_ssis", "test")
r := IntegrationRuntimeManagedSsisResource{}
Expand Down Expand Up @@ -846,6 +861,74 @@ resource "azurerm_data_factory_integration_runtime_azure_ssis" "test" {
`, data.RandomInteger, data.Locations.Primary, data.RandomString)
}

func (IntegrationRuntimeManagedSsisResource) userAssignedManagedCredentials(data acceptance.TestData) string {
return fmt.Sprintf(`
provider "azurerm" {
features {}
}

resource "azurerm_resource_group" "test" {
name = "acctestRG-df-%d"
location = "%s"
}

resource "azurerm_user_assigned_identity" "test" {
location = azurerm_resource_group.test.location
name = "testuser%d"
resource_group_name = azurerm_resource_group.test.name
}

resource "azurerm_data_factory" "test" {
name = "acctestdfirm%d"
location = azurerm_resource_group.test.location
resource_group_name = azurerm_resource_group.test.name

identity {
type = "UserAssigned"
identity_ids = [azurerm_user_assigned_identity.test.id]
}
}

resource "azurerm_data_factory_credential_user_managed_identity" "test" {
name = "credential%d"
data_factory_id = azurerm_data_factory.test.id
identity_id = azurerm_user_assigned_identity.test.id
}

resource "azurerm_sql_server" "test" {
name = "acctestsql%d"
resource_group_name = azurerm_resource_group.test.name
location = azurerm_resource_group.test.location
version = "12.0"
administrator_login = "ssis_catalog_admin"
administrator_login_password = "my-s3cret-p4ssword!"
}

resource "azurerm_sql_active_directory_administrator" "test" {
server_name = azurerm_sql_server.test.name
resource_group_name = azurerm_resource_group.test.name
login = azurerm_data_factory.test.name
tenant_id = azurerm_user_assigned_identity.test.tenant_id
object_id = azurerm_user_assigned_identity.test.principal_id
}

resource "azurerm_data_factory_integration_runtime_azure_ssis" "test" {
name = "managed-integration-runtime-%d"
data_factory_id = azurerm_data_factory.test.id
location = azurerm_resource_group.test.location
node_size = "Standard_D8_v3"
credential_user_assigned_identity_name = azurerm_data_factory_credential_user_managed_identity.test.name

catalog_info {
server_endpoint = azurerm_sql_server.test.fully_qualified_domain_name
pricing_tier = "Basic"
}

depends_on = [azurerm_sql_active_directory_administrator.test]
}
`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger)
}

func (t IntegrationRuntimeManagedSsisResource) Exists(ctx context.Context, clients *clients.Client, state *pluginsdk.InstanceState) (*bool, error) {
id, err := parse.IntegrationRuntimeID(state.ID)
if err != nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ The following arguments are supported:

* `number_of_nodes` - (Optional) Number of nodes for the Azure-SSIS Integration Runtime. Max is `10`. Defaults to `1`.

* `credential_user_assigned_identity_name` - (Optional) The name of a Data Factory Credential associated with a User Assigned Managed Identity. See [`azurerm_data_factory_credential_user_managed_identity`](data_factory_credential_user_assigned_managed_identity.html.html)

* `max_parallel_executions_per_node` - (Optional) Defines the maximum parallel executions per node. Defaults to `1`. Max is `1`.

* `edition` - (Optional) The Azure-SSIS Integration Runtime edition. Valid values are `Standard` and `Enterprise`. Defaults to `Standard`.
Expand Down
Loading