From dcb719ab459a8dd7bf9cd4f672aa1baa027d50fe Mon Sep 17 00:00:00 2001 From: Alex Ellwein Date: Thu, 19 Jan 2023 18:06:40 +0100 Subject: 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 --- .../resource_serviceendpoint_azurerm.go | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) (limited to 'azuredevops') 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 } -- cgit v1.2.3