Skip to content

Commit

Permalink
"azurerm_data_factory_integration_runtime_azure" - supports property …
Browse files Browse the repository at this point in the history
…"virtual_network_enabled" (hashicorp#12619)
  • Loading branch information
njuCZ authored and yupwei68 committed Jul 26, 2021
1 parent b919908 commit d77772d
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,19 @@ func resourceDataFactoryIntegrationRuntimeAzure() *pluginsdk.Resource {
Optional: true,
Default: 0,
},

"virtual_network_enabled": {
Type: pluginsdk.TypeBool,
Optional: true,
ForceNew: true,
},
},
}
}

func resourceDataFactoryIntegrationRuntimeAzureCreateUpdate(d *pluginsdk.ResourceData, meta interface{}) error {
client := meta.(*clients.Client).DataFactory.IntegrationRuntimesClient
managedVirtualNetworksClient := meta.(*clients.Client).DataFactory.ManagedVirtualNetworksClient
ctx, cancel := timeouts.ForCreateUpdate(meta.(*clients.Client).StopContext, d)
defer cancel()

Expand Down Expand Up @@ -121,6 +128,20 @@ func resourceDataFactoryIntegrationRuntimeAzureCreateUpdate(d *pluginsdk.Resourc
},
}

if d.Get("virtual_network_enabled").(bool) {
virtualNetworkName, err := getManagedVirtualNetworkName(ctx, managedVirtualNetworksClient, resourceGroup, factoryName)
if err != nil {
return err
}
if virtualNetworkName == nil {
return fmt.Errorf("virtual network feature for azure integration runtime is only available after managed virtual network for this data factory is enabled")
}
managedIntegrationRuntime.ManagedVirtualNetwork = &datafactory.ManagedVirtualNetworkReference{
Type: utils.String("ManagedVirtualNetworkReference"),
ReferenceName: virtualNetworkName,
}
}

basicIntegrationRuntime, _ := managedIntegrationRuntime.AsBasicIntegrationRuntime()

integrationRuntime := datafactory.IntegrationRuntimeResource{
Expand Down Expand Up @@ -183,6 +204,12 @@ func resourceDataFactoryIntegrationRuntimeAzureRead(d *pluginsdk.ResourceData, m
d.Set("description", managedIntegrationRuntime.Description)
}

virtualNetworkEnabled := false
if managedIntegrationRuntime.ManagedVirtualNetwork != nil && managedIntegrationRuntime.ManagedVirtualNetwork.ReferenceName != nil {
virtualNetworkEnabled = true
}
d.Set("virtual_network_enabled", virtualNetworkEnabled)

if computeProps := managedIntegrationRuntime.ComputeProperties; computeProps != nil {
if location := computeProps.Location; location != nil {
d.Set("location", location)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,21 @@ func TestAccDataFactoryIntegrationRuntimeAzure_timeToLive(t *testing.T) {
})
}

func TestAccDataFactoryIntegrationRuntimeAzure_virtualNetwork(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_data_factory_integration_runtime_azure", "test")
r := IntegrationRuntimeAzureResource{}

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

func (IntegrationRuntimeAzureResource) basic(data acceptance.TestData) string {
return fmt.Sprintf(`
provider "azurerm" {
Expand Down Expand Up @@ -189,6 +204,34 @@ resource "azurerm_data_factory_integration_runtime_azure" "test" {
`, data.RandomInteger, data.Locations.Primary, data.RandomInteger)
}

func (IntegrationRuntimeAzureResource) virtualNetwork(data acceptance.TestData) string {
return fmt.Sprintf(`
provider "azurerm" {
features {}
}
resource "azurerm_resource_group" "test" {
name = "acctestRG-df-%d"
location = "%s"
}
resource "azurerm_data_factory" "test" {
name = "acctestdf%d"
location = azurerm_resource_group.test.location
resource_group_name = azurerm_resource_group.test.name
managed_virtual_network_enabled = true
}
resource "azurerm_data_factory_integration_runtime_azure" "test" {
name = "azure-integration-runtime"
data_factory_name = azurerm_data_factory.test.name
resource_group_name = azurerm_resource_group.test.name
location = azurerm_resource_group.test.location
virtual_network_enabled = true
}
`, data.RandomInteger, data.Locations.Primary, data.RandomInteger)
}

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

* `time_to_live_min` - (Optional) Time to live (in minutes) setting of the cluster which will execute data flow job. Defaults to `0`.

* `virtual_network_enabled` - (Optional) Is Integration Runtime compute provisioned within Managed Virtual Network? Changing this forces a new resource to be created.

---

## Import
Expand Down

0 comments on commit d77772d

Please sign in to comment.