summaryrefslogtreecommitdiff
path: root/azuredevops
diff options
context:
space:
mode:
authorAlex Ellwein <alex.ellwein@gmail.com>2023-01-19 18:06:40 +0100
committerAlex Ellwein <alex.ellwein@gmail.com>2023-01-22 17:56:55 +0100
commitdcb719ab459a8dd7bf9cd4f672aa1baa027d50fe (patch)
tree108e682e56f71ad3aebfc349c02a4218d5203ce6 /azuredevops
parente0a312ff6ed509be781c4c3834b690ee6a659cdd (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
Diffstat (limited to 'azuredevops')
-rw-r--r--azuredevops/internal/service/serviceendpoint/resource_serviceendpoint_azurerm.go21
1 files changed, 18 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
}