Skip to content

Commit

Permalink
Add E2E for Subscription scope deployments
Browse files Browse the repository at this point in the history
  • Loading branch information
janboll committed Dec 19, 2024
1 parent 46d2516 commit ef67840
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 2 deletions.
7 changes: 5 additions & 2 deletions tooling/templatize/internal/end2end/e2e.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ func newE2E(tmpdir string) e2eImpl {
return imp
}

func (e *e2eImpl) UseRandomRG() func() error {
func GenerateRandomRGName() string {
rgSuffx := ""
if jobID := os.Getenv("JOB_ID"); jobID != "" {
rgSuffx = jobID
Expand All @@ -99,8 +99,11 @@ func (e *e2eImpl) UseRandomRG() func() error {
for i := 0; i < 3; i++ {
rgSuffx += string(chars[rand.IntN(len(chars))])
}
return "templatize-e2e-" + rgSuffx
}

e.rgName = "templatize-e2e-" + rgSuffx
func (e *e2eImpl) UseRandomRG() func() error {
e.rgName = GenerateRandomRGName()
e.SetConfig(config.Variables{"defaults": config.Variables{"rg": e.rgName}})

return func() error {
Expand Down
44 changes: 44 additions & 0 deletions tooling/templatize/internal/end2end/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package testutil

import (
"context"
"fmt"
"os"
"path/filepath"
"testing"
Expand All @@ -14,6 +15,7 @@ import (

"github.com/Azure/azure-sdk-for-go/sdk/azidentity"
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/dns/armdns"
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armresources"
)

func persistAndRun(t *testing.T, e2eImpl E2E) {
Expand Down Expand Up @@ -334,3 +336,45 @@ param parameterA = 'Hello Bicep'`,
assert.NilError(t, err)
assert.Equal(t, string(io), "Hello Bicep\n")
}

func TestE2EArmDeploySubscriptionScope(t *testing.T) {
if !shouldRunE2E() {
t.Skip("Skipping end-to-end tests")
}

tmpDir := t.TempDir()

e2eImpl := newE2E(tmpDir)
e2eImpl.AddStep(pipeline.Step{
Name: "parameterA",
Action: "ARM",
Template: "testa.bicep",
Parameters: "testa.bicepparm",
DeploymentLevel: "Subscription",
}, 0)
rgName := GenerateRandomRGName()
e2eImpl.AddBicepTemplate(fmt.Sprintf(`
targetScope='subscription'
resource newRG 'Microsoft.Resources/resourceGroups@2024-03-01' = {
name: '%s'
location: 'westus3'
}`, rgName),
"testa.bicep",
"using 'testa.bicep'",
"testa.bicepparm")

persistAndRun(t, &e2eImpl)

subsriptionID, err := pipeline.LookupSubscriptionID(context.Background(), "ARO Hosted Control Planes (EA Subscription 1)")
assert.NilError(t, err)

cred, err := azidentity.NewDefaultAzureCredential(nil)
assert.NilError(t, err)

rgClient, err := armresources.NewResourceGroupsClient(subsriptionID, cred, nil)
assert.NilError(t, err)

_, err = rgClient.BeginDelete(context.Background(), rgName, nil)
assert.NilError(t, err)
}

0 comments on commit ef67840

Please sign in to comment.