github.com/swisspost/terratest@v0.0.0-20230214120104-7ec6de2e1ae0/test/azure/terraform_azure_monitor_example_test.go (about)

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