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

dependencies: update go-azure-sdk to v0.20250131.1134653 #28674

Merged
merged 13 commits into from
Feb 6, 2025
Merged
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.6.0
github.com/google/uuid v1.6.0
github.com/hashicorp/go-azure-helpers v0.71.0
github.com/hashicorp/go-azure-sdk/resource-manager v0.20250115.1141151
github.com/hashicorp/go-azure-sdk/sdk v0.20250115.1141151
github.com/hashicorp/go-azure-sdk/resource-manager v0.20250131.1134653
github.com/hashicorp/go-azure-sdk/sdk v0.20250131.1134653
github.com/hashicorp/go-hclog v1.6.3
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 @@ -94,10 +94,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.71.0 h1:ra3aIRzg01g6MLKQ+yABcb6WJtrqRUDDgyuPLmyZ9lY=
github.com/hashicorp/go-azure-helpers v0.71.0/go.mod h1:BmbF4JDYXK5sEmFeU5hcn8Br21uElcqLfdQxjatwQKw=
github.com/hashicorp/go-azure-sdk/resource-manager v0.20250115.1141151 h1:bPvF5BpQiyd6lAcS+YEcYZOPPsszEV2ElwtrlxjF6aM=
github.com/hashicorp/go-azure-sdk/resource-manager v0.20250115.1141151/go.mod h1:h5yWlutmMw0h3tvfQ8hFoI37CT51ybYfqDfIFFiI1tg=
github.com/hashicorp/go-azure-sdk/sdk v0.20250115.1141151 h1:1Z1Y7QIHf1J9rzJTrRtgOhQYldhF1bOqny4uYn8aj/A=
github.com/hashicorp/go-azure-sdk/sdk v0.20250115.1141151/go.mod h1:oI5R0fTbBx3K/sJBK5R/OlEy8ozdQjvctxVU9v3EDkc=
github.com/hashicorp/go-azure-sdk/resource-manager v0.20250131.1134653 h1:KuDCZKWoOByX5MUyFRNWLl4Gy6wpZCwJ7Ez1mbUwouo=
github.com/hashicorp/go-azure-sdk/resource-manager v0.20250131.1134653/go.mod h1:AawbnS/Kkp/IURMJVzmvD+Co2zK91lKFqYYDbenCpGU=
github.com/hashicorp/go-azure-sdk/sdk v0.20250131.1134653 h1:Bd+glHUD1mdal1zn0NgoS4wDFhUB8Qfw61j0nZEnC5A=
github.com/hashicorp/go-azure-sdk/sdk v0.20250131.1134653/go.mod h1:oI5R0fTbBx3K/sJBK5R/OlEy8ozdQjvctxVU9v3EDkc=
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
22 changes: 11 additions & 11 deletions internal/provider/framework/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,11 @@ func (p *ProviderConfig) Load(ctx context.Context, data *ProviderModel, tfVersio
enableOIDC := getEnvBoolIfValueAbsent(data.UseOIDC, "ARM_USE_OIDC") || getEnvBoolIfValueAbsent(data.UseAKSWorkloadIdentity, "ARM_USE_AKS_WORKLOAD_IDENTITY")
auxTenants := getEnvListOfStringsIfAbsent(data.AuxiliaryTenantIds, "ARM_AUXILIARY_TENANT_IDS", ";")

oidcReqURL := getEnvStringOrDefault(data.OIDCRequestURL, "ARM_OIDC_REQUEST_URL", "")
if oidcReqURL == "" {
oidcReqURL = getEnvStringOrDefault(data.OIDCRequestURL, "ACTIONS_ID_TOKEN_REQUEST_URL", "")
}
oidcReqToken := getEnvStringOrDefault(data.OIDCRequestToken, "ARM_OIDC_REQUEST_TOKEN", "")
if oidcReqToken == "" {
oidcReqToken = getEnvStringOrDefault(data.OIDCRequestToken, "ACTIONS_ID_TOKEN_REQUEST_TOKEN", "")
}
oidcReqURL := getEnvStringsOrDefault(data.OIDCRequestURL, []string{"ARM_OIDC_REQUEST_URL", "ACTIONS_ID_TOKEN_REQUEST_URL", "SYSTEM_OIDCREQUESTURI"}, "")
oidcReqToken := getEnvStringsOrDefault(data.OIDCRequestToken, []string{"ARM_OIDC_REQUEST_TOKEN", "ACTIONS_ID_TOKEN_REQUEST_TOKEN", "SYSTEM_ACCESSTOKEN"}, "")

// ARM_OIDC_AZURE_SERVICE_CONNECTION_ID is to be compatible with `azapi` provider.
adoPipelineServiceConnectionID := getEnvStringsOrDefault(data.ADOPipelineServiceConnectionID, []string{"ARM_ADO_PIPELINE_SERVICE_CONNECTION_ID", "ARM_OIDC_AZURE_SERVICE_CONNECTION_ID"}, "")

authConfig := &auth.Credentials{
Environment: *env,
Expand All @@ -98,9 +95,11 @@ func (p *ProviderConfig) Load(ctx context.Context, data *ProviderModel, tfVersio
ClientCertificatePassword: getEnvStringOrDefault(data.ClientCertificatePassword, "ARM_CLIENT_CERTIFICATE_PASSWORD", ""),
ClientSecret: *clientSecret,

OIDCAssertionToken: *oidcToken,
GitHubOIDCTokenRequestURL: oidcReqURL,
GitHubOIDCTokenRequestToken: oidcReqToken,
OIDCAssertionToken: *oidcToken,
OIDCTokenRequestURL: oidcReqURL,
OIDCTokenRequestToken: oidcReqToken,

ADOPipelineServiceConnectionID: adoPipelineServiceConnectionID,

CustomManagedIdentityEndpoint: getEnvStringOrDefault(data.MSIEndpoint, "ARM_MSI_ENDPOINT", ""),

Expand All @@ -110,6 +109,7 @@ func (p *ProviderConfig) Load(ctx context.Context, data *ProviderModel, tfVersio
EnableAuthenticatingUsingClientSecret: true,
EnableAuthenticationUsingOIDC: enableOIDC,
EnableAuthenticationUsingGitHubOIDC: enableOIDC,
EnableAuthenticationUsingADOPipelineOIDC: enableOIDC,
EnableAuthenticatingUsingAzureCLI: getEnvBoolOrDefault(data.UseCLI, "ARM_USE_CLI", true),
EnableAuthenticatingUsingManagedIdentity: getEnvBoolOrDefault(data.UseMSI, "ARM_USE_MSI", false),
}
Expand Down
20 changes: 17 additions & 3 deletions internal/provider/framework/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,8 @@ func getEnvStringIfValueAbsent(val types.String, envVar string) string {
return val.ValueString()
}

// getEnvStringIfValueAbsent takes a Framework StringValue and a corresponding Environment Variable name and returns
// either the string value set in the StringValue if not Null / Unknown _or_ the os.GetEnv() value of the Environment
// Variable provided. If both of these are empty, an empty string "" is returned.
// getEnvStringOrDefault is similar to getEnvStringIfValueAbsent, except when both the value and the env var are absent,
// the defaultValue will be used, instead of the empty string.
func getEnvStringOrDefault(val types.String, envVar string, defaultValue string) string {
if val.IsNull() || val.IsUnknown() {
if v := os.Getenv(envVar); v != "" {
Expand All @@ -138,6 +137,21 @@ func getEnvStringOrDefault(val types.String, envVar string, defaultValue string)
return val.ValueString()
}

// getEnvStringsOrDefault is similar to getEnvStringOrDefault, except an array of env vars are checked, where the first non-empty
// env var will be returned, if any.
func getEnvStringsOrDefault(val types.String, envVars []string, defaultValue string) string {
if val.IsNull() || val.IsUnknown() {
for _, envVar := range envVars {
if v := os.Getenv(envVar); v != "" {
return os.Getenv(envVar)
}
}
return defaultValue
}

return val.ValueString()
}

// getEnvBoolIfValueAbsent takes a Framework BoolValue and a corresponding Environment Variable name and returns
// one of the following in priority order:
// 1 - the Boolean value set in the BoolValue if this is not Null / Unknown.
Expand Down
59 changes: 30 additions & 29 deletions internal/provider/framework/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,35 +9,36 @@ import (
)

type ProviderModel struct {
SubscriptionId types.String `tfsdk:"subscription_id"`
ClientId types.String `tfsdk:"client_id"`
ClientIdFilePath types.String `tfsdk:"client_id_file_path"`
TenantId types.String `tfsdk:"tenant_id"`
AuxiliaryTenantIds types.List `tfsdk:"auxiliary_tenant_ids"`
Environment types.String `tfsdk:"environment"`
MetaDataHost types.String `tfsdk:"metadata_host"`
ClientCertificate types.String `tfsdk:"client_certificate"`
ClientCertificatePath types.String `tfsdk:"client_certificate_path"`
ClientCertificatePassword types.String `tfsdk:"client_certificate_password"`
ClientSecret types.String `tfsdk:"client_secret"`
ClientSecretFilePath types.String `tfsdk:"client_secret_file_path"`
OIDCRequestToken types.String `tfsdk:"oidc_request_token"`
OIDCRequestURL types.String `tfsdk:"oidc_request_url"`
OIDCToken types.String `tfsdk:"oidc_token"`
OIDCTokenFilePath types.String `tfsdk:"oidc_token_file_path"`
UseOIDC types.Bool `tfsdk:"use_oidc"`
UseMSI types.Bool `tfsdk:"use_msi"`
MSIEndpoint types.String `tfsdk:"msi_endpoint"`
UseCLI types.Bool `tfsdk:"use_cli"`
UseAKSWorkloadIdentity types.Bool `tfsdk:"use_aks_workload_identity"`
PartnerId types.String `tfsdk:"partner_id"`
DisableCorrelationRequestId types.Bool `tfsdk:"disable_correlation_request_id"`
DisableTerraformPartnerId types.Bool `tfsdk:"disable_terraform_partner_id"`
StorageUseAzureAD types.Bool `tfsdk:"storage_use_azuread"`
Features types.List `tfsdk:"features"`
SkipProviderRegistration types.Bool `tfsdk:"skip_provider_registration"` // TODO - Remove in 5.0
ResourceProviderRegistrations types.String `tfsdk:"resource_provider_registrations"`
ResourceProvidersToRegister types.List `tfsdk:"resource_providers_to_register"`
SubscriptionId types.String `tfsdk:"subscription_id"`
ClientId types.String `tfsdk:"client_id"`
ClientIdFilePath types.String `tfsdk:"client_id_file_path"`
TenantId types.String `tfsdk:"tenant_id"`
AuxiliaryTenantIds types.List `tfsdk:"auxiliary_tenant_ids"`
Environment types.String `tfsdk:"environment"`
MetaDataHost types.String `tfsdk:"metadata_host"`
ClientCertificate types.String `tfsdk:"client_certificate"`
ClientCertificatePath types.String `tfsdk:"client_certificate_path"`
ClientCertificatePassword types.String `tfsdk:"client_certificate_password"`
ClientSecret types.String `tfsdk:"client_secret"`
ClientSecretFilePath types.String `tfsdk:"client_secret_file_path"`
ADOPipelineServiceConnectionID types.String `tfsdk:"ado_pipeline_service_connection_id"`
OIDCRequestToken types.String `tfsdk:"oidc_request_token"`
OIDCRequestURL types.String `tfsdk:"oidc_request_url"`
OIDCToken types.String `tfsdk:"oidc_token"`
OIDCTokenFilePath types.String `tfsdk:"oidc_token_file_path"`
UseOIDC types.Bool `tfsdk:"use_oidc"`
UseMSI types.Bool `tfsdk:"use_msi"`
MSIEndpoint types.String `tfsdk:"msi_endpoint"`
UseCLI types.Bool `tfsdk:"use_cli"`
UseAKSWorkloadIdentity types.Bool `tfsdk:"use_aks_workload_identity"`
PartnerId types.String `tfsdk:"partner_id"`
DisableCorrelationRequestId types.Bool `tfsdk:"disable_correlation_request_id"`
DisableTerraformPartnerId types.Bool `tfsdk:"disable_terraform_partner_id"`
StorageUseAzureAD types.Bool `tfsdk:"storage_use_azuread"`
Features types.List `tfsdk:"features"`
SkipProviderRegistration types.Bool `tfsdk:"skip_provider_registration"` // TODO - Remove in 5.0
ResourceProviderRegistrations types.String `tfsdk:"resource_provider_registrations"`
ResourceProvidersToRegister types.List `tfsdk:"resource_providers_to_register"`
}

type Features struct {
Expand Down
8 changes: 7 additions & 1 deletion internal/provider/framework/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,11 +125,17 @@ func (p *azureRmFrameworkProvider) Schema(_ context.Context, _ provider.SchemaRe
Description: "The path to a file containing the Client Secret which should be used. For use When authenticating as a Service Principal using a Client Secret.",
},

// OIDC specifc fields
"ado_pipeline_service_connection_id": schema.StringAttribute{
Optional: true,
Description: "The Azure DevOps Pipeline Service Connection ID.",
},

// OIDC specific fields
"oidc_request_token": schema.StringAttribute{
Optional: true,
Description: "The bearer token for the request to the OIDC provider. For use when authenticating as a Service Principal using OpenID Connect.",
},

"oidc_request_url": schema.StringAttribute{
Optional: true,
Description: "The URL for the OIDC provider from which to request an ID token. For use when authenticating as a Service Principal using OpenID Connect.",
Expand Down
21 changes: 16 additions & 5 deletions internal/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -237,16 +237,24 @@ func azureProvider(supportLegacyTestSuite bool) *schema.Provider {
Description: "Allow OpenID Connect to be used for authentication",
},

"ado_pipeline_service_connection_id": {
Type: schema.TypeString,
Optional: true,
DefaultFunc: schema.MultiEnvDefaultFunc([]string{"ARM_ADO_PIPELINE_SERVICE_CONNECTION_ID", "ARM_OIDC_AZURE_SERVICE_CONNECTION_ID"}, nil),
Description: "The Azure DevOps Pipeline Service Connection ID.",
},

"oidc_request_token": {
Type: schema.TypeString,
Optional: true,
DefaultFunc: schema.MultiEnvDefaultFunc([]string{"ARM_OIDC_REQUEST_TOKEN", "ACTIONS_ID_TOKEN_REQUEST_TOKEN"}, nil),
DefaultFunc: schema.MultiEnvDefaultFunc([]string{"ARM_OIDC_REQUEST_TOKEN", "ACTIONS_ID_TOKEN_REQUEST_TOKEN", "SYSTEM_ACCESSTOKEN"}, nil),
Description: "The bearer token for the request to the OIDC provider. For use when authenticating as a Service Principal using OpenID Connect.",
},

"oidc_request_url": {
Type: schema.TypeString,
Optional: true,
DefaultFunc: schema.MultiEnvDefaultFunc([]string{"ARM_OIDC_REQUEST_URL", "ACTIONS_ID_TOKEN_REQUEST_URL"}, nil),
DefaultFunc: schema.MultiEnvDefaultFunc([]string{"ARM_OIDC_REQUEST_URL", "ACTIONS_ID_TOKEN_REQUEST_URL", "SYSTEM_OIDCREQUESTURI"}, nil),
Description: "The URL for the OIDC provider from which to request an ID token. For use when authenticating as a Service Principal using OpenID Connect.",
},

Expand Down Expand Up @@ -466,9 +474,11 @@ func providerConfigure(p *schema.Provider) schema.ConfigureContextFunc {
ClientCertificatePassword: d.Get("client_certificate_password").(string),
ClientSecret: *clientSecret,

OIDCAssertionToken: *oidcToken,
GitHubOIDCTokenRequestURL: d.Get("oidc_request_url").(string),
GitHubOIDCTokenRequestToken: d.Get("oidc_request_token").(string),
OIDCAssertionToken: *oidcToken,
OIDCTokenRequestURL: d.Get("oidc_request_url").(string),
OIDCTokenRequestToken: d.Get("oidc_request_token").(string),

ADOPipelineServiceConnectionID: d.Get("ado_pipeline_service_connection_id").(string),

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

Expand All @@ -480,6 +490,7 @@ func providerConfigure(p *schema.Provider) schema.ConfigureContextFunc {
EnableAuthenticatingUsingManagedIdentity: enableManagedIdentity,
EnableAuthenticationUsingOIDC: enableOidc,
EnableAuthenticationUsingGitHubOIDC: enableOidc,
EnableAuthenticationUsingADOPipelineOIDC: enableOidc,
}

return buildClient(ctx, p, d, authConfig)
Expand Down
67 changes: 65 additions & 2 deletions internal/provider/provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -679,8 +679,8 @@ func TestAccProvider_githubOidcAuth(t *testing.T) {
Environment: *env,
TenantID: *tenantId,
ClientID: *clientId,
GitHubOIDCTokenRequestToken: d.Get("oidc_request_token").(string),
GitHubOIDCTokenRequestURL: d.Get("oidc_request_url").(string),
OIDCTokenRequestToken: d.Get("oidc_request_token").(string),
OIDCTokenRequestURL: d.Get("oidc_request_url").(string),
EnableAuthenticationUsingGitHubOIDC: true,
}

Expand All @@ -699,6 +699,69 @@ func TestAccProvider_githubOidcAuth(t *testing.T) {
}
}

func TestAccProvider_adoOidcAuth(t *testing.T) {
if os.Getenv("TF_ACC") == "" {
t.Skip("TF_ACC not set")
}
if os.Getenv("SYSTEM_ACCESSTOKEN") == "" {
t.Skip("SYSTEM_ACCESSTOKEN not set")
}
if os.Getenv("SYSTEM_OIDCREQUESTURI") == "" {
t.Skip("SYSTEM_OIDCREQUESTURI not set")
}
if os.Getenv("ARM_ADO_PIPELINE_SERVICE_CONNECTION_ID") == "" {
t.Skip("ARM_ADO_PIPELINE_SERVICE_CONNECTION_ID")
}

logging.SetOutput(t)

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

// Support only ADO OIDC 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)
}

clientId, err := getClientId(d)
if err != nil {
return nil, diag.FromErr(err)
}

tenantId, err := getTenantId(d)
if err != nil {
return nil, diag.FromErr(err)
}

authConfig := &auth.Credentials{
Environment: *env,
TenantID: *tenantId,
ClientID: *clientId,
OIDCTokenRequestToken: d.Get("oidc_request_token").(string),
OIDCTokenRequestURL: d.Get("oidc_request_url").(string),
ADOPipelineServiceConnectionID: d.Get("ado_pipeline_service_connection_id").(string),
EnableAuthenticationUsingADOPipelineOIDC: 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_aksWorkloadIdentityAuth(t *testing.T) {
if os.Getenv("TF_ACC") == "" {
t.Skip("TF_ACC not set")
Expand Down
34 changes: 7 additions & 27 deletions internal/services/connections/api_connection_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"log"
"time"

"github.com/hashicorp/go-azure-helpers/lang/pointer"
"github.com/hashicorp/go-azure-helpers/lang/response"
"github.com/hashicorp/go-azure-helpers/resourcemanager/commonschema"
"github.com/hashicorp/go-azure-helpers/resourcemanager/location"
Expand All @@ -20,7 +21,6 @@ import (
"github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk"
"github.com/hashicorp/terraform-provider-azurerm/internal/tf/validation"
"github.com/hashicorp/terraform-provider-azurerm/internal/timeouts"
"github.com/hashicorp/terraform-provider-azurerm/utils"
)

func resourceConnection() *pluginsdk.Resource {
Expand Down Expand Up @@ -116,20 +116,19 @@ func resourceConnectionCreate(d *schema.ResourceData, meta interface{}) error {
return fmt.Errorf("parsing `managed_app_id`: %+v", err)
}
location := location.Normalize(managedAppId.LocationName)
parameterValues := expandConnectionParameterValues(d.Get("parameter_values").(map[string]interface{}))
model := connections.ApiConnectionDefinition{
Location: utils.String(location),
Location: pointer.To(location),
Properties: &connections.ApiConnectionDefinitionProperties{
Api: &connections.ApiReference{
Id: utils.String(managedAppId.ID()),
Id: pointer.To(managedAppId.ID()),
},
DisplayName: utils.String(d.Get("display_name").(string)),
ParameterValues: parameterValues,
DisplayName: pointer.To(d.Get("display_name").(string)),
ParameterValues: pointer.To(d.Get("parameter_values").(map[string]interface{})),
},
Tags: tags.Expand(d.Get("tags").(map[string]interface{})),
}
if v := d.Get("display_name").(string); v != "" {
model.Properties.DisplayName = utils.String(v)
model.Properties.DisplayName = pointer.To(v)
}

if _, err := client.CreateOrUpdate(ctx, id, model); err != nil {
Expand Down Expand Up @@ -172,8 +171,7 @@ func resourceConnectionRead(d *schema.ResourceData, meta interface{}) error {
}
d.Set("managed_api_id", apiId)

parameterValues := flattenConnectionParameterValues(props.ParameterValues)
if err := d.Set("parameter_values", parameterValues); err != nil {
if err := d.Set("parameter_values", props.ParameterValues); err != nil {
return fmt.Errorf("setting `parameter_values`: %+v", err)
}
}
Expand Down Expand Up @@ -229,21 +227,3 @@ func resourceConnectionDelete(d *schema.ResourceData, meta interface{}) error {

return nil
}

func expandConnectionParameterValues(input map[string]interface{}) *map[string]string {
parameterValues := make(map[string]string)
for k, v := range input {
parameterValues[k] = v.(string)
}
return &parameterValues
}

func flattenConnectionParameterValues(input *map[string]string) map[string]interface{} {
parameterValues := make(map[string]interface{})
if input != nil {
for k, v := range *input {
parameterValues[k] = v
}
}
return parameterValues
}
Loading
Loading