github.com/darmach/terratest@v0.34.8-0.20210517103231-80931f95e3ff/test/azure/terraform_azure_monitor_example_test.go (about) 1 // +build azure 2 3 // NOTE: We use build tags to differentiate azure testing because we currently do not have azure access setup for 4 // CircleCI. 5 6 package test 7 8 import ( 9 "testing" 10 11 "github.com/gruntwork-io/terratest/modules/azure" 12 "github.com/gruntwork-io/terratest/modules/random" 13 "github.com/gruntwork-io/terratest/modules/terraform" 14 "github.com/stretchr/testify/assert" 15 ) 16 17 func TestTerraformAzureMonitorExample(t *testing.T) { 18 t.Parallel() 19 20 // subscriptionID is overridden by the environment variable "ARM_SUBSCRIPTION_ID" 21 subscriptionID := "" 22 uniquePostfix := random.UniqueId() 23 24 // website::tag::1:: Configure Terraform setting up a path to Terraform code. 25 terraformOptions := &terraform.Options{ 26 // The path to where our Terraform code is located 27 TerraformDir: "../../examples/azure/terraform-azure-monitor-example", 28 Vars: map[string]interface{}{ 29 "postfix": uniquePostfix, 30 }, 31 } 32 33 // website::tag::4:: At the end of the test, run `terraform destroy` to clean up any resources that were created 34 defer terraform.Destroy(t, terraformOptions) 35 36 // website::tag::2:: Run `terraform init` and `terraform apply`. Fail the test if there are any errors. 37 terraform.InitAndApply(t, terraformOptions) 38 39 expectedDiagnosticSettingName := terraform.Output(t, terraformOptions, "diagnostic_setting_name") 40 keyvaultID := terraform.Output(t, terraformOptions, "keyvault_id") 41 42 diagnosticSettingsResourceExists := azure.DiagnosticSettingsResourceExists(t, expectedDiagnosticSettingName, keyvaultID, subscriptionID) 43 44 assert.Equal(t, diagnosticSettingsResourceExists, true, "Diagnostic settings should exist") 45 }