github.com/darmach/terratest@v0.34.8-0.20210517103231-80931f95e3ff/test/azure/terraform_azure_recoveryservices_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 TestTerraformAzureRecoveryServicesExample(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-recoveryservices-example", 28 // Variables to pass to our Terraform code using -var options 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 // website::tag::3:: Run `terraform output` to get the values of output variables 41 resourceGroupName := terraform.Output(t, terraformOptions, "resource_group_name") 42 vaultName := terraform.Output(t, terraformOptions, "recovery_service_vault_name") 43 policyVmName := terraform.Output(t, terraformOptions, "backup_policy_vm_name") 44 45 // website::tag::4:: Verify the recovery services resources 46 exists := azure.RecoveryServicesVaultExists(t, vaultName, resourceGroupName, subscriptionID) 47 assert.True(t, exists, "vault does not exist") 48 49 policyList := azure.GetRecoveryServicesVaultBackupPolicyList(t, vaultName, resourceGroupName, subscriptionID) 50 assert.NotNil(t, policyList, "vault backup policy list is nil") 51 52 vmPolicyList := azure.GetRecoveryServicesVaultBackupProtectedVMList(t, policyVmName, vaultName, resourceGroupName, subscriptionID) 53 assert.NotNil(t, vmPolicyList, "vault backup policy list for protected vm is nil") 54 }