Azure / azure-dev

A developer CLI that reduces the time it takes for you to get started on Azure. The Azure Developer CLI (azd) provides a set of developer-friendly commands that map to key stages in your workflow - code, build, deploy, monitor, repeat.
https://aka.ms/azd
MIT License
412 stars 201 forks source link

ci: Re-enable Terraform Tests #4564

Open ellismg opened 4 hours ago

ellismg commented 4 hours ago

Our terraform tests in CI are currently disabled (in the case of the inner-loop build-cli leg) or failing (in the case of template tests) since moving to the TME environment since we need to use OIDC to connect.

This bug tracks re-enabling these disabled tests.

ellismg commented 4 hours ago

Trying to re-enable the remote state terraform tests failed with this error coming back from TF:

=== FAIL: cli/azd/test/functional Test_CLI_InfraCreateAndDeleteResourceTerraformRemote (113.42s)
    cli_test.go:833: DIR: /tmp/Test_CLI_InfraCreateAndDeleteResourceTerraformRemote560961891/001
    cli_test.go:841: AZURE_ENV_NAME: azdtest-lb61dc9
2024/11/15 19:05:09 Run exec: 'az group create --name rs-azdtest-lb61dc9 --location eastus2' , exit code: 0
2024/11/15 19:05:34 Run exec: 'az storage account create --resource-group rs-azdtest-lb61dc9 --name azdtestlb61dc9 --sku Standard_LRS --encryption-services blob' , exit code: 0
2024/11/15 19:05:36 Run exec: 'az storage account keys list --resource-group rs-azdtest-lb61dc9 --account-name azdtestlb61dc9 --query [0].value -o tsv' , exit code: 0
2024/11/15 19:05:37 Run exec: 'az storage container create --name tfstate --account-name azdtestlb61dc9 --account-key <redacted>' , exit code: 0
    cli.go:241: 17ms [stdout] 
    cli.go:241: 19ms [stdout] Initializing an app to run on Azure (azd init)
    cli.go:241: 19ms [stdout] 
    cli.go:241: 37ms [stdout] Enter a new environment name: 
    cli.go:241: 42ms [stdout] SUCCESS: Initialized environment azdtest-lb61dc9.
    cli_test.go:903: Starting infra create
    cli.go:241: 20ms [stdout] 
    cli.go:241: 24ms [stdout] Provisioning Azure resources (azd provision)
    cli.go:241: 27ms [stdout] Provisioning Azure resources can take some time.
    cli.go:241: 27ms [stdout] 
    cli.go:241: 1.489s [stdout] Select an Azure Subscription to use (or hit enter to use the default  1. Azure SDK Test Resources - TME (4d042dc6-fe17-4698-a23f-ec6a8d1e98f4)): Reading subscription and location from environment...
    cli.go:241: 4.676s [stdout] Subscription: Azure SDK Test Resources - TME (4d042dc6-fe17-4698-a23f-ec6a8d1e98f4)
    cli.go:241: 4.677s [stdout] Location: East US 2
    cli.go:241: 4.677s [stdout] 
    cli.go:241: 4.677s [stdout] Locating plan file...
    cli.go:241: 4.678s [stdout] Generating terraform backend config file...
    cli.go:241: 5.475s [stdout] Initializing the backend...
    cli.go:241: 6.184s [stderr] ╷
    cli.go:241: 6.197s [stderr] │ Error: Error building ARM Config: Authenticating using the Azure CLI is only supported as a User (not a Service Principal).
    cli.go:241: 6.198s [stderr] │ 
    cli.go:241: 6.201s [stdout] 
    cli.go:241: 6.207s [stdout] ERROR: deployment failed: error deploying infrastructure: terraform init failed:  , err: failed running terraform init:  (exit code: 1)
    cli.go:241: 6.214s [stderr] │ To authenticate to Azure using a Service Principal, you can use the separate 'Authenticate using a Service Principal'
    cli.go:241: 6.214s [stdout] TraceID: 957c3d18ecfa564f6d182e0f475dae9d
    cli.go:241: 6.222s [stderr] │ auth method - instructions for which can be found here: https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/guides/service_principal_client_secret
    cli.go:241: 6.223s [stderr] │ 
    cli.go:241: 6.228s [stderr] │ Alternatively you can authenticate using the Azure CLI by using a User Account.
    cli.go:241: 6.229s [stderr] │ 
    cli.go:241: 6.23s [stderr] │ 
    cli.go:241: 6.231s [stderr] ╵
    cli_test.go:905: 
            Error Trace:    /mnt/vss/_work/1/s/cli/azd/test/functional/cli_test.go:905
            Error:          Received unexpected error:
                            command 'azd provision --cwd /tmp/Test_CLI_InfraCreateAndDeleteResourceTerraformRemote560961891/001 in /tmp/Test_CLI_InfraCreateAndDeleteResourceTerraformRemote560961891/001' had non-zero exit code: exit status 1
            Test:           Test_CLI_InfraCreateAndDeleteResourceTerraformRemote
2024/11/15 19:07:01 Run exec: 'az group delete --name rs-azdtest-lb61dc9 --yes' , exit code: 0

I think this is an auth problem with the remote state provider, not the azure RM provider, since the other terraform test passed without issue. Keeping this skipped against the bug for now.