Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions internal/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,15 @@ func azureProvider(supportLegacyTestSuite bool) *schema.Provider {
Description: "Allow Azure CLI to be used for Authentication.",
},

// Azure Developer CLI specific fields
"use_azd": {
Type: schema.TypeBool,
Optional: true,
Default: true,
DefaultFunc: schema.EnvDefaultFunc("ARM_USE_AZD", true),
Description: "Allow Azure Developer CLI to be used for Authentication.",
},

// Managed Tracking GUID for User-agent
"partner_id": {
Type: schema.TypeString,
Expand Down Expand Up @@ -417,6 +426,7 @@ func providerConfigure(p *schema.Provider) schema.ConfigureContextFunc {

var (
enableAzureCli = d.Get("use_cli").(bool)
enableAzd = d.Get("use_azd").(bool)
enableManagedIdentity = d.Get("use_msi").(bool)
enableOidc = d.Get("use_oidc").(bool)
)
Expand All @@ -441,6 +451,7 @@ func providerConfigure(p *schema.Provider) schema.ConfigureContextFunc {
EnableAuthenticatingUsingClientCertificate: true,
EnableAuthenticatingUsingClientSecret: true,
EnableAuthenticatingUsingAzureCLI: enableAzureCli,
EnableAuthenticatingUsingAzureDeveloperCLI: enableAzd,
EnableAuthenticatingUsingManagedIdentity: enableManagedIdentity,
EnableAuthenticationUsingOIDC: enableOidc,
EnableAuthenticationUsingGitHubOIDC: enableOidc,
Expand Down
40 changes: 40 additions & 0 deletions internal/provider/provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,46 @@ func TestAccProvider_cliAuth(t *testing.T) {
}
}

func TestAccProvider_azdAuth(t *testing.T) {
if os.Getenv("TF_ACC") == "" {
t.Skip("TF_ACC not set")
}

logging.SetOutput(t)

provider := TestAzureProvider()
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Minute)
defer cancel()

// Support only Azure Developer CLI authentication
provider.ConfigureContextFunc = func(ctx context.Context, d *schema.ResourceData) (interface{}, diag.Diagnostics) {
envName := d.Get("environment").(string)
env, err := environments.FromName(envName)
if err != nil {
t.Fatalf("configuring environment %q: %v", envName, err)
}

authConfig := &auth.Credentials{
Environment: *env,
EnableAuthenticatingUsingAzureCLI: false,
EnableAuthenticatingUsingAzureDeveloperCLI: true,
}

return buildClient(ctx, provider, d, authConfig)
}

d := provider.Configure(ctx, terraform.NewResourceConfigRaw(nil))
if d != nil && d.HasError() {
t.Fatalf("err: %+v", d)
}

if errs := testCheckProvider(provider); len(errs) > 0 {
for _, err := range errs {
t.Error(err)
}
}
}

func TestAccProvider_clientCertificateAuth(t *testing.T) {
if os.Getenv("TF_ACC") == "" {
t.Skip("TF_ACC not set")
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions website/docs/guides/azure_cli.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ Terraform supports a number of different methods for authenticating to Azure:
* [Authenticating to Azure using a Service Principal and a Client Certificate](service_principal_client_certificate.html)
* [Authenticating to Azure using a Service Principal and a Client Secret](service_principal_client_secret.html)
* [Authenticating to Azure using a Service Principal and Open ID Connect](service_principal_oidc.html)
* [Authenticating to Azure using the Azure Developer CLI (azd)](azure_developer_cli.html)

---

Expand Down
Loading