From 8ad606fb03de6da572818b60d7cedd84c3b55561 Mon Sep 17 00:00:00 2001 From: sweanan Date: Mon, 12 Jun 2023 07:36:34 -0500 Subject: [PATCH 1/6] first draft --- .../main.tf | 49 +++++++++++++++++++ .../outputs.tf | 7 +++ .../variables.tf | 31 ++++++++++++ go.mod | 3 +- go.sum | 4 +- modules/azure/client_factory.go | 30 ++++++++++++ modules/azure/datafactory.go | 36 ++++++++++++++ modules/azure/datafactory_test.go | 23 +++++++++ ...erraform_azure_datafactory_example_test.go | 46 +++++++++++++++++ 9 files changed, 226 insertions(+), 3 deletions(-) create mode 100644 examples/azure/terraform-azure-datafactory-example/main.tf create mode 100644 examples/azure/terraform-azure-datafactory-example/outputs.tf create mode 100644 examples/azure/terraform-azure-datafactory-example/variables.tf create mode 100644 modules/azure/datafactory.go create mode 100644 modules/azure/datafactory_test.go create mode 100644 test/azure/terraform_azure_datafactory_example_test.go diff --git a/examples/azure/terraform-azure-datafactory-example/main.tf b/examples/azure/terraform-azure-datafactory-example/main.tf new file mode 100644 index 000000000..934e6bba3 --- /dev/null +++ b/examples/azure/terraform-azure-datafactory-example/main.tf @@ -0,0 +1,49 @@ +# --------------------------------------------------------------------------------------------------------------------- +# DEPLOY AN AZURE DATA FACTORY +# This is an example of how to deploy an AZURE Data Factory +# See test/terraform_azure_example_test.go for how to write automated tests for this code. +# --------------------------------------------------------------------------------------------------------------------- + + +# --------------------------------------------------------------------------------------------------------------------- +# CONFIGURE OUR AZURE CONNECTION +# --------------------------------------------------------------------------------------------------------------------- + +provider "azurerm" { + version = "~>2.29.0" + features {} +} + +# --------------------------------------------------------------------------------------------------------------------- +# CREATE RANDOM PASSWORD +# --------------------------------------------------------------------------------------------------------------------- + +# Random password is used as an example to simplify the deployment and improve the security of the database. +# This is not as a production recommendation as the password is stored in the Terraform state file. +resource "random_password" "password" { + length = 16 + override_special = "-_%@" + min_upper = "1" + min_lower = "1" + min_numeric = "1" + min_special = "1" +} + +# --------------------------------------------------------------------------------------------------------------------- +# DEPLOY A RESOURCE GROUP +# --------------------------------------------------------------------------------------------------------------------- + +resource "azurerm_resource_group" "datafactory_rg" { + name = "terratest-datafactory-${var.postfix}" + location = var.location +} + +# --------------------------------------------------------------------------------------------------------------------- +# DEPLOY A DATA FACTORY +# --------------------------------------------------------------------------------------------------------------------- + +resource "azurerm_data_factory" "data_factory" { + name = "datafactory${var.postfix}" + location = azurerm_resource_group.datafactory_rg.location + resource_group_name = azurerm_resource_group.datafactory_rg.name +} \ No newline at end of file diff --git a/examples/azure/terraform-azure-datafactory-example/outputs.tf b/examples/azure/terraform-azure-datafactory-example/outputs.tf new file mode 100644 index 000000000..f1b4c328f --- /dev/null +++ b/examples/azure/terraform-azure-datafactory-example/outputs.tf @@ -0,0 +1,7 @@ +output "resource_group_name" { + value = azurerm_resource_group.datafactory_rg.name +} + +output "datafactory_name" { + value = azurerm_data_factory.data_factory.name +} diff --git a/examples/azure/terraform-azure-datafactory-example/variables.tf b/examples/azure/terraform-azure-datafactory-example/variables.tf new file mode 100644 index 000000000..45feecbaa --- /dev/null +++ b/examples/azure/terraform-azure-datafactory-example/variables.tf @@ -0,0 +1,31 @@ +# --------------------------------------------------------------------------------------------------------------------- +# ENVIRONMENT VARIABLES +# Define these secrets as environment variables +# --------------------------------------------------------------------------------------------------------------------- + +# ARM_CLIENT_ID +# ARM_CLIENT_SECRET +# ARM_SUBSCRIPTION_ID +# ARM_TENANT_ID + +# --------------------------------------------------------------------------------------------------------------------- +# REQUIRED PARAMETERS +# You must provide a value for each of these parameters. +# --------------------------------------------------------------------------------------------------------------------- + +# --------------------------------------------------------------------------------------------------------------------- +# OPTIONAL PARAMETERS +# These parameters have reasonable defaults. +# --------------------------------------------------------------------------------------------------------------------- + +variable "location" { + description = "The supported azure location where the resource exists" + type = string + default = "usgovvirginia" +} + +variable "postfix" { + description = "A postfix string to centrally mitigate resource name collisions." + type = string + default = "resource" +} diff --git a/go.mod b/go.mod index 35b98bbb4..6c3ba29d5 100644 --- a/go.mod +++ b/go.mod @@ -5,7 +5,7 @@ go 1.19 require ( cloud.google.com/go v0.105.0 // indirect cloud.google.com/go/storage v1.27.0 - github.com/Azure/azure-sdk-for-go v50.2.0+incompatible + github.com/Azure/azure-sdk-for-go v51.0.0+incompatible github.com/Azure/go-autorest/autorest v0.11.20 github.com/Azure/go-autorest/autorest/azure/auth v0.5.8 github.com/Azure/go-autorest/autorest/to v0.4.0 // indirect @@ -53,6 +53,7 @@ require ( ) require ( + cloud.google.com/go v0.105.0 // indirect cloud.google.com/go/compute v1.12.1 // indirect cloud.google.com/go/compute/metadata v0.2.1 // indirect cloud.google.com/go/iam v0.7.0 // indirect diff --git a/go.sum b/go.sum index e2a86b5ec..2b2b7c3bc 100644 --- a/go.sum +++ b/go.sum @@ -191,8 +191,8 @@ cloud.google.com/go/workflows v1.6.0/go.mod h1:6t9F5h/unJz41YqfBmqSASJSXccBLtD1V cloud.google.com/go/workflows v1.7.0/go.mod h1:JhSrZuVZWuiDfKEFxU0/F1PQjmpnpcoISEXH2bcHC3M= dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU= github.com/Azure/azure-sdk-for-go v16.2.1+incompatible/go.mod h1:9XXNKU+eRnpl9moKnB4QOLf1HestfXbmab5FXxiDBjc= -github.com/Azure/azure-sdk-for-go v50.2.0+incompatible h1:w9EF1btRfLLWbNEp6XvkMjeA6nQ3e1GZ2KNDqB/SjOQ= -github.com/Azure/azure-sdk-for-go v50.2.0+incompatible/go.mod h1:9XXNKU+eRnpl9moKnB4QOLf1HestfXbmab5FXxiDBjc= +github.com/Azure/azure-sdk-for-go v51.0.0+incompatible h1:p7blnyJSjJqf5jflHbSGhIhEpXIgIFmYZNg5uwqweso= +github.com/Azure/azure-sdk-for-go v51.0.0+incompatible/go.mod h1:9XXNKU+eRnpl9moKnB4QOLf1HestfXbmab5FXxiDBjc= github.com/Azure/go-ansiterm v0.0.0-20170929234023-d6e3b3328b78/go.mod h1:LmzpDX56iTiv29bbRTIsUNlaFfuhWRQBWjQdVyAevI8= github.com/Azure/go-autorest v10.8.1+incompatible/go.mod h1:r+4oMnoxhatjLLJ6zxSWATqVooLgysK6ZNox3g/xq24= github.com/Azure/go-autorest v14.2.0+incompatible h1:V5VMDjClD3GiElqLWO7mz2MxNAK/vTfRHdAubSIPRgs= diff --git a/modules/azure/client_factory.go b/modules/azure/client_factory.go index 383ff8980..421175639 100644 --- a/modules/azure/client_factory.go +++ b/modules/azure/client_factory.go @@ -24,6 +24,7 @@ import ( "github.com/Azure/azure-sdk-for-go/services/containerinstance/mgmt/2018-10-01/containerinstance" "github.com/Azure/azure-sdk-for-go/services/containerregistry/mgmt/2019-05-01/containerregistry" "github.com/Azure/azure-sdk-for-go/services/containerservice/mgmt/2019-11-01/containerservice" + "github.com/Azure/azure-sdk-for-go/services/datafactory/mgmt/2018-06-01/datafactory" kvmng "github.com/Azure/azure-sdk-for-go/services/keyvault/mgmt/2016-10-01/keyvault" "github.com/Azure/azure-sdk-for-go/services/network/mgmt/2019-09-01/network" "github.com/Azure/azure-sdk-for-go/services/resources/mgmt/2019-06-01/subscriptions" @@ -771,6 +772,35 @@ func CreateFrontDoorFrontendEndpointClientE(subscriptionID string) (*frontdoor.F return &client, nil } +// CreateDataFactoriesClientE is a helper function that will setup a synapse client. +func CreateDataFactoriesClientE(subscriptionID string) (*datafactory.FactoriesClient, error) { + // Validate Azure subscription ID + subscriptionID, err := getTargetAzureSubscription(subscriptionID) + if err != nil { + return nil, err + } + + // Lookup environment URI + baseURI, err := getBaseURI() + if err != nil { + return nil, err + } + + // Create a synapse client + dataFactoryClient := datafactory.NewFactoriesClientWithBaseURI(baseURI, subscriptionID) + + // Create an authorizer + authorizer, err := NewAuthorizer() + if err != nil { + return nil, err + } + + // Attach authorizer to the client + dataFactoryClient.Authorizer = *authorizer + + return &dataFactoryClient, nil +} + // GetKeyVaultURISuffixE returns the proper KeyVault URI suffix for the configured Azure environment. // This function would fail the test if there is an error. func GetKeyVaultURISuffixE() (string, error) { diff --git a/modules/azure/datafactory.go b/modules/azure/datafactory.go new file mode 100644 index 000000000..4d88c2d7b --- /dev/null +++ b/modules/azure/datafactory.go @@ -0,0 +1,36 @@ +package azure + +import ( + "context" + + "github.com/Azure/azure-sdk-for-go/services/datafactory/mgmt/2018-06-01/datafactory" + "github.com/gruntwork-io/terratest/modules/testing" + "github.com/stretchr/testify/require" +) + +// GetSynapseWorkspace is a helper function that gets the synapse workspace. +// This function would fail the test if there is an error. +func GetDataFactory(t testing.TestingT, resGroupName string, factoryName string, subscriptionID string) *datafactory.Factory { + Workspace, err := GetDataFactoryE(t, subscriptionID, resGroupName, factoryName) + require.NoError(t, err) + + return Workspace +} + +// GetDataFactoryE is a helper function that gets the workspace. +func GetDataFactoryE(t testing.TestingT, subscriptionID string, resGroupName string, factoryName string) (*datafactory.Factory, error) { + // Create a datafactory client + datafactoryClient, err := CreateDataFactoriesClientE(subscriptionID) + if err != nil { + return nil, err + } + + // Get the corresponding synapse workspace + dataFactory, err := datafactoryClient.Get(context.Background(), resGroupName, factoryName, "") + if err != nil { + return nil, err + } + + //Return synapse workspace + return &dataFactory, nil +} diff --git a/modules/azure/datafactory_test.go b/modules/azure/datafactory_test.go new file mode 100644 index 000000000..b3f688aa4 --- /dev/null +++ b/modules/azure/datafactory_test.go @@ -0,0 +1,23 @@ +package azure + +import ( + "testing" + + "github.com/stretchr/testify/require" +) + +/* +The below tests are currently stubbed out, with the expectation that they will throw errors. +If/when CRUD methods are introduced for Azure Synapse, these tests can be extended +*/ + +func TestGetDataFactoryE(t *testing.T) { + t.Parallel() + + resGroupName := "terratest-datafactory-resource" + subscriptionID := "00fb78cc-7201-4e1c-8203-2b2e1390309a" + dataFactoryName := "datafactoryresource" + + _, err := GetDataFactoryE(t, subscriptionID, resGroupName, dataFactoryName) + require.Error(t, err) +} diff --git a/test/azure/terraform_azure_datafactory_example_test.go b/test/azure/terraform_azure_datafactory_example_test.go new file mode 100644 index 000000000..cd3d99260 --- /dev/null +++ b/test/azure/terraform_azure_datafactory_example_test.go @@ -0,0 +1,46 @@ +package test + +import ( + "strings" + "testing" + + "github.com/gruntwork-io/terratest/modules/azure" + "github.com/gruntwork-io/terratest/modules/random" + "github.com/gruntwork-io/terratest/modules/terraform" + "github.com/stretchr/testify/assert" +) + +func TestTerraformAzureDataFactoryExample(t *testing.T) { + t.Parallel() + + uniquePostfix := strings.ToLower(random.UniqueId()) + expectedDataFactoryProvisioningState := "Succeeded" + expectedLocation := "usgovvirginia" + + // website::tag::1:: Configure Terraform setting up a path to Terraform code. + terraformOptions := &terraform.Options{ + // The path to where our Terraform code is located + TerraformDir: "../../examples/azure/terraform-azure-datafactory-example", + Vars: map[string]interface{}{ + "postfix": uniquePostfix, + "location": expectedLocation, + }, + } + + // website::tag::4:: At the end of the test, run `terraform destroy` to clean up any resources that were created + defer terraform.Destroy(t, terraformOptions) + + // website::tag::2:: Run `terraform init` and `terraform apply`. Fail the test if there are any errors. + terraform.InitAndApply(t, terraformOptions) + + // website::tag::3:: Run `terraform output` to get the values of output variables + expectedResourceGroupName := terraform.Output(t, terraformOptions, "resource_group_name") + expectedDataFactoryName := terraform.Output(t, terraformOptions, "datafactory_name") + + // // website::tag::4:: Get synapse details and assert them against the terraform output + actualDataFactory := azure.GetDataFactory(t, expectedResourceGroupName, expectedDataFactoryName, "") + + assert.Equal(t, expectedDataFactoryName, *actualDataFactory.Name) + assert.Equal(t, expectedDataFactoryProvisioningState, *actualDataFactory.FactoryProperties.ProvisioningState) + +} From a7d0356fc658f59bfee417182470b4362b1604f3 Mon Sep 17 00:00:00 2001 From: sweanan Date: Tue, 13 Jun 2023 07:56:12 -0500 Subject: [PATCH 2/6] update the version and location --- .../README.md | 31 +++++++++++++++++++ .../main.tf | 2 +- .../variables.tf | 2 +- ...erraform_azure_datafactory_example_test.go | 2 +- 4 files changed, 34 insertions(+), 3 deletions(-) create mode 100644 examples/azure/terraform-azure-datafactory-example/README.md diff --git a/examples/azure/terraform-azure-datafactory-example/README.md b/examples/azure/terraform-azure-datafactory-example/README.md new file mode 100644 index 000000000..f53e86886 --- /dev/null +++ b/examples/azure/terraform-azure-datafactory-example/README.md @@ -0,0 +1,31 @@ +# Terraform Azure Data Factory Example + +This folder contains a Terraform module that deploys resources in [Azure](https://azure.microsoft.com/) to demonstrate how you can use Terratest to write automated tests for your Azure Terraform code. +This module deploys a Data Factory. + +- A [Azure MySQL Database](https://azure.microsoft.com/en-us/products/data-factory). + +Check out [test/azure/terraform_azure_datafactory_example_test.go](./../../../test/azure/terraform_azure_datafactory_example_test.go) to see how you can write automated tests for this module and validate the configuration of the parameters and options. + +**WARNING**: This module and the automated tests for it deploy real resources into your Azure account which can cost you money. + +## Running this module manually +1. Sign up for [Azure](https://azure.microsoft.com/). +1. Configure your Azure credentials using one of the [supported methods for Azure CLI + tools](https://docs.microsoft.com/en-us/cli/azure/azure-cli-configuration?view=azure-cli-latest) +1. Install [Terraform](https://www.terraform.io/) and make sure it's on your `PATH`. +1. Ensure [environment variables](../README.md#review-environment-variables) are available +1. Run `terraform init` +1. Run `terraform apply` +1. When you're done, run `terraform destroy`. + + +## Running automated tests against this module +1. Sign up for [Azure](https://azure.microsoft.com/) +1. Configure your Azure credentials using one of the [supported methods for Azure CLI + tools](https://docs.microsoft.com/en-us/cli/azure/azure-cli-configuration?view=azure-cli-latest) +1. Install [Terraform](https://www.terraform.io/) and make sure it's on your `PATH` +1. Configure your Terratest [Go test environment](../README.md) +1. `cd test/azure` +1. `go build terraform_azure_datafactory_example_test.go` +2. `go test -v -timeout 60m -tags azure -run TestTerraformAzureDataFactoryExample` \ No newline at end of file diff --git a/examples/azure/terraform-azure-datafactory-example/main.tf b/examples/azure/terraform-azure-datafactory-example/main.tf index 934e6bba3..2b89521c9 100644 --- a/examples/azure/terraform-azure-datafactory-example/main.tf +++ b/examples/azure/terraform-azure-datafactory-example/main.tf @@ -10,7 +10,7 @@ # --------------------------------------------------------------------------------------------------------------------- provider "azurerm" { - version = "~>2.29.0" + version = "~>2.93.0" features {} } diff --git a/examples/azure/terraform-azure-datafactory-example/variables.tf b/examples/azure/terraform-azure-datafactory-example/variables.tf index 45feecbaa..bd88a0e8f 100644 --- a/examples/azure/terraform-azure-datafactory-example/variables.tf +++ b/examples/azure/terraform-azure-datafactory-example/variables.tf @@ -21,7 +21,7 @@ variable "location" { description = "The supported azure location where the resource exists" type = string - default = "usgovvirginia" + default = "West US2" } variable "postfix" { diff --git a/test/azure/terraform_azure_datafactory_example_test.go b/test/azure/terraform_azure_datafactory_example_test.go index cd3d99260..28b68a0b0 100644 --- a/test/azure/terraform_azure_datafactory_example_test.go +++ b/test/azure/terraform_azure_datafactory_example_test.go @@ -15,7 +15,7 @@ func TestTerraformAzureDataFactoryExample(t *testing.T) { uniquePostfix := strings.ToLower(random.UniqueId()) expectedDataFactoryProvisioningState := "Succeeded" - expectedLocation := "usgovvirginia" + expectedLocation := "West US2" // website::tag::1:: Configure Terraform setting up a path to Terraform code. terraformOptions := &terraform.Options{ From 59d37493382d84f72894e459c60d66842f83c584 Mon Sep 17 00:00:00 2001 From: sweanan Date: Fri, 16 Jun 2023 08:31:25 -0500 Subject: [PATCH 3/6] added datafactoryExists helper function --- modules/azure/datafactory.go | 26 ++++++++++++++++--- modules/azure/datafactory_test.go | 20 +++++++++++--- ...erraform_azure_datafactory_example_test.go | 2 ++ 3 files changed, 41 insertions(+), 7 deletions(-) diff --git a/modules/azure/datafactory.go b/modules/azure/datafactory.go index 4d88c2d7b..b8d5be7e3 100644 --- a/modules/azure/datafactory.go +++ b/modules/azure/datafactory.go @@ -8,17 +8,37 @@ import ( "github.com/stretchr/testify/require" ) -// GetSynapseWorkspace is a helper function that gets the synapse workspace. +// DataFactoryExists indicates whether the Data Factory exists for the subscription. +// This function would fail the test if there is an error. +func DataFactoryExists(t testing.TestingT, dataFactoryName string, resourceGroupName string, subscriptionID string) bool { + exists, err := DataFactoryExistsE(dataFactoryName, resourceGroupName, subscriptionID) + require.NoError(t, err) + return exists +} + +// DataFactoryExistsE indicates whether the specified Data Factory exists and may return an error. +func DataFactoryExistsE(dataFactoryName string, resourceGroupName string, subscriptionID string) (bool, error) { + _, err := GetDataFactoryE(subscriptionID, resourceGroupName, dataFactoryName) + if err != nil { + if ResourceNotFoundErrorExists(err) { + return false, nil + } + return false, err + } + return true, nil +} + +// GetDataFactory is a helper function that gets the synapse workspace. // This function would fail the test if there is an error. func GetDataFactory(t testing.TestingT, resGroupName string, factoryName string, subscriptionID string) *datafactory.Factory { - Workspace, err := GetDataFactoryE(t, subscriptionID, resGroupName, factoryName) + Workspace, err := GetDataFactoryE(subscriptionID, resGroupName, factoryName) require.NoError(t, err) return Workspace } // GetDataFactoryE is a helper function that gets the workspace. -func GetDataFactoryE(t testing.TestingT, subscriptionID string, resGroupName string, factoryName string) (*datafactory.Factory, error) { +func GetDataFactoryE(subscriptionID string, resGroupName string, factoryName string) (*datafactory.Factory, error) { // Create a datafactory client datafactoryClient, err := CreateDataFactoriesClientE(subscriptionID) if err != nil { diff --git a/modules/azure/datafactory_test.go b/modules/azure/datafactory_test.go index b3f688aa4..437e31d39 100644 --- a/modules/azure/datafactory_test.go +++ b/modules/azure/datafactory_test.go @@ -10,14 +10,26 @@ import ( The below tests are currently stubbed out, with the expectation that they will throw errors. If/when CRUD methods are introduced for Azure Synapse, these tests can be extended */ +func TestDataFactoryExists(t *testing.T) { + t.Parallel() + + dataFactoryName := "" + resourceGroupName := "" + subscriptionID := "" + + exists, err := DataFactoryExistsE(dataFactoryName, resourceGroupName, subscriptionID) + + require.False(t, exists) + require.Error(t, err) +} func TestGetDataFactoryE(t *testing.T) { t.Parallel() - resGroupName := "terratest-datafactory-resource" - subscriptionID := "00fb78cc-7201-4e1c-8203-2b2e1390309a" - dataFactoryName := "datafactoryresource" + resGroupName := "" + subscriptionID := "" + dataFactoryName := "" - _, err := GetDataFactoryE(t, subscriptionID, resGroupName, dataFactoryName) + _, err := GetDataFactoryE(subscriptionID, resGroupName, dataFactoryName) require.Error(t, err) } diff --git a/test/azure/terraform_azure_datafactory_example_test.go b/test/azure/terraform_azure_datafactory_example_test.go index 28b68a0b0..45865fbab 100644 --- a/test/azure/terraform_azure_datafactory_example_test.go +++ b/test/azure/terraform_azure_datafactory_example_test.go @@ -43,4 +43,6 @@ func TestTerraformAzureDataFactoryExample(t *testing.T) { assert.Equal(t, expectedDataFactoryName, *actualDataFactory.Name) assert.Equal(t, expectedDataFactoryProvisioningState, *actualDataFactory.FactoryProperties.ProvisioningState) + actualDataFactoryExits := azure.DataFactoryExists(t, expectedDataFactoryName, expectedResourceGroupName, "") + assert.True(t, actualDataFactoryExits) } From 4e21d6a2dde27e2a0c84a1cef434bc113b75a17f Mon Sep 17 00:00:00 2001 From: sweanan Date: Tue, 20 Jun 2023 08:23:01 -0500 Subject: [PATCH 4/6] move the data factory exists upfront --- ...erraform_azure_datafactory_example_test.go | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/test/azure/terraform_azure_datafactory_example_test.go b/test/azure/terraform_azure_datafactory_example_test.go index 45865fbab..c9c516c29 100644 --- a/test/azure/terraform_azure_datafactory_example_test.go +++ b/test/azure/terraform_azure_datafactory_example_test.go @@ -15,9 +15,9 @@ func TestTerraformAzureDataFactoryExample(t *testing.T) { uniquePostfix := strings.ToLower(random.UniqueId()) expectedDataFactoryProvisioningState := "Succeeded" - expectedLocation := "West US2" + expectedLocation := "eastus" - // website::tag::1:: Configure Terraform setting up a path to Terraform code. + //Configure Terraform setting up a path to Terraform code. terraformOptions := &terraform.Options{ // The path to where our Terraform code is located TerraformDir: "../../examples/azure/terraform-azure-datafactory-example", @@ -27,22 +27,23 @@ func TestTerraformAzureDataFactoryExample(t *testing.T) { }, } - // website::tag::4:: At the end of the test, run `terraform destroy` to clean up any resources that were created + // At the end of the test, run `terraform destroy` to clean up any resources that were created defer terraform.Destroy(t, terraformOptions) - // website::tag::2:: Run `terraform init` and `terraform apply`. Fail the test if there are any errors. + //Run `terraform init` and `terraform apply`. Fail the test if there are any errors. terraform.InitAndApply(t, terraformOptions) - // website::tag::3:: Run `terraform output` to get the values of output variables + // Run `terraform output` to get the values of output variables expectedResourceGroupName := terraform.Output(t, terraformOptions, "resource_group_name") expectedDataFactoryName := terraform.Output(t, terraformOptions, "datafactory_name") - // // website::tag::4:: Get synapse details and assert them against the terraform output - actualDataFactory := azure.GetDataFactory(t, expectedResourceGroupName, expectedDataFactoryName, "") + // check for if data factory exists + actualDataFactoryExits := azure.DataFactoryExists(t, expectedDataFactoryName, expectedResourceGroupName, "") + assert.True(t, actualDataFactoryExits) + //Get data factory details and assert them against the terraform output + actualDataFactory := azure.GetDataFactory(t, expectedResourceGroupName, expectedDataFactoryName, "") assert.Equal(t, expectedDataFactoryName, *actualDataFactory.Name) assert.Equal(t, expectedDataFactoryProvisioningState, *actualDataFactory.FactoryProperties.ProvisioningState) - actualDataFactoryExits := azure.DataFactoryExists(t, expectedDataFactoryName, expectedResourceGroupName, "") - assert.True(t, actualDataFactoryExits) } From 00d56175c15e1794d8ae40afad4e32480b39312d Mon Sep 17 00:00:00 2001 From: sweanan Date: Tue, 20 Jun 2023 15:28:36 -0500 Subject: [PATCH 5/6] added build tags --- test/azure/terraform_azure_datafactory_example_test.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/test/azure/terraform_azure_datafactory_example_test.go b/test/azure/terraform_azure_datafactory_example_test.go index c9c516c29..86e392c89 100644 --- a/test/azure/terraform_azure_datafactory_example_test.go +++ b/test/azure/terraform_azure_datafactory_example_test.go @@ -1,3 +1,6 @@ +//go:build azure +// +build azure + package test import ( From b7e102202ec439a40da9c133b24a457badcaf82e Mon Sep 17 00:00:00 2001 From: sweanan Date: Tue, 20 Jun 2023 16:21:54 -0500 Subject: [PATCH 6/6] update the location for synapse --- test/azure/terraform_azure_synapse_example_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/azure/terraform_azure_synapse_example_test.go b/test/azure/terraform_azure_synapse_example_test.go index c779115b6..e1e254a8a 100644 --- a/test/azure/terraform_azure_synapse_example_test.go +++ b/test/azure/terraform_azure_synapse_example_test.go @@ -22,7 +22,7 @@ func TestTerraformAzureSynapseExample(t *testing.T) { uniquePostfix := strings.ToLower(random.UniqueId()) expectedSynapseSqlUser := "sqladminuser" expectedSynapseProvisioningState := "Succeeded" - expectedLocation := "West US2" + expectedLocation := "westus2" expectedSyPoolSkuName := "DW100c" // website::tag::1:: Configure Terraform setting up a path to Terraform code.