-
Notifications
You must be signed in to change notification settings - Fork 15
feat: Add support for sovereign cloud environments #95
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
base: main
Are you sure you want to change the base?
Changes from all commits
2097f9d
22bebbc
0bb10ba
c854094
78dad39
4a93fea
5fe9a56
d769290
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -26,6 +26,16 @@ import ( | |
|
|
||
| var _ provider.Provider = &MSGraphProvider{} | ||
|
|
||
| var validEnvironments = []string{ | ||
| "global", | ||
| "public", | ||
| "usgovernmentl4", | ||
| "usgovernment", | ||
| "usgovernmentl5", | ||
| "dod", | ||
| "china", | ||
| } | ||
|
|
||
| type MSGraphProvider struct{} | ||
|
|
||
| type MSGraphProviderModel struct { | ||
|
|
@@ -47,6 +57,7 @@ type MSGraphProviderModel struct { | |
| UsePowerShell types.Bool `tfsdk:"use_powershell"` | ||
| UseMSI types.Bool `tfsdk:"use_msi"` | ||
| UseAKSWorkloadIdentity types.Bool `tfsdk:"use_aks_workload_identity"` | ||
| Environment types.String `tfsdk:"environment"` | ||
| PartnerID types.String `tfsdk:"partner_id"` | ||
| CustomCorrelationRequestID types.String `tfsdk:"custom_correlation_request_id"` | ||
| DisableCorrelationRequestID types.Bool `tfsdk:"disable_correlation_request_id"` | ||
|
|
@@ -227,6 +238,15 @@ func (p *MSGraphProvider) Schema(ctx context.Context, req provider.SchemaRequest | |
| MarkdownDescription: "Should AKS Workload Identity be used for Authentication? This can also be sourced from the `ARM_USE_AKS_WORKLOAD_IDENTITY` Environment Variable. Defaults to `false`. When set, `client_id`, `tenant_id` and `oidc_token_file_path` will be detected from the environment and do not need to be specified.", | ||
| }, | ||
|
|
||
| // Cloud environment | ||
| "environment": schema.StringAttribute{ | ||
| Optional: true, | ||
| Validators: []validator.String{ | ||
| stringvalidator.OneOf(validEnvironments...), | ||
| }, | ||
| MarkdownDescription: "The cloud environment which should be used. Possible values are: `global` (also `public`), `usgovernmentl4` (also `usgovernment`), `usgovernmentl5` (also `dod`), and `china`. Defaults to `global`. This can also be sourced from the `ARM_ENVIRONMENT` environment variable.", | ||
| }, | ||
|
|
||
| // Managed Tracking GUID for User-agent | ||
| "partner_id": schema.StringAttribute{ | ||
| Optional: true, | ||
|
|
@@ -418,6 +438,27 @@ func (p *MSGraphProvider) Configure(ctx context.Context, req provider.ConfigureR | |
| } | ||
| } | ||
|
|
||
| if model.Environment.IsNull() { | ||
| if v := os.Getenv("ARM_ENVIRONMENT"); v != "" { | ||
| v = strings.ToLower(v) | ||
| valid := false | ||
| for _, env := range validEnvironments { | ||
| if v == env { | ||
| valid = true | ||
| break | ||
| } | ||
| } | ||
| if !valid { | ||
| resp.Diagnostics.AddError("Invalid `environment` value", | ||
| fmt.Sprintf("The value %q provided via ARM_ENVIRONMENT is not a valid environment. Valid values are: global (also public), usgovernmentl4 (also usgovernment), usgovernmentl5 (also dod), china", v)) | ||
| return | ||
| } | ||
| model.Environment = types.StringValue(v) | ||
| } else { | ||
| model.Environment = types.StringValue(clients.DefaultEnvironment) | ||
| } | ||
| } | ||
|
|
||
| option := azidentity.DefaultAzureCredentialOptions{ | ||
| TenantID: model.TenantID.ValueString(), | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The |
||
| } | ||
|
|
@@ -435,6 +476,7 @@ func (p *MSGraphProvider) Configure(ctx context.Context, req provider.ConfigureR | |
| CustomCorrelationRequestID: model.CustomCorrelationRequestID.ValueString(), | ||
| CloudCfg: cloud.Configuration{}, | ||
| TenantId: model.TenantID.ValueString(), | ||
| Environment: model.Environment.ValueString(), | ||
| } | ||
| client := &clients.Client{} | ||
| if err = client.Build(ctx, copt); err != nil { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use cloud.Configuration as the single source of truth per environment
Replace the map[string]string endpoint map with a map[string]cloud.Configuration that embeds MS Graph as a ServiceConfiguration:
So it could remove the CloudCfg + Environment on clients.Option.
And use use explicit Audience + "/.default" instead of endpoint + "/.default".