Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

provider: support subscription ID hinting when using Azure CLI authentication #26282

Merged
merged 2 commits into from
Jun 10, 2024
Merged
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
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ require (
github.com/google/go-cmp v0.5.9
github.com/google/uuid v1.4.0
github.com/hashicorp/go-azure-helpers v0.69.0
github.com/hashicorp/go-azure-sdk/resource-manager v0.20240604.1114748
github.com/hashicorp/go-azure-sdk/sdk v0.20240604.1114748
github.com/hashicorp/go-azure-sdk/resource-manager v0.20240610.1112704
github.com/hashicorp/go-azure-sdk/sdk v0.20240610.1112704
github.com/hashicorp/go-hclog v1.5.0
github.com/hashicorp/go-multierror v1.1.1
github.com/hashicorp/go-uuid v1.0.3
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,10 @@ github.com/hashicorp/errwrap v1.1.0 h1:OxrOeh75EUXMY8TBjag2fzXGZ40LB6IKw45YeGUDY
github.com/hashicorp/errwrap v1.1.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4=
github.com/hashicorp/go-azure-helpers v0.69.0 h1:JwUWXyDgyr6OafU4CgSvrbEP1wcMjfz4gxRQciDQkBQ=
github.com/hashicorp/go-azure-helpers v0.69.0/go.mod h1:BmbF4JDYXK5sEmFeU5hcn8Br21uElcqLfdQxjatwQKw=
github.com/hashicorp/go-azure-sdk/resource-manager v0.20240604.1114748 h1:sJEw1sYmLpBFUY+4UpE88GimbuAcvmo4ZvTPYenEdp4=
github.com/hashicorp/go-azure-sdk/resource-manager v0.20240604.1114748/go.mod h1:1kTyma4K4ZtSWbtCNQfv8H2NZMsIyF+6S8GRbchmUCI=
github.com/hashicorp/go-azure-sdk/sdk v0.20240604.1114748 h1:DJi4uLd/aUmAcXbTuQXeI6HukIG2ydrnq9aDM2o6D5A=
github.com/hashicorp/go-azure-sdk/sdk v0.20240604.1114748/go.mod h1:Ts5vRL3KPw8iLit+4WSi1hOWlRCx++wJrCkMGj69xBY=
github.com/hashicorp/go-azure-sdk/resource-manager v0.20240610.1112704 h1:APaOXyzHnmXF8SSVck0XJxFe+Y7OUHlGPt3dJ4YnU48=
github.com/hashicorp/go-azure-sdk/resource-manager v0.20240610.1112704/go.mod h1:iRfW3HSkKTYgoqUg9oOOvd3dRDwzNUUbvtLjWUwrWT0=
github.com/hashicorp/go-azure-sdk/sdk v0.20240610.1112704 h1:UDcE9AU+O5sAJobSdjAW0a0K87tiEEtAs3o9axJtpGQ=
github.com/hashicorp/go-azure-sdk/sdk v0.20240610.1112704/go.mod h1:Ts5vRL3KPw8iLit+4WSi1hOWlRCx++wJrCkMGj69xBY=
github.com/hashicorp/go-checkpoint v0.5.0 h1:MFYpPZCnQqQTE18jFwSII6eUQrD/oxMFp3mlgcqk5mU=
github.com/hashicorp/go-checkpoint v0.5.0/go.mod h1:7nfLNL10NsxqO4iWuW6tWW0HjZuDrwkBuEQsVcpCOgg=
github.com/hashicorp/go-cleanhttp v0.5.0/go.mod h1:JpRdi6/HCYpAwUzNwuwqhbovhLtngrth3wmdIIUrZ80=
Expand Down
2 changes: 2 additions & 0 deletions internal/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,8 @@ func providerConfigure(p *schema.Provider) schema.ConfigureContextFunc {

CustomManagedIdentityEndpoint: d.Get("msi_endpoint").(string),

AzureCliSubscriptionIDHint: d.Get("subscription_id").(string),

EnableAuthenticatingUsingClientCertificate: true,
EnableAuthenticatingUsingClientSecret: true,
EnableAuthenticatingUsingAzureCLI: enableAzureCli,
Expand Down
43 changes: 43 additions & 0 deletions internal/provider/provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,49 @@ func TestAccProvider_cliAuth(t *testing.T) {
}
}

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

logging.SetOutput(t)

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

// Support only Azure 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: true,
AzureCliSubscriptionIDHint: d.Get("subscription_id").(string),
}

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
7 changes: 4 additions & 3 deletions vendor/github.com/hashicorp/go-azure-sdk/sdk/auth/auth.go

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.

3 changes: 3 additions & 0 deletions vendor/github.com/hashicorp/go-azure-sdk/sdk/auth/config.go

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.

4 changes: 2 additions & 2 deletions vendor/modules.txt
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ github.com/hashicorp/go-azure-helpers/resourcemanager/tags
github.com/hashicorp/go-azure-helpers/resourcemanager/zones
github.com/hashicorp/go-azure-helpers/sender
github.com/hashicorp/go-azure-helpers/storage
# github.com/hashicorp/go-azure-sdk/resource-manager v0.20240604.1114748
# github.com/hashicorp/go-azure-sdk/resource-manager v0.20240610.1112704
## explicit; go 1.21
github.com/hashicorp/go-azure-sdk/resource-manager/aad/2021-05-01/domainservices
github.com/hashicorp/go-azure-sdk/resource-manager/aadb2c/2021-04-01-preview
Expand Down Expand Up @@ -1116,7 +1116,7 @@ github.com/hashicorp/go-azure-sdk/resource-manager/workloads/2023-04-01/saplands
github.com/hashicorp/go-azure-sdk/resource-manager/workloads/2023-04-01/saprecommendations
github.com/hashicorp/go-azure-sdk/resource-manager/workloads/2023-04-01/sapsupportedsku
github.com/hashicorp/go-azure-sdk/resource-manager/workloads/2023-04-01/sapvirtualinstances
# github.com/hashicorp/go-azure-sdk/sdk v0.20240604.1114748
# github.com/hashicorp/go-azure-sdk/sdk v0.20240610.1112704
## explicit; go 1.21
github.com/hashicorp/go-azure-sdk/sdk/auth
github.com/hashicorp/go-azure-sdk/sdk/auth/autorest
Expand Down
Loading