diff options
| author | xuzhang3 <57888764+xuzhang3@users.noreply.github.com> | 2023-01-29 17:20:53 +0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-01-29 17:20:53 +0800 |
| commit | 48dbbe34522501c1a006d4371df1ec99a162a16d (patch) | |
| tree | 7ac8d105edd96fc0532652ce9920d98806f3eb75 | |
| parent | e0a312ff6ed509be781c4c3834b690ee6a659cdd (diff) | |
| parent | 16b502e0c7dc00746a07ff0995272d22526d4c2d (diff) | |
Merge pull request #699 from aellwein/feature/support-azure-china-in-azurerm-service-endpoint
feat: allow environment specification in AzureRM service endpoint
| -rw-r--r-- | azuredevops/internal/service/serviceendpoint/resource_serviceendpoint_azurerm.go | 21 | ||||
| -rw-r--r-- | website/docs/r/serviceendpoint_azurerm.html.markdown | 13 |
2 files changed, 25 insertions, 9 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..27d49ef5 100644 --- a/website/docs/r/serviceendpoint_azurerm.html.markdown +++ b/website/docs/r/serviceendpoint_azurerm.html.markdown @@ -91,12 +91,13 @@ resource "azuredevops_serviceendpoint_azurerm" "example" { The following arguments are supported: - `project_id` - (Required) The ID of the project. -- `service_endpoint_name` - (Required) The Service Endpoint name. -- `azurerm_spn_tenantid` - (Required) The tenant id if the service principal. -- `azurerm_management_group_id` - (Optional) The management group Id of the Azure targets. -- `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. +- `service_endpoint_name` - (Required) The Service Endpoint Name. +- `azurerm_spn_tenantid` - (Required) The Tenant ID if the service principal. +- `azurerm_management_group_id` - (Optional) The Management group ID of the Azure targets. +- `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) The Cloud Environment to use. Defaults to `AzureCloud`. Possible values are `AzureCloud`, `AzureChinaCloud`. Changing this forces a new resource to be created. ~> **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. |
