Skip to content

Commit

Permalink
tests: Remove Terraform Remote State integration test (#4701)
Browse files Browse the repository at this point in the history
When we were bringing up the `azd` support for Terraform, we added two
end to end tests which deployed an application using Terraform.  One
stored the state file localy and the other used the terraform remote
state backend to store the state in blob storage.

When we migrated to the TME environment, this broke, because we need
to use OIDC to authenticate to the storage account, but the remote
state plugin isn't able to do this natively, and the support to use
the `az` CLI fails in in this mode because it is only supported for
user accounts (and the tests run under a service principal).

In practice, `azd` isn't doing anything special here - the test uses
the `az` CLI to create a storage account and then sets some
environment variables to configure the terraform provider to use it
for state management.  So, instead of fighting with the infrastructure
to support this tests, let's just get rid of it.  We already have end
to end coverage of Terraform itself with the local state test, and the
way `azd` interacts with terraform is the same between remote and
local state storage, so we aren't getting any additional coverage from
the test.

Closes #4564
  • Loading branch information
ellismg authored Jan 16, 2025
1 parent 7a302d7 commit ad53ef2
Showing 1 changed file with 0 additions and 88 deletions.
88 changes: 0 additions & 88 deletions cli/azd/test/functional/cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -837,94 +837,6 @@ func Test_CLI_InfraCreateAndDeleteResourceTerraform(t *testing.T) {
t.Logf("Done\n")
}

func Test_CLI_InfraCreateAndDeleteResourceTerraformRemote(t *testing.T) {
t.Skip("azure/azure-dev#4564")

ctx, cancel := newTestContext(t)
defer cancel()

dir := tempDirWithDiagnostics(t)
t.Logf("DIR: %s", dir)

envName := randomEnvName()
location := "eastus2"
backendResourceGroupName := fmt.Sprintf("rs-%s", envName)
backendStorageAccountName := strings.Replace(envName, "-", "", -1)
backendContainerName := "tfstate"

t.Logf("AZURE_ENV_NAME: %s", envName)

cli := azdcli.NewCLI(t)
cli.WorkingDirectory = dir
cli.Env = append(os.Environ(), fmt.Sprintf("AZURE_LOCATION=%s", location))

err := copySample(dir, "resourcegroupterraformremote")
require.NoError(t, err, "failed expanding sample")

//Create remote state resources
commandRunner := exec.NewCommandRunner(nil)
runArgs := newRunArgs("az", "group", "create", "--name", backendResourceGroupName, "--location", location)

_, err = commandRunner.Run(ctx, runArgs)
require.NoError(t, err)

defer func() {
commandRunner := exec.NewCommandRunner(nil)
runArgs := newRunArgs("az", "group", "delete", "--name", backendResourceGroupName, "--yes")
_, err = commandRunner.Run(ctx, runArgs)
require.NoError(t, err)
}()

//Create storage account
runArgs = newRunArgs("az", "storage", "account", "create", "--resource-group", backendResourceGroupName,
"--name", backendStorageAccountName, "--sku", "Standard_LRS", "--encryption-services", "blob")
_, err = commandRunner.Run(ctx, runArgs)
require.NoError(t, err)

//Get Account Key
runArgs = newRunArgs("az", "storage", "account", "keys", "list", "--resource-group",
backendResourceGroupName, "--account-name", backendStorageAccountName, "--query", "[0].value",
"-o", "tsv")
cmdResult, err := commandRunner.Run(ctx, runArgs)
require.NoError(t, err)
storageAccountKey := strings.ReplaceAll(strings.ReplaceAll(cmdResult.Stdout, "\n", ""), "\r", "")

// Create storage container
runArgs = newRunArgs("az", "storage", "container", "create", "--name", backendContainerName,
"--account-name", backendStorageAccountName, "--account-key", storageAccountKey)
runArgs.SensitiveData = append(runArgs.SensitiveData, storageAccountKey)
result, err := commandRunner.Run(ctx, runArgs)
_ = result
require.NoError(t, err)

//Run azd init
_, err = cli.RunCommandWithStdIn(ctx, stdinForInit(envName), "init")
require.NoError(t, err)

_, err = cli.RunCommand(ctx, "env", "set", "RS_STORAGE_ACCOUNT", backendStorageAccountName, "--cwd", dir)
require.NoError(t, err)

_, err = cli.RunCommand(ctx, "env", "set", "RS_CONTAINER_NAME", backendContainerName, "--cwd", dir)
require.NoError(t, err)

_, err = cli.RunCommand(ctx, "env", "set", "RS_RESOURCE_GROUP", backendResourceGroupName, "--cwd", dir)
require.NoError(t, err)

// turn alpha feature on
_, err = cli.RunCommand(ctx, "config", "set", "alpha.terraform", "on")
require.NoError(t, err)

t.Logf("Starting infra create\n")
_, err = cli.RunCommandWithStdIn(ctx, stdinForProvision(), "provision", "--cwd", dir)
require.NoError(t, err)

t.Logf("Starting infra delete\n")
_, err = cli.RunCommand(ctx, "down", "--cwd", dir, "--force", "--purge")
require.NoError(t, err)

t.Logf("Done\n")
}

func newRunArgs(cmd string, args ...string) exec.RunArgs {
return exec.NewRunArgs(cmd, args...)
}
Expand Down

0 comments on commit ad53ef2

Please sign in to comment.