diff options
| author | Alex Ellwein <alex.ellwein@gmail.com> | 2023-01-19 18:06:40 +0100 |
|---|---|---|
| committer | Alex Ellwein <alex.ellwein@gmail.com> | 2023-01-22 17:56:55 +0100 |
| commit | dcb719ab459a8dd7bf9cd4f672aa1baa027d50fe (patch) | |
| tree | 108e682e56f71ad3aebfc349c02a4218d5203ce6 | |
| parent | e0a312ff6ed509be781c4c3834b690ee6a659cdd (diff) | |
feat: allow environment specification in AzureRM service endpoint
In order to allow creation of AzureRM service endpoints in Azure
China cloud, environment and different endpoint URL must be used.
Refs: microsoft/terraform-provider-azuredevops#27
| -rw-r--r-- | azuredevops/internal/service/serviceendpoint/resource_serviceendpoint_azurerm.go | 21 | ||||
| -rw-r--r-- | website/docs/r/serviceendpoint_azurerm.html.markdown | 1 |
2 files changed, 19 insertions, 3 deletions
diff --git a/azuredevops/internal/service/serviceendpoint/resource_serviceendpoint_azurerm.go b/azuredevops/internal/service/serviceendpoint/resource_serviceendpoint_azurerm.go index ded0352d..7660f7f7 100644 --- a/azuredevops/internal/service/serviceendpoint/resource_serviceendpoint_azurerm.go +++ b/azuredevops/internal/service/serviceendpoint/resource_serviceendpoint_azurerm.go @@ -6,6 +6,7 @@ import ( "github.com/google/uuid" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" "github.com/microsoft/azure-devops-go-api/azuredevops/v6/serviceendpoint" "github.com/microsoft/terraform-provider-azuredevops/azuredevops/internal/utils/converter" "github.com/microsoft/terraform-provider-azuredevops/azuredevops/internal/utils/tfhelper" @@ -56,7 +57,14 @@ func ResourceServiceEndpointAzureRM() *schema.Resource { }, }, } - + r.Schema["environment"] = &schema.Schema{ + Type: schema.TypeString, + Optional: true, + ForceNew: true, + Description: "Environment (Azure Cloud type)", + Default: "AzureCloud", + ValidateFunc: validation.StringInSlice([]string{"AzureCloud", "AzureChinaCloud"}, false), + } return r } @@ -70,6 +78,7 @@ func expandServiceEndpointAzureRM(d *schema.ResourceData) (*serviceendpoint.Serv mgmtGrpId := d.Get("azurerm_management_group_id").(string) mgmtGrpName := d.Get("azurerm_management_group_name").(string) + environment := d.Get("environment").(string) scopeLevelMap := map[string][]string{ "subscription": {subId, subName}, @@ -101,9 +110,15 @@ func expandServiceEndpointAzureRM(d *schema.ResourceData) (*serviceendpoint.Serv }, Scheme: converter.String("ServicePrincipal"), } + var endpointUrl string + if environment == "AzureCloud" { + endpointUrl = "https://management.azure.com/" + } else if environment == "AzureChinaCloud" { + endpointUrl = "https://management.chinacloudapi.cn/" + } serviceEndpoint.Data = &map[string]string{ "creationMode": "Automatic", - "environment": "AzureCloud", + "environment": environment, } if scopeLevel == "Subscription" || scopeLevel == "ResourceGroup" { @@ -130,7 +145,7 @@ func expandServiceEndpointAzureRM(d *schema.ResourceData) (*serviceendpoint.Serv } serviceEndpoint.Type = converter.String("azurerm") - serviceEndpoint.Url = converter.String("https://management.azure.com/") + serviceEndpoint.Url = converter.String(endpointUrl) return serviceEndpoint, projectID, nil } diff --git a/website/docs/r/serviceendpoint_azurerm.html.markdown b/website/docs/r/serviceendpoint_azurerm.html.markdown index 0befcca2..c8a331e4 100644 --- a/website/docs/r/serviceendpoint_azurerm.html.markdown +++ b/website/docs/r/serviceendpoint_azurerm.html.markdown @@ -97,6 +97,7 @@ The following arguments are supported: - `azurerm_management_group_name` - (Optional) The management group Name of the targets. - `azurerm_subscription_id` - (Optional) The subscription Id of the Azure targets. - `azurerm_subscription_name` - (Optional) The subscription Name of the targets. +- `environment` - (Optional) cloud environment to use, can be `AzureCloud` (which is default) or `AzureChinaCloud`. ~> **NOTE:** One of either `Subscription` scoped i.e. `azurerm_subscription_id`, `azurerm_subscription_name` or `ManagementGroup` scoped i.e. `azurerm_management_group_id`, `azurerm_management_group_name` values must be specified. |
