diff --git a/.github/labeler-issue-triage.yml b/.github/labeler-issue-triage.yml index 114f21bfa4ae..3e60d8f97fb8 100644 --- a/.github/labeler-issue-triage.yml +++ b/.github/labeler-issue-triage.yml @@ -141,6 +141,9 @@ service/event-grid: service/event-hubs: - '### (|New or )Affected Resource\(s\)\/Data Source\(s\)((.|\n)*)azurerm_eventhub((.|\n)*)###' +service/extendedlocation: + - '### (|New or )Affected Resource\(s\)\/Data Source\(s\)((.|\n)*)azurerm_custom_location((.|\n)*)###' + service/firewall: - '### (|New or )Affected Resource\(s\)\/Data Source\(s\)((.|\n)*)azurerm_firewall((.|\n)*)###' diff --git a/.github/labeler-pull-request-triage.yml b/.github/labeler-pull-request-triage.yml index 1f21c88b7000..921e2509174f 100644 --- a/.github/labeler-pull-request-triage.yml +++ b/.github/labeler-pull-request-triage.yml @@ -239,6 +239,11 @@ service/event-hubs: - any-glob-to-any-file: - internal/services/eventhub/**/* +service/extendedlocation: +- changed-files: + - any-glob-to-any-file: + - internal/services/extendedlocation/**/* + service/firewall: - changed-files: - any-glob-to-any-file: diff --git a/.teamcity/components/generated/services.kt b/.teamcity/components/generated/services.kt index 78c055e88b34..7ccb89121910 100644 --- a/.teamcity/components/generated/services.kt +++ b/.teamcity/components/generated/services.kt @@ -53,6 +53,7 @@ var services = mapOf( "elasticsan" to "ElasticSan", "eventgrid" to "EventGrid", "eventhub" to "EventHub", + "extendedlocation" to "ExtendedLocation", "firewall" to "Firewall", "fluidrelay" to "Fluid Relay", "frontdoor" to "FrontDoor", diff --git a/internal/clients/client.go b/internal/clients/client.go index d280edd1ec2d..5aa21a0a9502 100644 --- a/internal/clients/client.go +++ b/internal/clients/client.go @@ -73,6 +73,7 @@ import ( elasticsan "github.com/hashicorp/terraform-provider-azurerm/internal/services/elasticsan/client" eventgrid "github.com/hashicorp/terraform-provider-azurerm/internal/services/eventgrid/client" eventhub "github.com/hashicorp/terraform-provider-azurerm/internal/services/eventhub/client" + extendedlocation "github.com/hashicorp/terraform-provider-azurerm/internal/services/extendedlocation/client" fluidrelay "github.com/hashicorp/terraform-provider-azurerm/internal/services/fluidrelay/client" frontdoor "github.com/hashicorp/terraform-provider-azurerm/internal/services/frontdoor/client" graph "github.com/hashicorp/terraform-provider-azurerm/internal/services/graphservices/client" @@ -210,6 +211,7 @@ type Client struct { ElasticSan *elasticsan.Client EventGrid *eventgrid_v2022_06_15.Client Eventhub *eventhub.Client + ExtendedLocation *extendedlocation.Client FluidRelay *fluidrelay_2022_05_26.Client Frontdoor *frontdoor.Client Graph *graph.Client @@ -447,6 +449,9 @@ func (client *Client) Build(ctx context.Context, o *common.ClientOptions) error if client.Eventhub, err = eventhub.NewClient(o); err != nil { return fmt.Errorf("building clients for Eventhub: %+v", err) } + if client.ExtendedLocation, err = extendedlocation.NewClient(o); err != nil { + return fmt.Errorf("building clients for ExtendedLocation: %+v", err) + } if client.FluidRelay, err = fluidrelay.NewClient(o); err != nil { return fmt.Errorf("building clients for FluidRelay: %+v", err) } diff --git a/internal/provider/services.go b/internal/provider/services.go index 380ab5770014..8b4178749e90 100644 --- a/internal/provider/services.go +++ b/internal/provider/services.go @@ -53,6 +53,7 @@ import ( "github.com/hashicorp/terraform-provider-azurerm/internal/services/elasticsan" "github.com/hashicorp/terraform-provider-azurerm/internal/services/eventgrid" "github.com/hashicorp/terraform-provider-azurerm/internal/services/eventhub" + "github.com/hashicorp/terraform-provider-azurerm/internal/services/extendedlocation" "github.com/hashicorp/terraform-provider-azurerm/internal/services/firewall" "github.com/hashicorp/terraform-provider-azurerm/internal/services/fluidrelay" "github.com/hashicorp/terraform-provider-azurerm/internal/services/frontdoor" @@ -170,6 +171,7 @@ func SupportedTypedServices() []sdk.TypedServiceRegistration { domainservices.Registration{}, elasticsan.Registration{}, eventhub.Registration{}, + extendedlocation.Registration{}, fluidrelay.Registration{}, graphservices.Registration{}, storagecache.Registration{}, diff --git a/internal/services/extendedlocation/client/client.go b/internal/services/extendedlocation/client/client.go new file mode 100644 index 000000000000..74b0d429e159 --- /dev/null +++ b/internal/services/extendedlocation/client/client.go @@ -0,0 +1,26 @@ +package client + +import ( + "fmt" + + extendedLocation20210815 "github.com/hashicorp/go-azure-sdk/resource-manager/extendedlocation/2021-08-15" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/terraform-provider-azurerm/internal/common" +) + +type Client struct { + *extendedLocation20210815.Client +} + +func NewClient(o *common.ClientOptions) (*Client, error) { + client, err := extendedLocation20210815.NewClientWithBaseURI(o.Environment.ResourceManager, func(c *resourcemanager.Client) { + o.Configure(c, o.Authorizers.ResourceManager) + }) + if err != nil { + return nil, fmt.Errorf("building clients for Network: %+v", err) + } + + return &Client{ + Client: client, + }, nil +} diff --git a/internal/services/extendedlocation/custom_location_data_source.go b/internal/services/extendedlocation/custom_location_data_source.go new file mode 100644 index 000000000000..7e7c7a84eded --- /dev/null +++ b/internal/services/extendedlocation/custom_location_data_source.go @@ -0,0 +1,138 @@ +package extendedlocation + +import ( + "context" + "fmt" + "time" + + "github.com/hashicorp/go-azure-helpers/lang/pointer" + "github.com/hashicorp/go-azure-helpers/lang/response" + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonschema" + "github.com/hashicorp/go-azure-helpers/resourcemanager/identity" + "github.com/hashicorp/go-azure-helpers/resourcemanager/location" + "github.com/hashicorp/go-azure-helpers/resourcemanager/tags" + "github.com/hashicorp/go-azure-sdk/resource-manager/extendedlocation/2021-08-15/customlocations" + "github.com/hashicorp/terraform-provider-azurerm/internal/sdk" + "github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk" + "github.com/hashicorp/terraform-provider-azurerm/internal/tf/validation" +) + +type CustomLocationDataSource struct{} + +var _ sdk.DataSource = CustomLocationDataSource{} + +type CustomLocationDataSourceModel struct { + ClusterExtensionIds []string `tfschema:"cluster_extension_ids"` + DisplayName string `tfschema:"display_name"` + HostResourceId string `tfschema:"host_resource_id"` + Identities []identity.ModelSystemAssigned `tfschema:"identities"` + Location string `tfschema:"location"` + Name string `tfschema:"name"` + Namespace string `tfschema:"namespace"` + ResourceGroupName string `tfschema:"resource_group_name"` + Tags map[string]interface{} `tfschema:"tags"` +} + +func (r CustomLocationDataSource) ResourceType() string { + return "azurerm_custom_location" +} + +func (r CustomLocationDataSource) ModelObject() interface{} { + return &CustomLocationDataSourceModel{} +} + +func (r CustomLocationDataSource) Arguments() map[string]*pluginsdk.Schema { + return map[string]*pluginsdk.Schema{ + "name": { + Type: pluginsdk.TypeString, + Required: true, + ValidateFunc: validation.StringIsNotEmpty, + }, + + "resource_group_name": commonschema.ResourceGroupNameForDataSource(), + } +} + +func (r CustomLocationDataSource) Attributes() map[string]*pluginsdk.Schema { + return map[string]*pluginsdk.Schema{ + "cluster_extension_ids": { + Type: pluginsdk.TypeList, + Computed: true, + Elem: &pluginsdk.Schema{ + Type: pluginsdk.TypeString, + }, + }, + + "display_name": { + Type: pluginsdk.TypeString, + Computed: true, + }, + + "host_resource_id": { + Type: pluginsdk.TypeString, + Computed: true, + }, + + "identities": commonschema.SystemAssignedIdentityComputed(), + + "location": { + Type: pluginsdk.TypeString, + Computed: true, + }, + + "namespace": { + Type: pluginsdk.TypeString, + Computed: true, + }, + + "tags": commonschema.TagsDataSource(), + } +} + +func (r CustomLocationDataSource) Read() sdk.ResourceFunc { + return sdk.ResourceFunc{ + Timeout: 5 * time.Minute, + Func: func(ctx context.Context, metadata sdk.ResourceMetaData) error { + client := metadata.Client.ExtendedLocation.CustomLocations + subscriptionId := metadata.Client.Account.SubscriptionId + + var model CustomLocationDataSourceModel + if err := metadata.Decode(&model); err != nil { + return fmt.Errorf("decoding: %+v", err) + } + + id := customlocations.NewCustomLocationID(subscriptionId, model.ResourceGroupName, model.Name) + + existing, err := client.Get(ctx, id) + if err != nil { + if response.WasNotFound(existing.HttpResponse) { + return fmt.Errorf("%s does not exist", id) + } + + return fmt.Errorf("retrieving %s: %+v", id, err) + } + + state := CustomLocationDataSourceModel{ + Name: model.Name, + ResourceGroupName: model.ResourceGroupName, + } + + if model := existing.Model; model != nil { + state.Location = location.Normalize(model.Location) + state.Tags = tags.Flatten(model.Tags) + state.Identities = identity.FlattenSystemAssignedToModel(model.Identity) + + if props := model.Properties; props != nil { + state.ClusterExtensionIds = pointer.From(props.ClusterExtensionIds) + state.DisplayName = pointer.From(props.DisplayName) + state.HostResourceId = pointer.From(props.HostResourceId) + state.Namespace = pointer.From(props.Namespace) + } + } + + metadata.SetID(id) + + return metadata.Encode(&state) + }, + } +} diff --git a/internal/services/extendedlocation/custom_location_data_source_test.go b/internal/services/extendedlocation/custom_location_data_source_test.go new file mode 100644 index 000000000000..b2c6effb8042 --- /dev/null +++ b/internal/services/extendedlocation/custom_location_data_source_test.go @@ -0,0 +1,52 @@ +package extendedlocation_test + +import ( + "fmt" + "os" + "testing" + + "github.com/hashicorp/terraform-provider-azurerm/internal/acceptance" + "github.com/hashicorp/terraform-provider-azurerm/internal/acceptance/check" +) + +type CustomLocationDataSource struct{} + +const ( + customLocationName = "ARM_TEST_CUSTOM_LOCATION_NAME" + customLocationResourceGroupName = "ARM_TEST_CUSTOM_LOCATION_RESOURCE_GROUP_NAME" +) + +func TestAccCustomLocationDataSource_basic(t *testing.T) { + data := acceptance.BuildTestData(t, "data.azurerm_custom_location", "test") + d := CustomLocationDataSource{} + + if os.Getenv(customLocationName) == "" || os.Getenv(customLocationResourceGroupName) == "" { + t.Skipf("Skipping test due to missing environment variables: %s, %s", customLocationName, customLocationResourceGroupName) + } + + data.DataSourceTestInSequence(t, []acceptance.TestStep{ + { + Config: d.basic(), + Check: acceptance.ComposeTestCheckFunc( + check.That(data.ResourceName).Key("location").IsNotEmpty(), + check.That(data.ResourceName).Key("host_resource_id").IsNotEmpty(), + check.That(data.ResourceName).Key("display_name").IsNotEmpty(), + check.That(data.ResourceName).Key("namespace").IsNotEmpty(), + check.That(data.ResourceName).Key("cluster_extension_ids.#").HasValue("2"), + ), + }, + }) +} + +func (d CustomLocationDataSource) basic() string { + return fmt.Sprintf(` +provider azurerm { + features {} +} + +data "azurerm_custom_location" "test" { + name = %q + resource_group_name = %q +} +`, os.Getenv(customLocationName), os.Getenv(customLocationResourceGroupName)) +} diff --git a/internal/services/extendedlocation/registration.go b/internal/services/extendedlocation/registration.go new file mode 100644 index 000000000000..fb447cad9c0b --- /dev/null +++ b/internal/services/extendedlocation/registration.go @@ -0,0 +1,31 @@ +package extendedlocation + +import "github.com/hashicorp/terraform-provider-azurerm/internal/sdk" + +var _ sdk.TypedServiceRegistration = Registration{} + +type Registration struct{} + +func (r Registration) AssociatedGitHubLabel() string { + return "service/extendedlocation" +} + +func (Registration) Name() string { + return "ExtendedLocation" +} + +func (Registration) DataSources() []sdk.DataSource { + return []sdk.DataSource{ + CustomLocationDataSource{}, + } +} + +func (Registration) Resources() []sdk.Resource { + return []sdk.Resource{} +} + +func (Registration) WebsiteCategories() []string { + return []string{ + "Extended Location", + } +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/extendedlocation/2021-08-15/client.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/extendedlocation/2021-08-15/client.go new file mode 100644 index 000000000000..07876ce117f8 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/extendedlocation/2021-08-15/client.go @@ -0,0 +1,28 @@ +package v2021_08_15 + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/resource-manager/extendedlocation/2021-08-15/customlocations" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +type Client struct { + CustomLocations *customlocations.CustomLocationsClient +} + +func NewClientWithBaseURI(sdkApi sdkEnv.Api, configureFunc func(c *resourcemanager.Client)) (*Client, error) { + customLocationsClient, err := customlocations.NewCustomLocationsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building CustomLocations client: %+v", err) + } + configureFunc(customLocationsClient.Client) + + return &Client{ + CustomLocations: customLocationsClient, + }, nil +} diff --git a/vendor/modules.txt b/vendor/modules.txt index 498fc8f9791b..3fb07a600b96 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -519,6 +519,7 @@ github.com/hashicorp/go-azure-sdk/resource-manager/eventhub/2021-11-01/namespace github.com/hashicorp/go-azure-sdk/resource-manager/eventhub/2021-11-01/networkrulesets github.com/hashicorp/go-azure-sdk/resource-manager/eventhub/2021-11-01/schemaregistry github.com/hashicorp/go-azure-sdk/resource-manager/eventhub/2022-01-01-preview/namespaces +github.com/hashicorp/go-azure-sdk/resource-manager/extendedlocation/2021-08-15 github.com/hashicorp/go-azure-sdk/resource-manager/extendedlocation/2021-08-15/customlocations github.com/hashicorp/go-azure-sdk/resource-manager/fluidrelay/2022-05-26 github.com/hashicorp/go-azure-sdk/resource-manager/fluidrelay/2022-05-26/fluidrelaycontainers diff --git a/website/allowed-subcategories b/website/allowed-subcategories index a73c2bb3b112..7ba8bdec8572 100644 --- a/website/allowed-subcategories +++ b/website/allowed-subcategories @@ -51,6 +51,7 @@ Digital Twins Disks Elastic Elastic SAN +Extended Location Fluid Relay Graph Services HDInsight diff --git a/website/docs/d/custom_location.html.markdown b/website/docs/d/custom_location.html.markdown new file mode 100644 index 000000000000..3c0257da3003 --- /dev/null +++ b/website/docs/d/custom_location.html.markdown @@ -0,0 +1,68 @@ +--- +subcategory: "Extended Location" +layout: "azurerm" +page_title: "Azure Resource Manager: Data Source: azurerm_custom_location" +description: |- + Gets information about an existing Custom Location. +--- + +# Data Source: azurerm_custom_location + +Use this data source to access information about an existing Custom Location. + +## Example Usage + +```hcl +data "azurerm_custom_location" "example" { + name = "existing" + resource_group_name = "existing" +} + +output "id" { + value = data.azurerm_custom_location.example.id +} +``` + +## Arguments Reference + +The following arguments are supported: + +* `name` - (Required) The name of this Custom Location. + +* `resource_group_name` - (Required) The name of the Resource Group where the Custom Location exists. + +## Attributes Reference + +In addition to the Arguments listed above - the following Attributes are exported: + +* `id` - The ID of the Custom Location. + +* `cluster_extension_ids` - A `cluster_extension_ids` block as defined below. + +* `display_name` - The display name of the Custom Location. + +* `host_resource_id` - The ID of the host resource of the Custom Location. + +* `identities` - A `identities` block as defined below. + +* `location` - The geo-location where the Custom Location exists. + +* `namespace` - Kubernetes namespace that is created on the specified cluster for the Custom Location. + +* `tags` - A mapping of tags assigned to the Custom Location. + +--- + +A `identities` block exports the following: + +* `principal_id` - The Principal ID of the System Assigned Managed Service Identity that is configured on this Custom Location. + +* `tenant_id` - The Tenant ID of the System Assigned Managed Service Identity that is configured on this Custom Location. + +* `type` - The type of Managed Service Identity that is configured on this Custom Location. + +## Timeouts + +The `timeouts` block allows you to specify [timeouts](https://www.terraform.io/language/resources/syntax#operation-timeouts) for certain actions: + +* `read` - (Defaults to 5 minutes) Used when retrieving the Custom Location.