From 09ba9fb9ac5d51d829221e90efbd9825f187387c Mon Sep 17 00:00:00 2001 From: rob Date: Thu, 17 Oct 2019 11:20:56 +0200 Subject: [PATCH] New Resource: data_factory_integration_runtime_managed (#4342) --- .../internal/services/datafactory/client.go | 21 +- azurerm/provider.go | 1 + ...ata_factory_integration_runtime_managed.go | 453 ++++++++++++++++++ ...actory_integration_runtime_managed_test.go | 360 ++++++++++++++ go.sum | 3 - website/azurerm.erb | 4 + ..._integration_runtime_managed.html.markdown | 107 +++++ 7 files changed, 938 insertions(+), 11 deletions(-) create mode 100644 azurerm/resource_arm_data_factory_integration_runtime_managed.go create mode 100644 azurerm/resource_arm_data_factory_integration_runtime_managed_test.go create mode 100644 website/docs/r/data_factory_integration_runtime_managed.html.markdown diff --git a/azurerm/internal/services/datafactory/client.go b/azurerm/internal/services/datafactory/client.go index d741e279f32c..7d0175c18413 100644 --- a/azurerm/internal/services/datafactory/client.go +++ b/azurerm/internal/services/datafactory/client.go @@ -6,10 +6,11 @@ import ( ) type Client struct { - DatasetClient *datafactory.DatasetsClient - FactoriesClient *datafactory.FactoriesClient - LinkedServiceClient *datafactory.LinkedServicesClient - PipelinesClient *datafactory.PipelinesClient + DatasetClient *datafactory.DatasetsClient + FactoriesClient *datafactory.FactoriesClient + IntegrationRuntimesClient *datafactory.IntegrationRuntimesClient + LinkedServiceClient *datafactory.LinkedServicesClient + PipelinesClient *datafactory.PipelinesClient } func BuildClient(o *common.ClientOptions) *Client { @@ -19,6 +20,9 @@ func BuildClient(o *common.ClientOptions) *Client { FactoriesClient := datafactory.NewFactoriesClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId) o.ConfigureClient(&FactoriesClient.Client, o.ResourceManagerAuthorizer) + IntegrationRuntimesClient := datafactory.NewIntegrationRuntimesClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId) + o.ConfigureClient(&IntegrationRuntimesClient.Client, o.ResourceManagerAuthorizer) + LinkedServiceClient := datafactory.NewLinkedServicesClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId) o.ConfigureClient(&LinkedServiceClient.Client, o.ResourceManagerAuthorizer) @@ -26,9 +30,10 @@ func BuildClient(o *common.ClientOptions) *Client { o.ConfigureClient(&PipelinesClient.Client, o.ResourceManagerAuthorizer) return &Client{ - DatasetClient: &DatasetClient, - FactoriesClient: &FactoriesClient, - LinkedServiceClient: &LinkedServiceClient, - PipelinesClient: &PipelinesClient, + DatasetClient: &DatasetClient, + FactoriesClient: &FactoriesClient, + IntegrationRuntimesClient: &IntegrationRuntimesClient, + LinkedServiceClient: &LinkedServiceClient, + PipelinesClient: &PipelinesClient, } } diff --git a/azurerm/provider.go b/azurerm/provider.go index 47ec0798aad5..28e479df5808 100644 --- a/azurerm/provider.go +++ b/azurerm/provider.go @@ -230,6 +230,7 @@ func Provider() terraform.ResourceProvider { "azurerm_data_factory_dataset_mysql": resourceArmDataFactoryDatasetMySQL(), "azurerm_data_factory_dataset_postgresql": resourceArmDataFactoryDatasetPostgreSQL(), "azurerm_data_factory_dataset_sql_server_table": resourceArmDataFactoryDatasetSQLServerTable(), + "azurerm_data_factory_integration_runtime_managed": resourceArmDataFactoryIntegrationRuntimeManaged(), "azurerm_data_factory_linked_service_data_lake_storage_gen2": resourceArmDataFactoryLinkedServiceDataLakeStorageGen2(), "azurerm_data_factory_linked_service_mysql": resourceArmDataFactoryLinkedServiceMySQL(), "azurerm_data_factory_linked_service_postgresql": resourceArmDataFactoryLinkedServicePostgreSQL(), diff --git a/azurerm/resource_arm_data_factory_integration_runtime_managed.go b/azurerm/resource_arm_data_factory_integration_runtime_managed.go new file mode 100644 index 000000000000..84e4b034f4bc --- /dev/null +++ b/azurerm/resource_arm_data_factory_integration_runtime_managed.go @@ -0,0 +1,453 @@ +package azurerm + +import ( + "fmt" + "regexp" + + "github.com/Azure/azure-sdk-for-go/services/datafactory/mgmt/2018-06-01/datafactory" + "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/helper/validation" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/validate" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" +) + +func resourceArmDataFactoryIntegrationRuntimeManaged() *schema.Resource { + return &schema.Resource{ + Create: resourceArmDataFactoryIntegrationRuntimeManagedCreateUpdate, + Read: resourceArmDataFactoryIntegrationRuntimeManagedRead, + Update: resourceArmDataFactoryIntegrationRuntimeManagedCreateUpdate, + Delete: resourceArmDataFactoryIntegrationRuntimeManagedDelete, + + Importer: &schema.ResourceImporter{ + State: schema.ImportStatePassthrough, + }, + + Schema: map[string]*schema.Schema{ + "name": { + Type: schema.TypeString, + Required: true, + ForceNew: true, + ValidateFunc: validation.StringMatch( + regexp.MustCompile(`^([a-zA-Z0-9](-|-?[a-zA-Z0-9]+)+[a-zA-Z0-9])$`), + `Invalid name for Managed Integration Runtime: minimum 3 characters, must start and end with a number or a letter, may only consist of letters, numbers and dashes and no consecutive dashes.`, + ), + }, + + "description": { + Type: schema.TypeString, + Optional: true, + }, + + "data_factory_name": { + Type: schema.TypeString, + Required: true, + ForceNew: true, + ValidateFunc: validation.StringMatch( + regexp.MustCompile(`^[A-Za-z0-9]+(?:-[A-Za-z0-9]+)*$`), + `Invalid name for Data Factory, see https://docs.microsoft.com/en-us/azure/data-factory/naming-rules`, + ), + }, + + "resource_group_name": azure.SchemaResourceGroupName(), + + "location": azure.SchemaLocation(), + + "node_size": { + Type: schema.TypeString, + Required: true, + ValidateFunc: validation.StringInSlice([]string{ + "Standard_D2_v3", + "Standard_D4_v3", + "Standard_D8_v3", + "Standard_D16_v3", + "Standard_D32_v3", + "Standard_D64_v3", + "Standard_E2_v3", + "Standard_E4_v3", + "Standard_E8_v3", + "Standard_E16_v3", + "Standard_E32_v3", + "Standard_E64_v3", + "Standard_D1_v2", + "Standard_D2_v2", + "Standard_D3_v2", + "Standard_D4_v2", + "Standard_A4_v2", + "Standard_A8_v2", + }, false), + }, + + "number_of_nodes": { + Type: schema.TypeInt, + Optional: true, + Default: 1, + ValidateFunc: validation.IntBetween(1, 10), + }, + + "max_parallel_executions_per_node": { + Type: schema.TypeInt, + Optional: true, + Default: 1, + ValidateFunc: validation.IntBetween(1, 16), + }, + + "edition": { + Type: schema.TypeString, + Optional: true, + Default: string(datafactory.Standard), + ValidateFunc: validation.StringInSlice([]string{ + string(datafactory.Standard), + string(datafactory.Enterprise), + }, false), + }, + + "license_type": { + Type: schema.TypeString, + Optional: true, + Default: string(datafactory.LicenseIncluded), + ValidateFunc: validation.StringInSlice([]string{ + string(datafactory.LicenseIncluded), + string(datafactory.BasePrice), + }, false), + }, + + "vnet_integration": { + Type: schema.TypeList, + Optional: true, + MaxItems: 1, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "vnet_id": { + Type: schema.TypeString, + Required: true, + ValidateFunc: azure.ValidateResourceID, + }, + "subnet_name": { + Type: schema.TypeString, + Required: true, + ValidateFunc: validate.NoEmptyStrings, + }, + }, + }, + }, + + "custom_setup_script": { + Type: schema.TypeList, + Optional: true, + MaxItems: 1, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "blob_container_uri": { + Type: schema.TypeString, + Required: true, + ValidateFunc: validate.NoEmptyStrings, + }, + "sas_token": { + Type: schema.TypeString, + Required: true, + Sensitive: true, + ValidateFunc: validate.NoEmptyStrings, + }, + }, + }, + }, + + "catalog_info": { + Type: schema.TypeList, + Optional: true, + MaxItems: 1, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "server_endpoint": { + Type: schema.TypeString, + Required: true, + ValidateFunc: validate.NoEmptyStrings, + }, + "administrator_login": { + Type: schema.TypeString, + Required: true, + ValidateFunc: validate.NoEmptyStrings, + }, + "administrator_password": { + Type: schema.TypeString, + Required: true, + Sensitive: true, + ValidateFunc: validate.NoEmptyStrings, + }, + "pricing_tier": { + Type: schema.TypeString, + Optional: true, + Default: string(datafactory.IntegrationRuntimeSsisCatalogPricingTierBasic), + ValidateFunc: validation.StringInSlice([]string{ + string(datafactory.IntegrationRuntimeSsisCatalogPricingTierBasic), + string(datafactory.IntegrationRuntimeSsisCatalogPricingTierStandard), + string(datafactory.IntegrationRuntimeSsisCatalogPricingTierPremium), + string(datafactory.IntegrationRuntimeSsisCatalogPricingTierPremiumRS), + }, false), + }, + }, + }, + }, + }, + } +} + +func resourceArmDataFactoryIntegrationRuntimeManagedCreateUpdate(d *schema.ResourceData, meta interface{}) error { + client := meta.(*ArmClient).DataFactory.IntegrationRuntimesClient + ctx := meta.(*ArmClient).StopContext + + name := d.Get("name").(string) + factoryName := d.Get("data_factory_name").(string) + resourceGroup := d.Get("resource_group_name").(string) + + if features.ShouldResourcesBeImported() && d.IsNewResource() { + existing, err := client.Get(ctx, resourceGroup, factoryName, name, "") + if err != nil { + if !utils.ResponseWasNotFound(existing.Response) { + return fmt.Errorf("Error checking for presence of existing Data Factory Managed Integration Runtime %q (Resource Group %q, Data Factory %q): %s", name, resourceGroup, factoryName, err) + } + } + + if existing.ID != nil && *existing.ID != "" { + return tf.ImportAsExistsError("azurerm_data_factory_integration_runtime_managed", *existing.ID) + } + } + + description := d.Get("description").(string) + managedIntegrationRuntime := datafactory.ManagedIntegrationRuntime{ + Description: &description, + Type: datafactory.TypeManaged, + ManagedIntegrationRuntimeTypeProperties: &datafactory.ManagedIntegrationRuntimeTypeProperties{ + ComputeProperties: expandArmDataFactoryIntegrationRuntimeManagedComputeProperties(d), + SsisProperties: expandArmDataFactoryIntegrationRuntimeManagedSsisProperties(d), + }, + } + + basicIntegrationRuntime, _ := managedIntegrationRuntime.AsBasicIntegrationRuntime() + + integrationRuntime := datafactory.IntegrationRuntimeResource{ + Name: &name, + Properties: basicIntegrationRuntime, + } + + if _, err := client.CreateOrUpdate(ctx, resourceGroup, factoryName, name, integrationRuntime, ""); err != nil { + return fmt.Errorf("Error creating/updating Data Factory Managed Integration Runtime %q (Resource Group %q, Data Factory %q): %+v", name, resourceGroup, factoryName, err) + } + + resp, err := client.Get(ctx, resourceGroup, factoryName, name, "") + if err != nil { + return fmt.Errorf("Error retrieving Data Factory Managed Integration Runtime %q (Resource Group %q, Data Factory %q): %+v", name, resourceGroup, factoryName, err) + } + + if resp.ID == nil { + return fmt.Errorf("Cannot read Data Factory Managed Integration Runtime %q (Resource Group %q, Data Factory %q) ID", name, resourceGroup, factoryName) + } + + d.SetId(*resp.ID) + + return resourceArmDataFactoryIntegrationRuntimeManagedRead(d, meta) +} + +func resourceArmDataFactoryIntegrationRuntimeManagedRead(d *schema.ResourceData, meta interface{}) error { + client := meta.(*ArmClient).DataFactory.IntegrationRuntimesClient + ctx := meta.(*ArmClient).StopContext + + id, err := azure.ParseAzureResourceID(d.Id()) + if err != nil { + return err + } + resourceGroup := id.ResourceGroup + factoryName := id.Path["factories"] + name := id.Path["integrationruntimes"] + + resp, err := client.Get(ctx, resourceGroup, factoryName, name, "") + if err != nil { + if utils.ResponseWasNotFound(resp.Response) { + d.SetId("") + return nil + } + + return fmt.Errorf("Error retrieving Data Factory Managed Integration Runtime %q (Resource Group %q, Data Factory %q): %+v", name, resourceGroup, factoryName, err) + } + + d.Set("name", name) + d.Set("data_factory_name", factoryName) + d.Set("resource_group_name", resourceGroup) + + managedIntegrationRuntime, convertSuccess := resp.Properties.AsManagedIntegrationRuntime() + if !convertSuccess { + return fmt.Errorf("Error converting integration runtime to managed managed integration runtime %q (Resource Group %q, Data Factory %q)", name, resourceGroup, factoryName) + } + + if managedIntegrationRuntime.Description != nil { + d.Set("description", managedIntegrationRuntime.Description) + } + + if computeProps := managedIntegrationRuntime.ComputeProperties; computeProps != nil { + if location := computeProps.Location; location != nil { + d.Set("location", location) + } + + if nodeSize := computeProps.NodeSize; nodeSize != nil { + d.Set("node_size", nodeSize) + } + + if numberOfNodes := computeProps.NumberOfNodes; numberOfNodes != nil { + d.Set("number_of_nodes", numberOfNodes) + } + + if maxParallelExecutionsPerNode := computeProps.MaxParallelExecutionsPerNode; maxParallelExecutionsPerNode != nil { + d.Set("max_parallel_executions_per_node", maxParallelExecutionsPerNode) + } + + if err := d.Set("vnet_integration", flattenArmDataFactoryIntegrationRuntimeManagedVnetIntegration(computeProps.VNetProperties)); err != nil { + return fmt.Errorf("Error setting `vnet_integration`: %+v", err) + } + } + + if ssisProps := managedIntegrationRuntime.SsisProperties; ssisProps != nil { + d.Set("edition", string(ssisProps.Edition)) + d.Set("license_type", string(ssisProps.LicenseType)) + + if err := d.Set("catalog_info", flattenArmDataFactoryIntegrationRuntimeManagedSsisCatalogInfo(ssisProps.CatalogInfo, d)); err != nil { + return fmt.Errorf("Error setting `vnet_integration`: %+v", err) + } + + if err := d.Set("custom_setup_script", flattenArmDataFactoryIntegrationRuntimeManagedSsisCustomSetupScript(ssisProps.CustomSetupScriptProperties, d)); err != nil { + return fmt.Errorf("Error setting `vnet_integration`: %+v", err) + } + } + + return nil +} + +func resourceArmDataFactoryIntegrationRuntimeManagedDelete(d *schema.ResourceData, meta interface{}) error { + client := meta.(*ArmClient).DataFactory.IntegrationRuntimesClient + ctx := meta.(*ArmClient).StopContext + + id, err := azure.ParseAzureResourceID(d.Id()) + if err != nil { + return err + } + resourceGroup := id.ResourceGroup + factoryName := id.Path["factories"] + name := id.Path["integrationruntimes"] + + response, err := client.Delete(ctx, resourceGroup, factoryName, name) + if err != nil { + if !utils.ResponseWasNotFound(response) { + return fmt.Errorf("Error deleting Data Factory Managed Integration Runtime %q (Resource Group %q, Data Factory %q): %+v", name, resourceGroup, factoryName, err) + } + } + + return nil +} + +func expandArmDataFactoryIntegrationRuntimeManagedComputeProperties(d *schema.ResourceData) *datafactory.IntegrationRuntimeComputeProperties { + location := azure.NormalizeLocation(d.Get("location").(string)) + computeProperties := datafactory.IntegrationRuntimeComputeProperties{ + Location: &location, + NodeSize: utils.String(d.Get("node_size").(string)), + NumberOfNodes: utils.Int32(int32(d.Get("number_of_nodes").(int))), + MaxParallelExecutionsPerNode: utils.Int32(int32(d.Get("max_parallel_executions_per_node").(int))), + } + + if vnetIntegrations, ok := d.GetOk("vnet_integration"); ok && len(vnetIntegrations.([]interface{})) > 0 { + vnetProps := vnetIntegrations.([]interface{})[0].(map[string]interface{}) + computeProperties.VNetProperties = &datafactory.IntegrationRuntimeVNetProperties{ + VNetID: utils.String(vnetProps["vnet_id"].(string)), + Subnet: utils.String(vnetProps["subnet_name"].(string)), + } + } + + return &computeProperties +} + +func expandArmDataFactoryIntegrationRuntimeManagedSsisProperties(d *schema.ResourceData) *datafactory.IntegrationRuntimeSsisProperties { + ssisProperties := &datafactory.IntegrationRuntimeSsisProperties{ + Edition: datafactory.IntegrationRuntimeEdition(d.Get("edition").(string)), + LicenseType: datafactory.IntegrationRuntimeLicenseType(d.Get("license_type").(string)), + } + + if catalogInfos, ok := d.GetOk("catalog_info"); ok && len(catalogInfos.([]interface{})) > 0 { + catalogInfo := catalogInfos.([]interface{})[0].(map[string]interface{}) + + adminPassword := &datafactory.SecureString{ + Value: utils.String(catalogInfo["administrator_password"].(string)), + Type: datafactory.TypeSecureString, + } + + ssisProperties.CatalogInfo = &datafactory.IntegrationRuntimeSsisCatalogInfo{ + CatalogServerEndpoint: utils.String(catalogInfo["server_endpoint"].(string)), + CatalogAdminUserName: utils.String(catalogInfo["administrator_login"].(string)), + CatalogAdminPassword: adminPassword, + CatalogPricingTier: datafactory.IntegrationRuntimeSsisCatalogPricingTier(catalogInfo["pricing_tier"].(string)), + } + } + + if customSetupScripts, ok := d.GetOk("custom_setup_script"); ok && len(customSetupScripts.([]interface{})) > 0 { + customSetupScript := customSetupScripts.([]interface{})[0].(map[string]interface{}) + + sasToken := &datafactory.SecureString{ + Value: utils.String(customSetupScript["sas_token"].(string)), + Type: datafactory.TypeSecureString, + } + + ssisProperties.CustomSetupScriptProperties = &datafactory.IntegrationRuntimeCustomSetupScriptProperties{ + BlobContainerURI: utils.String(customSetupScript["blob_container_uri"].(string)), + SasToken: sasToken, + } + } + + return ssisProperties +} + +func flattenArmDataFactoryIntegrationRuntimeManagedVnetIntegration(vnetProperties *datafactory.IntegrationRuntimeVNetProperties) []interface{} { + if vnetProperties == nil { + return []interface{}{} + } + + return []interface{}{ + map[string]string{ + "vnet_id": *vnetProperties.VNetID, + "subnet_name": *vnetProperties.Subnet, + }, + } +} + +func flattenArmDataFactoryIntegrationRuntimeManagedSsisCatalogInfo(ssisProperties *datafactory.IntegrationRuntimeSsisCatalogInfo, d *schema.ResourceData) []interface{} { + if ssisProperties == nil { + return []interface{}{} + } + + catalogInfo := map[string]string{ + "server_endpoint": *ssisProperties.CatalogServerEndpoint, + "administrator_login": *ssisProperties.CatalogAdminUserName, + "pricing_tier": string(ssisProperties.CatalogPricingTier), + } + + if adminPassword, ok := d.GetOk("catalog_info.0.administrator_password"); ok { + catalogInfo["administrator_password"] = adminPassword.(string) + } + + return []interface{}{catalogInfo} +} + +func flattenArmDataFactoryIntegrationRuntimeManagedSsisCustomSetupScript(customSetupScriptProperties *datafactory.IntegrationRuntimeCustomSetupScriptProperties, d *schema.ResourceData) []interface{} { + if customSetupScriptProperties == nil { + return []interface{}{} + } + + customSetupScript := map[string]string{ + "blob_container_uri": *customSetupScriptProperties.BlobContainerURI, + } + + if sasToken, ok := d.GetOk("custom_setup_script.0.sas_token"); ok { + customSetupScript["sas_token"] = sasToken.(string) + } + + return []interface{}{customSetupScript} +} diff --git a/azurerm/resource_arm_data_factory_integration_runtime_managed_test.go b/azurerm/resource_arm_data_factory_integration_runtime_managed_test.go new file mode 100644 index 000000000000..4211dffaa8cf --- /dev/null +++ b/azurerm/resource_arm_data_factory_integration_runtime_managed_test.go @@ -0,0 +1,360 @@ +package azurerm + +import ( + "fmt" + "net/http" + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/helper/acctest" + "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/terraform" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" +) + +func TestAccAzureRMDataFactoryIntegrationRuntimeManaged_basic(t *testing.T) { + ri := tf.AccRandTimeInt() + config := testAccAzureRMDataFactoryIntegrationRuntimeManaged_basic(ri, testLocation()) + resourceName := "azurerm_data_factory_integration_runtime_managed.test" + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testCheckAzureRMDataFactoryIntegrationRuntimeManagedDestroy, + Steps: []resource.TestStep{ + { + Config: config, + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMDataFactoryIntegrationRuntimeManagedExists(resourceName), + ), + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +func TestAccAzureRMDataFactoryIntegrationRuntimeManaged_vnetIntegration(t *testing.T) { + ri := tf.AccRandTimeInt() + config := testAccAzureRMDataFactoryIntegrationRuntimeManaged_vnetIntegration(ri, testLocation()) + resourceName := "azurerm_data_factory_integration_runtime_managed.test" + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testCheckAzureRMDataFactoryIntegrationRuntimeManagedDestroy, + Steps: []resource.TestStep{ + { + Config: config, + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMDataFactoryIntegrationRuntimeManagedExists(resourceName), + resource.TestCheckResourceAttr(resourceName, "vnet_integration.#", "1"), + resource.TestCheckResourceAttrSet(resourceName, "vnet_integration.0.vnet_id"), + resource.TestCheckResourceAttrSet(resourceName, "vnet_integration.0.subnet_name"), + ), + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +func TestAccAzureRMDataFactoryIntegrationRuntimeManaged_catalogInfo(t *testing.T) { + ri := tf.AccRandTimeInt() + config := testAccAzureRMDataFactoryIntegrationRuntimeManaged_catalogInfo(ri, testLocation()) + resourceName := "azurerm_data_factory_integration_runtime_managed.test" + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testCheckAzureRMDataFactoryIntegrationRuntimeManagedDestroy, + Steps: []resource.TestStep{ + { + Config: config, + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMDataFactoryIntegrationRuntimeManagedExists(resourceName), + resource.TestCheckResourceAttr(resourceName, "catalog_info.#", "1"), + resource.TestCheckResourceAttrSet(resourceName, "catalog_info.0.server_endpoint"), + resource.TestCheckResourceAttr(resourceName, "catalog_info.0.administrator_login", "ssis_catalog_admin"), + resource.TestCheckResourceAttr(resourceName, "catalog_info.0.administrator_password", "my-s3cret-p4ssword!"), + resource.TestCheckResourceAttr(resourceName, "catalog_info.0.pricing_tier", "Basic"), + ), + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"catalog_info.0.administrator_password"}, + }, + }, + }) +} + +func TestAccAzureRMDataFactoryIntegrationRuntimeManaged_customSetupScript(t *testing.T) { + ri := tf.AccRandTimeInt() + rs := acctest.RandString(6) + config := testAccAzureRMDataFactoryIntegrationRuntimeManaged_customSetupScript(ri, testLocation(), rs) + resourceName := "azurerm_data_factory_integration_runtime_managed.test" + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testCheckAzureRMDataFactoryIntegrationRuntimeManagedDestroy, + Steps: []resource.TestStep{ + { + Config: config, + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMDataFactoryIntegrationRuntimeManagedExists(resourceName), + resource.TestCheckResourceAttr(resourceName, "custom_setup_script.#", "1"), + resource.TestCheckResourceAttrSet(resourceName, "custom_setup_script.0.blob_container_uri"), + resource.TestCheckResourceAttrSet(resourceName, "custom_setup_script.0.sas_token"), + ), + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"custom_setup_script.0.sas_token"}, + }, + }, + }) +} + +func testAccAzureRMDataFactoryIntegrationRuntimeManaged_basic(rInt int, location string) string { + return fmt.Sprintf(` +resource "azurerm_resource_group" "test" { + name = "acctestRG-%d" + location = "%s" +} + +resource "azurerm_data_factory" "test" { + name = "acctestdfirm%d" + location = "${azurerm_resource_group.test.location}" + resource_group_name = "${azurerm_resource_group.test.name}" +} + +resource "azurerm_data_factory_integration_runtime_managed" "test" { + name = "managed-integration-runtime" + data_factory_name = azurerm_data_factory.test.name + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location + + node_size = "Standard_D8_v3" + number_of_nodes = 2 + max_parallel_executions_per_node = 8 + edition = "Standard" + license_type = "LicenseIncluded" +} +`, rInt, location, rInt) +} + +func testAccAzureRMDataFactoryIntegrationRuntimeManaged_vnetIntegration(rInt int, location string) string { + return fmt.Sprintf(` +resource "azurerm_resource_group" "test" { + name = "acctestRG-%d" + location = "%s" +} + +resource "azurerm_virtual_network" "test" { + name = "acctestvnet%d" + address_space = ["10.0.0.0/16"] + location = "${azurerm_resource_group.test.location}" + resource_group_name = "${azurerm_resource_group.test.name}" +} + +resource "azurerm_subnet" "test" { + name = "acctestsubnet%d" + resource_group_name = "${azurerm_resource_group.test.name}" + virtual_network_name = "${azurerm_virtual_network.test.name}" + address_prefix = "10.0.2.0/24" +} + +resource "azurerm_data_factory" "test" { + name = "acctestdfirm%d" + location = "${azurerm_resource_group.test.location}" + resource_group_name = "${azurerm_resource_group.test.name}" +} + +resource "azurerm_data_factory_integration_runtime_managed" "test" { + name = "managed-integration-runtime" + data_factory_name = azurerm_data_factory.test.name + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location + + node_size = "Standard_D8_v3" + + vnet_integration { + vnet_id = "${azurerm_virtual_network.test.id}" + subnet_name = "${azurerm_subnet.test.name}" + } +} +`, rInt, location, rInt, rInt, rInt) +} + +func testAccAzureRMDataFactoryIntegrationRuntimeManaged_catalogInfo(rInt int, location string) string { + return fmt.Sprintf(` +resource "azurerm_resource_group" "test" { + name = "acctestRG-%d" + location = "%s" +} + +resource "azurerm_data_factory" "test" { + name = "acctestdfirm%d" + location = "${azurerm_resource_group.test.location}" + resource_group_name = "${azurerm_resource_group.test.name}" +} + +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_data_factory_integration_runtime_managed" "test" { + name = "managed-integration-runtime" + data_factory_name = azurerm_data_factory.test.name + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location + + node_size = "Standard_D8_v3" + + catalog_info { + server_endpoint = "${azurerm_sql_server.test.fully_qualified_domain_name}" + administrator_login = "ssis_catalog_admin" + administrator_password = "my-s3cret-p4ssword!" + pricing_tier = "Basic" + } +} +`, rInt, location, rInt, rInt) +} + +func testAccAzureRMDataFactoryIntegrationRuntimeManaged_customSetupScript(rInt int, location string, rString string) string { + return fmt.Sprintf(` +resource "azurerm_resource_group" "test" { + name = "acctestRG-%d" + location = "%s" +} + +resource "azurerm_data_factory" "test" { + name = "acctestdfirm%d" + location = "${azurerm_resource_group.test.location}" + resource_group_name = "${azurerm_resource_group.test.name}" +} + +resource "azurerm_storage_account" "test" { + name = "acctestsa%s" + resource_group_name = "${azurerm_resource_group.test.name}" + location = "${azurerm_resource_group.test.location}" + account_kind = "BlobStorage" + account_tier = "Standard" + account_replication_type = "LRS" + access_tier = "Hot" + enable_https_traffic_only = true +} + +resource "azurerm_storage_container" "test" { + name = "setup-files" + storage_account_name = "${azurerm_storage_account.test.name}" + container_access_type = "private" +} + +data "azurerm_storage_account_blob_container_sas" "test" { + connection_string = "${azurerm_storage_account.test.primary_connection_string}" + container_name = "${azurerm_storage_container.test.name}" + https_only = true + + start = "2017-03-21" + expiry = "2022-03-21" + + permissions { + read = true + add = false + create = false + write = true + delete = false + list = true + } +} + +resource "azurerm_data_factory_integration_runtime_managed" "test" { + name = "managed-integration-runtime" + data_factory_name = azurerm_data_factory.test.name + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location + + node_size = "Standard_D8_v3" + + custom_setup_script { + blob_container_uri = "${azurerm_storage_account.test.primary_blob_endpoint}/${azurerm_storage_container.test.name}" + sas_token = "${data.azurerm_storage_account_blob_container_sas.test.sas}" + } +} +`, rInt, location, rInt, rString) +} + +func testCheckAzureRMDataFactoryIntegrationRuntimeManagedExists(name string) resource.TestCheckFunc { + return func(s *terraform.State) error { + // Ensure we have enough information in state to look up in API + rs, ok := s.RootModule().Resources[name] + if !ok { + return fmt.Errorf("Not found: %s", name) + } + + name := rs.Primary.Attributes["name"] + factoryName := rs.Primary.Attributes["data_factory_name"] + resourceGroup, hasResourceGroup := rs.Primary.Attributes["resource_group_name"] + if !hasResourceGroup { + return fmt.Errorf("Bad: no resource group found in state for Data Factory Managed Integration Runtime: %s", name) + } + + client := testAccProvider.Meta().(*ArmClient).DataFactory.IntegrationRuntimesClient + ctx := testAccProvider.Meta().(*ArmClient).StopContext + + resp, err := client.Get(ctx, resourceGroup, factoryName, name, "") + if err != nil { + return fmt.Errorf("Bad: Get on IntegrationRuntimesClient: %+v", err) + } + + if utils.ResponseWasNotFound(resp.Response) { + return fmt.Errorf("Bad: Data Factory Managed Integration Runtime %q (Resource Group: %q, Data Factory %q) does not exist", name, factoryName, resourceGroup) + } + + return nil + } +} + +func testCheckAzureRMDataFactoryIntegrationRuntimeManagedDestroy(s *terraform.State) error { + client := testAccProvider.Meta().(*ArmClient).DataFactory.IntegrationRuntimesClient + ctx := testAccProvider.Meta().(*ArmClient).StopContext + + for _, rs := range s.RootModule().Resources { + if rs.Type != "azurerm_data_factory_integration_managed" { + continue + } + + name := rs.Primary.Attributes["name"] + factoryName := rs.Primary.Attributes["data_factory_name"] + resourceGroup := rs.Primary.Attributes["resource_group_name"] + + resp, err := client.Get(ctx, resourceGroup, factoryName, name, "") + + if err != nil { + return nil + } + + if resp.StatusCode != http.StatusNotFound { + return fmt.Errorf("Data Factory Managed Integration Runtime still exists:\n%#v", resp.Properties) + } + } + + return nil +} diff --git a/go.sum b/go.sum index b3838e99275c..5a9de3c28e6b 100644 --- a/go.sum +++ b/go.sum @@ -13,8 +13,6 @@ contrib.go.opencensus.io/exporter/ocagent v0.5.0/go.mod h1:ImxhfLRpxoYiSq891pBrL github.com/Azure/azure-sdk-for-go v21.3.0+incompatible/go.mod h1:9XXNKU+eRnpl9moKnB4QOLf1HestfXbmab5FXxiDBjc= github.com/Azure/azure-sdk-for-go v32.5.0+incompatible h1:Hn/DsObfmw0M7dMGS/c0MlVrJuGFzHzOpBWL89acR68= github.com/Azure/azure-sdk-for-go v32.5.0+incompatible/go.mod h1:9XXNKU+eRnpl9moKnB4QOLf1HestfXbmab5FXxiDBjc= -github.com/Azure/azure-sdk-for-go v33.2.0+incompatible h1:eDPeIqsD1UxYEcrn/DMxhfA47QcvaOXGtj4MkGIHIio= -github.com/Azure/azure-sdk-for-go v33.2.0+incompatible/go.mod h1:9XXNKU+eRnpl9moKnB4QOLf1HestfXbmab5FXxiDBjc= github.com/Azure/azure-sdk-for-go v34.1.0+incompatible h1:uW/dgSzmRQEPXwaRUN8WzBHJy5J2cp8cw1ea908uFj0= github.com/Azure/azure-sdk-for-go v34.1.0+incompatible/go.mod h1:9XXNKU+eRnpl9moKnB4QOLf1HestfXbmab5FXxiDBjc= github.com/Azure/go-autorest v10.15.4+incompatible/go.mod h1:r+4oMnoxhatjLLJ6zxSWATqVooLgysK6ZNox3g/xq24= @@ -445,7 +443,6 @@ golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL golang.org/x/exp v0.0.0-20190510132918-efd6b22b2522/go.mod h1:ZjyILWgesfNpC6sMxTJOJm9Kp84zZh5NQWvqDGG3Qr8= golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js= golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= -golang.org/x/lint v0.0.0-20181217174547-8f45f776aaf1/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU= golang.org/x/lint v0.0.0-20190301231843-5614ed5bae6f/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= diff --git a/website/azurerm.erb b/website/azurerm.erb index e9a243e9486b..feab96257f32 100644 --- a/website/azurerm.erb +++ b/website/azurerm.erb @@ -963,6 +963,10 @@ azurerm_data_factory_dataset_sql_server_table +
  • + azurerm_data_factory_integration_runtime_managed +
  • +
  • azurerm_data_factory_pipeline
  • diff --git a/website/docs/r/data_factory_integration_runtime_managed.html.markdown b/website/docs/r/data_factory_integration_runtime_managed.html.markdown new file mode 100644 index 000000000000..3caeebac84b5 --- /dev/null +++ b/website/docs/r/data_factory_integration_runtime_managed.html.markdown @@ -0,0 +1,107 @@ +--- +layout: "azurerm" +page_title: "Azure Resource Manager: azurerm_data_factory_integration_runtime_managed" +sidebar_current: "docs-azurerm_data_factory_integration_runtime_managed" +description: |- + Manages an Azure Data Factory Managed Integration Runtime. +--- + +# azurerm_data_factory_integration_runtime_managed + +Manages an Azure Data Factory Managed Integration Runtime. + +## Example Usage + +```hcl +resource "azurerm_resource_group" "example" { + name = "example" + location = "northeurope" +} + +resource "azurerm_data_factory" "example" { + name = "example" + location = "${azurerm_resource_group.example.location}" + resource_group_name = "${azurerm_resource_group.example.name}" +} + +resource "azurerm_data_factory_integration_runtime_managed" "example" { + name = "example" + data_factory_name = "${azurerm_data_factory.example.name}" + resource_group_name = "${azurerm_resource_group.example.name}" + location = "${azurerm_resource_group.example.location}" + + node_size = "Standard_D8_v3" +} +``` + +## Argument Reference + +The following arguments are supported: + +* `name` - (Required) Specifies the name of the Managed Integration Runtime. Changing this forces a new resource to be created. Must be globally unique. See the [Microsoft documentation](https://docs.microsoft.com/en-us/azure/data-factory/naming-rules) for all restrictions. + +* `data_factory_name` - (Required) Specifies the name of the Data Factory the Managed Integration Runtime belongs to. Changing this forces a new resource to be created. + +* `resource_group_name` - (Required) The name of the resource group in which to create the Managed Integration Runtime. Changing this forces a new resource to be created. + +* `location` - (Required) Specifies the supported Azure location where the resource exists. Changing this forces a new resource to be created. + +* `node_size` - (Required) The size of the nodes on which the Managed Integration Runtime runs. Valid values are: `Standard_D2_v3`, `Standard_D4_v3`, `Standard_D8_v3`, `Standard_D16_v3`, `Standard_D32_v3`, `Standard_D64_v3`, `Standard_E2_v3`, `Standard_E4_v3`, `Standard_E8_v3`, `Standard_E16_v3`, `Standard_E32_v3`, `Standard_E64_v3`, `Standard_D1_v2`, `Standard_D2_v2`, `Standard_D3_v2`, `Standard_D4_v2`, `Standard_A4_v2` and `Standard_A8_v2` + +* `number_of_nodes` - (Optional) Number of nodes for the Managed Integration Runtime. Max is `10`. Defaults to `1`. + +* `max_parallel_executions_per_node` - (Optional) Defines the maximum parallel executions per node. Defaults to `1`. Max is `16`. + +* `edition` - (Optional) The Managed Integration Runtime edition. Valid values are `Standard` and `Enterprise`. Defaults to `Standard`. + +* `license_type` - (Optional) The type of the license that is used. Valid values are `LicenseIncluded` and `BasePrize`. Defaults to `LicenseIncluded`. + +* `catalog_info` - (Optional) A `catalog_info` block as defined below. + +* `custom_setup_script` - (Optional) A `custom_setup_script` block as defined below. + +* `vnet_integration` - (Optional) A `vnet_integration` block as defined below. + +--- + +A `catalog_info` block supports the following: + +* `server_endpoint` - (Required) The endpoint of an Azure SQL Server that will be used to host the SSIS catalog. + +* `administrator_login` - (Required) Administrator login name for the SQL Server. + +* `administrator_password` - (Required) Administrator login password for the SQL Server. + +* `pricing_tier` - (Required) Pricing tier for the database that will be created for the SSIS catalog. Valid values are: `Basic`, `Standard`, `Premium` and `PremiumRS`. + +--- + +A `custom_setup_script` block supports the following: + +* `blob_container_uri` - (Required) The blob endpoint for the container which contains a custom setup script that will be run on every node on startup. See [https://docs.microsoft.com/en-us/azure/data-factory/how-to-configure-azure-ssis-ir-custom-setup](https://docs.microsoft.com/en-us/azure/data-factory/how-to-configure-azure-ssis-ir-custom-setup) for more information. + +* `sas_token` - (Required) A container SAS token that gives access to the files. See [https://docs.microsoft.com/en-us/azure/data-factory/how-to-configure-azure-ssis-ir-custom-setup](https://docs.microsoft.com/en-us/azure/data-factory/how-to-configure-azure-ssis-ir-custom-setup) for more information. + +--- + +A `vnet_integration` block supports the following: + +* `vnet_id` - (Required) ID of the virtual network to which the nodes of the Managed Integration Runtime will be added. + +* `subnet_name` - (Required) Name of the subnet to which the nodes of the Managed Integration Runtime will be added. + + +## Attributes Reference + +The following attributes are exported: + +* `id` - The Managed Integration Runtime ID. + + +## Import + +Managed Integration Runtime can be imported using the `resource id`, e.g. + +```shell +terraform import azurerm_data_factory.example /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/example/providers/Microsoft.DataFactory/factories/example/integrationruntimes/example +```