-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
sweanan
committed
Jun 12, 2023
1 parent
60601b4
commit 8ad606f
Showing
9 changed files
with
226 additions
and
3 deletions.
There are no files selected for viewing
49 changes: 49 additions & 0 deletions
49
examples/azure/terraform-azure-datafactory-example/main.tf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} |
7 changes: 7 additions & 0 deletions
7
examples/azure/terraform-azure-datafactory-example/outputs.tf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} |
31 changes: 31 additions & 0 deletions
31
examples/azure/terraform-azure-datafactory-example/variables.tf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) | ||
|
||
} |