MCPcopy
hub / github.com/Azure/aztfexport / TestAppendToModule

Function TestAppendToModule

internal/test/resourcegroup/module_test.go:23–171  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

21)
22
23func TestAppendToModule(t *testing.T) {
24 t.Parallel()
25 test.Precheck(t)
26 d := test.NewData()
27 tfexecPath := test.EnsureTF(t)
28
29 provisionDir := t.TempDir()
30 if test.Keep() {
31 provisionDir, _ = os.MkdirTemp("", "")
32 t.Log(provisionDir)
33 }
34
35 if err := os.WriteFile(filepath.Join(provisionDir, "main.tf"), []byte(fmt.Sprintf(`
36provider "azurerm" {
37 features {
38 resource_group {
39 prevent_deletion_if_contains_resources = false
40 }
41 }
42}
43resource "azurerm_resource_group" "test1" {
44 name = "%[1]s1"
45 location = "WestEurope"
46}
47resource "azurerm_resource_group" "test2" {
48 name = "%[1]s2"
49 location = "WestEurope"
50}
51resource "azurerm_resource_group" "test3" {
52 name = "%[1]s3"
53 location = "WestEurope"
54}
55`, d.RandomRgName())), 0644); err != nil {
56 t.Fatalf("failed to create the TF config file: %v", err)
57 }
58 tf, err := tfexec.NewTerraform(provisionDir, tfexecPath)
59 if err != nil {
60 t.Fatalf("failed to new terraform: %v", err)
61 }
62 ctx := context.Background()
63 t.Log("Running: terraform init")
64 if err := tf.Init(ctx); err != nil {
65 t.Fatalf("terraform init failed: %v", err)
66 }
67 t.Log("Running: terraform apply")
68 if err := tf.Apply(ctx); err != nil {
69 t.Fatalf("terraform apply failed: %v", err)
70 }
71
72 if !test.Keep() {
73 defer func() {
74 t.Log("Running: terraform destroy")
75 if err := tf.Destroy(ctx); err != nil {
76 t.Logf("terraform destroy failed: %v", err)
77 }
78 }()
79 }
80

Callers

nothing calls this directly

Calls 8

PrecheckFunction · 0.92
NewDataFunction · 0.92
EnsureTFFunction · 0.92
KeepFunction · 0.92
BuildCredAndClientOptFunction · 0.92
BatchImportFunction · 0.92
RandomRgNameMethod · 0.80
InitMethod · 0.65

Tested by

no test coverage detected