diff --git a/internal/services/resource/client/client.go b/internal/services/resource/client/client.go index 149b2c55076d..5f1cb279f283 100644 --- a/internal/services/resource/client/client.go +++ b/internal/services/resource/client/client.go @@ -9,6 +9,7 @@ import ( "github.com/Azure/azure-sdk-for-go/services/preview/resources/mgmt/2019-06-01-preview/templatespecs" // nolint: staticcheck "github.com/Azure/azure-sdk-for-go/services/resources/mgmt/2020-06-01/resources" // nolint: staticcheck "github.com/hashicorp/go-azure-sdk/resource-manager/resources/2020-05-01/managementlocks" + "github.com/hashicorp/go-azure-sdk/resource-manager/resources/2020-05-01/privatelinkassociation" "github.com/hashicorp/go-azure-sdk/resource-manager/resources/2020-05-01/resourcemanagementprivatelink" "github.com/hashicorp/go-azure-sdk/resource-manager/resources/2020-10-01/deploymentscripts" "github.com/hashicorp/go-azure-sdk/resource-manager/resources/2021-07-01/features" @@ -22,6 +23,7 @@ type Client struct { FeaturesClient *features.FeaturesClient GroupsClient *resources.GroupsClient LocksClient *managementlocks.ManagementLocksClient + PrivateLinkAssociationClient *privatelinkassociation.PrivateLinkAssociationClient ResourceManagementPrivateLinkClient *resourcemanagementprivatelink.ResourceManagementPrivateLinkClient ResourceProvidersClient *providers.ProvidersClient ResourcesClient *resources.Client @@ -56,6 +58,12 @@ func NewClient(o *common.ClientOptions) (*Client, error) { } o.Configure(locksClient.Client, o.Authorizers.ResourceManager) + privateLinkAssociationClient, err := privatelinkassociation.NewPrivateLinkAssociationClientWithBaseURI(o.Environment.ResourceManager) + if err != nil { + return nil, fmt.Errorf("building PrivateLinkAssociation client: %+v", err) + } + o.Configure(privateLinkAssociationClient.Client, o.Authorizers.ResourceManager) + resourceManagementPrivateLinkClient, err := resourcemanagementprivatelink.NewResourceManagementPrivateLinkClientWithBaseURI(o.Environment.ResourceManager) if err != nil { return nil, fmt.Errorf("building ResourceManagementPrivateLink client: %+v", err) @@ -83,6 +91,7 @@ func NewClient(o *common.ClientOptions) (*Client, error) { DeploymentScriptsClient: deploymentScriptsClient, FeaturesClient: featuresClient, LocksClient: locksClient, + PrivateLinkAssociationClient: privateLinkAssociationClient, ResourceManagementPrivateLinkClient: resourceManagementPrivateLinkClient, ResourceProvidersClient: resourceProvidersClient, ResourcesClient: &resourcesClient, diff --git a/internal/services/resource/registration.go b/internal/services/resource/registration.go index aaec2742104c..1a8afa890f16 100644 --- a/internal/services/resource/registration.go +++ b/internal/services/resource/registration.go @@ -63,6 +63,7 @@ func (r Registration) DataSources() []sdk.DataSource { // Resources returns a list of Resources supported by this Service func (r Registration) Resources() []sdk.Resource { return []sdk.Resource{ + ResourceManagementPrivateLinkAssociationResource{}, ResourceProviderRegistrationResource{}, ResourceManagementPrivateLinkResource{}, ResourceDeploymentScriptAzurePowerShellResource{}, diff --git a/internal/services/resource/resource_management_private_link_association_resource.go b/internal/services/resource/resource_management_private_link_association_resource.go new file mode 100644 index 000000000000..68a724d71a07 --- /dev/null +++ b/internal/services/resource/resource_management_private_link_association_resource.go @@ -0,0 +1,205 @@ +package resource + +import ( + "context" + "fmt" + "time" + + "github.com/google/uuid" + "github.com/hashicorp/go-azure-helpers/lang/pointer" + "github.com/hashicorp/go-azure-helpers/lang/response" + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" + "github.com/hashicorp/go-azure-sdk/resource-manager/resources/2020-05-01/privatelinkassociation" + "github.com/hashicorp/go-azure-sdk/resource-manager/resources/2020-05-01/resourcemanagementprivatelink" + "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" +) + +var _ sdk.Resource = ResourceManagementPrivateLinkAssociationResource{} + +type ResourceManagementPrivateLinkAssociationResource struct{} + +func (r ResourceManagementPrivateLinkAssociationResource) ModelObject() interface{} { + return &ResourceManagementPrivateLinkAssociationResourceSchema{} +} + +type ResourceManagementPrivateLinkAssociationResourceSchema struct { + ManagementGroupId string `tfschema:"management_group_id"` + Name string `tfschema:"name"` + ResourceManagementPrivateLinkId string `tfschema:"resource_management_private_link_id"` + PublicNetworkAccessEnabled bool `tfschema:"public_network_access_enabled"` + TenantID string `tfschema:"tenant_id"` +} + +func (r ResourceManagementPrivateLinkAssociationResource) IDValidationFunc() pluginsdk.SchemaValidateFunc { + return privatelinkassociation.ValidatePrivateLinkAssociationID +} + +func (r ResourceManagementPrivateLinkAssociationResource) ResourceType() string { + return "azurerm_resource_management_private_link_association" +} + +func (r ResourceManagementPrivateLinkAssociationResource) Arguments() map[string]*pluginsdk.Schema { + return map[string]*pluginsdk.Schema{ + "name": { + ForceNew: true, + Optional: true, + Type: pluginsdk.TypeString, + ValidateFunc: validation.IsUUID, + }, + "management_group_id": { + ForceNew: true, + Required: true, + Type: pluginsdk.TypeString, + ValidateFunc: commonids.ValidateManagementGroupID, + }, + "resource_management_private_link_id": { + ForceNew: true, + Required: true, + Type: pluginsdk.TypeString, + ValidateFunc: resourcemanagementprivatelink.ValidateResourceManagementPrivateLinkID, + }, + "public_network_access_enabled": { + ForceNew: true, + Required: true, + Type: pluginsdk.TypeBool, + }, + } +} + +func (r ResourceManagementPrivateLinkAssociationResource) Attributes() map[string]*pluginsdk.Schema { + return map[string]*pluginsdk.Schema{ + "tenant_id": { + Computed: true, + Type: pluginsdk.TypeString, + }, + } +} + +func (r ResourceManagementPrivateLinkAssociationResource) Create() sdk.ResourceFunc { + return sdk.ResourceFunc{ + Timeout: 30 * time.Minute, + Func: func(ctx context.Context, metadata sdk.ResourceMetaData) error { + client := metadata.Client.Resource.PrivateLinkAssociationClient + + var config ResourceManagementPrivateLinkAssociationResourceSchema + if err := metadata.Decode(&config); err != nil { + return fmt.Errorf("decoding: %+v", err) + } + + managementGroupId, err := commonids.ParseManagementGroupID(config.ManagementGroupId) + if err != nil { + return err + } + + var name string + if config.Name != "" { + name = config.Name + } + + if name == "" { + name = uuid.New().String() + } + + id := privatelinkassociation.NewPrivateLinkAssociationID(managementGroupId.GroupId, name) + + existing, err := client.Get(ctx, id) + if err != nil { + if !response.WasNotFound(existing.HttpResponse) { + return fmt.Errorf("checking for the presence of an existing %s: %+v", id, err) + } + } + if !response.WasNotFound(existing.HttpResponse) { + return metadata.ResourceRequiresImport(r.ResourceType(), id) + } + + payload := privatelinkassociation.PrivateLinkAssociationObject{ + Properties: &privatelinkassociation.PrivateLinkAssociationProperties{ + PrivateLink: pointer.To(config.ResourceManagementPrivateLinkId), + PublicNetworkAccess: r.expandPublicNetworkAccess(config.PublicNetworkAccessEnabled), + }, + } + + if _, err := client.Put(ctx, id, payload); err != nil { + return fmt.Errorf("creating %s: %+v", id, err) + } + + metadata.SetID(id) + return nil + }, + } +} + +func (r ResourceManagementPrivateLinkAssociationResource) Read() sdk.ResourceFunc { + return sdk.ResourceFunc{ + Timeout: 5 * time.Minute, + Func: func(ctx context.Context, metadata sdk.ResourceMetaData) error { + client := metadata.Client.Resource.PrivateLinkAssociationClient + schema := ResourceManagementPrivateLinkAssociationResourceSchema{} + + id, err := privatelinkassociation.ParsePrivateLinkAssociationID(metadata.ResourceData.Id()) + if err != nil { + return err + } + + resp, err := client.Get(ctx, *id) + if err != nil { + if response.WasNotFound(resp.HttpResponse) { + return metadata.MarkAsGone(*id) + } + return fmt.Errorf("retrieving %s: %+v", *id, err) + } + + schema.ManagementGroupId = commonids.NewManagementGroupID(id.GroupId).ID() + schema.Name = id.PlaId + + if model := resp.Model; model != nil { + if prop := model.Properties; prop != nil { + schema.PublicNetworkAccessEnabled = r.flattenPublicNetworkAccess(prop.PublicNetworkAccess) + schema.TenantID = pointer.From(prop.TenantID) + schema.ResourceManagementPrivateLinkId = pointer.From(prop.PrivateLink) + } + } + + return metadata.Encode(&schema) + }, + } +} + +func (r ResourceManagementPrivateLinkAssociationResource) Delete() sdk.ResourceFunc { + return sdk.ResourceFunc{ + Timeout: 30 * time.Minute, + Func: func(ctx context.Context, metadata sdk.ResourceMetaData) error { + client := metadata.Client.Resource.PrivateLinkAssociationClient + + id, err := privatelinkassociation.ParsePrivateLinkAssociationID(metadata.ResourceData.Id()) + if err != nil { + return err + } + + if _, err := client.Delete(ctx, *id); err != nil { + return fmt.Errorf("deleting %s: %+v", *id, err) + } + + return nil + }, + } +} + +func (r ResourceManagementPrivateLinkAssociationResource) expandPublicNetworkAccess(input bool) *privatelinkassociation.PublicNetworkAccessOptions { + output := privatelinkassociation.PublicNetworkAccessOptionsEnabled + if !input { + output = privatelinkassociation.PublicNetworkAccessOptionsDisabled + } + + return &output +} + +func (r ResourceManagementPrivateLinkAssociationResource) flattenPublicNetworkAccess(input *privatelinkassociation.PublicNetworkAccessOptions) bool { + if input == nil || *input == privatelinkassociation.PublicNetworkAccessOptionsEnabled { + return true + } + + return false +} diff --git a/internal/services/resource/resource_management_private_link_association_resource_test.go b/internal/services/resource/resource_management_private_link_association_resource_test.go new file mode 100644 index 000000000000..d8c726ca6e8a --- /dev/null +++ b/internal/services/resource/resource_management_private_link_association_resource_test.go @@ -0,0 +1,147 @@ +package resource_test + +import ( + "context" + "fmt" + "testing" + + "github.com/hashicorp/go-azure-sdk/resource-manager/resources/2020-05-01/privatelinkassociation" + "github.com/hashicorp/go-uuid" + "github.com/hashicorp/terraform-provider-azurerm/internal/acceptance" + "github.com/hashicorp/terraform-provider-azurerm/internal/acceptance/check" + "github.com/hashicorp/terraform-provider-azurerm/internal/clients" + "github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk" + "github.com/hashicorp/terraform-provider-azurerm/utils" +) + +type ResourceManagementPrivateLinkAssociationTestResource struct{} + +func TestAccResourceManagementPrivateLinkAssociation_basic(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_resource_management_private_link_association", "test") + r := ResourceManagementPrivateLinkAssociationTestResource{} + + data.ResourceTest(t, r, []acceptance.TestStep{ + { + Config: r.basic(data), + Check: acceptance.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + ), + }, + data.ImportStep(), + }) +} + +func TestAccResourceManagementPrivateLinkAssociation_requiresImport(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_resource_management_private_link_association", "test") + r := ResourceManagementPrivateLinkAssociationTestResource{} + + data.ResourceTest(t, r, []acceptance.TestStep{ + { + Config: r.basic(data), + Check: acceptance.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + ), + }, + data.RequiresImportErrorStep(r.requiresImport), + }) +} + +func TestAccResourceManagementPrivateLinkAssociation_generateName(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_resource_management_private_link_association", "test") + r := ResourceManagementPrivateLinkAssociationTestResource{} + + data.ResourceTest(t, r, []acceptance.TestStep{ + { + Config: r.generateName(data), + Check: acceptance.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + ), + }, + data.ImportStep(), + }) +} + +func (r ResourceManagementPrivateLinkAssociationTestResource) Exists(ctx context.Context, clients *clients.Client, state *pluginsdk.InstanceState) (*bool, error) { + id, err := privatelinkassociation.ParsePrivateLinkAssociationID(state.ID) + if err != nil { + return nil, err + } + + resp, err := clients.Resource.PrivateLinkAssociationClient.Get(ctx, *id) + if err != nil { + return nil, fmt.Errorf("reading %s: %+v", *id, err) + } + + return utils.Bool(resp.Model != nil), nil +} + +func (r ResourceManagementPrivateLinkAssociationTestResource) basic(data acceptance.TestData) string { + randomUUID, _ := uuid.GenerateUUID() + return fmt.Sprintf(` +provider "azurerm" { + features {} +} + +%s + +resource "azurerm_resource_management_private_link_association" "test" { + name = "%s" + management_group_id = data.azurerm_management_group.test.id + resource_management_private_link_id = azurerm_resource_management_private_link.test.id + public_network_access_enabled = true +} +`, r.template(data), randomUUID) +} + +func (r ResourceManagementPrivateLinkAssociationTestResource) generateName(data acceptance.TestData) string { + return fmt.Sprintf(` +provider "azurerm" { + features {} +} + +%s + +resource "azurerm_resource_management_private_link_association" "test" { + management_group_id = data.azurerm_management_group.test.id + resource_management_private_link_id = azurerm_resource_management_private_link.test.id + public_network_access_enabled = true + lifecycle { + ignore_changes = [name] + } +} +`, r.template(data)) +} + +func (r ResourceManagementPrivateLinkAssociationTestResource) requiresImport(data acceptance.TestData) string { + return fmt.Sprintf(` +%s + +resource "azurerm_resource_management_private_link_association" "import" { + name = azurerm_resource_management_private_link_association.test.name + management_group_id = azurerm_resource_management_private_link_association.test.management_group_id + resource_management_private_link_id = azurerm_resource_management_private_link_association.test.resource_management_private_link_id + public_network_access_enabled = azurerm_resource_management_private_link_association.test.public_network_access_enabled +} +`, r.basic(data)) +} + +func (r ResourceManagementPrivateLinkAssociationTestResource) template(data acceptance.TestData) string { + return fmt.Sprintf(` +data "azurerm_client_config" "test" {} + +data "azurerm_management_group" "test" { + name = data.azurerm_client_config.test.tenant_id +} + +resource "azurerm_resource_group" "test" { + name = "acctestrg-%d" + location = "%s" +} + +resource "azurerm_resource_management_private_link" "test" { + location = azurerm_resource_group.test.location + name = "acctestrmpl-%[1]d" + resource_group_name = azurerm_resource_group.test.name +} +`, data.RandomInteger, data.Locations.Primary) +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/resources/2020-05-01/privatelinkassociation/README.md b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/resources/2020-05-01/privatelinkassociation/README.md new file mode 100644 index 000000000000..a77321d1c848 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/resources/2020-05-01/privatelinkassociation/README.md @@ -0,0 +1,89 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/resources/2020-05-01/privatelinkassociation` Documentation + +The `privatelinkassociation` SDK allows for interaction with the Azure Resource Manager Service `resources` (API Version `2020-05-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/resources/2020-05-01/privatelinkassociation" +``` + + +### Client Initialization + +```go +client := privatelinkassociation.NewPrivateLinkAssociationClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `PrivateLinkAssociationClient.Delete` + +```go +ctx := context.TODO() +id := privatelinkassociation.NewPrivateLinkAssociationID("groupIdValue", "plaIdValue") + +read, err := client.Delete(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `PrivateLinkAssociationClient.Get` + +```go +ctx := context.TODO() +id := privatelinkassociation.NewPrivateLinkAssociationID("groupIdValue", "plaIdValue") + +read, err := client.Get(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `PrivateLinkAssociationClient.List` + +```go +ctx := context.TODO() +id := privatelinkassociation.NewManagementGroupID("groupIdValue") + +read, err := client.List(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `PrivateLinkAssociationClient.Put` + +```go +ctx := context.TODO() +id := privatelinkassociation.NewPrivateLinkAssociationID("groupIdValue", "plaIdValue") + +payload := privatelinkassociation.PrivateLinkAssociationObject{ + // ... +} + + +read, err := client.Put(ctx, id, payload) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/resources/2020-05-01/privatelinkassociation/client.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/resources/2020-05-01/privatelinkassociation/client.go new file mode 100644 index 000000000000..7eda06e6d3d3 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/resources/2020-05-01/privatelinkassociation/client.go @@ -0,0 +1,26 @@ +package privatelinkassociation + +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrivateLinkAssociationClient struct { + Client *resourcemanager.Client +} + +func NewPrivateLinkAssociationClientWithBaseURI(sdkApi sdkEnv.Api) (*PrivateLinkAssociationClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "privatelinkassociation", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating PrivateLinkAssociationClient: %+v", err) + } + + return &PrivateLinkAssociationClient{ + Client: client, + }, nil +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/resources/2020-05-01/privatelinkassociation/constants.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/resources/2020-05-01/privatelinkassociation/constants.go new file mode 100644 index 000000000000..0b4150bc2204 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/resources/2020-05-01/privatelinkassociation/constants.go @@ -0,0 +1,51 @@ +package privatelinkassociation + +import ( + "encoding/json" + "fmt" + "strings" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PublicNetworkAccessOptions string + +const ( + PublicNetworkAccessOptionsDisabled PublicNetworkAccessOptions = "Disabled" + PublicNetworkAccessOptionsEnabled PublicNetworkAccessOptions = "Enabled" +) + +func PossibleValuesForPublicNetworkAccessOptions() []string { + return []string{ + string(PublicNetworkAccessOptionsDisabled), + string(PublicNetworkAccessOptionsEnabled), + } +} + +func (s *PublicNetworkAccessOptions) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parsePublicNetworkAccessOptions(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parsePublicNetworkAccessOptions(input string) (*PublicNetworkAccessOptions, error) { + vals := map[string]PublicNetworkAccessOptions{ + "disabled": PublicNetworkAccessOptionsDisabled, + "enabled": PublicNetworkAccessOptionsEnabled, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := PublicNetworkAccessOptions(input) + return &out, nil +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/resources/2020-05-01/privatelinkassociation/id_privatelinkassociation.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/resources/2020-05-01/privatelinkassociation/id_privatelinkassociation.go new file mode 100644 index 000000000000..4b93814fbc4c --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/resources/2020-05-01/privatelinkassociation/id_privatelinkassociation.go @@ -0,0 +1,116 @@ +package privatelinkassociation + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = PrivateLinkAssociationId{} + +// PrivateLinkAssociationId is a struct representing the Resource ID for a Private Link Association +type PrivateLinkAssociationId struct { + GroupId string + PlaId string +} + +// NewPrivateLinkAssociationID returns a new PrivateLinkAssociationId struct +func NewPrivateLinkAssociationID(groupId string, plaId string) PrivateLinkAssociationId { + return PrivateLinkAssociationId{ + GroupId: groupId, + PlaId: plaId, + } +} + +// ParsePrivateLinkAssociationID parses 'input' into a PrivateLinkAssociationId +func ParsePrivateLinkAssociationID(input string) (*PrivateLinkAssociationId, error) { + parser := resourceids.NewParserFromResourceIdType(PrivateLinkAssociationId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := PrivateLinkAssociationId{} + + if id.GroupId, ok = parsed.Parsed["groupId"]; !ok { + return nil, resourceids.NewSegmentNotSpecifiedError(id, "groupId", *parsed) + } + + if id.PlaId, ok = parsed.Parsed["plaId"]; !ok { + return nil, resourceids.NewSegmentNotSpecifiedError(id, "plaId", *parsed) + } + + return &id, nil +} + +// ParsePrivateLinkAssociationIDInsensitively parses 'input' case-insensitively into a PrivateLinkAssociationId +// note: this method should only be used for API response data and not user input +func ParsePrivateLinkAssociationIDInsensitively(input string) (*PrivateLinkAssociationId, error) { + parser := resourceids.NewParserFromResourceIdType(PrivateLinkAssociationId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := PrivateLinkAssociationId{} + + if id.GroupId, ok = parsed.Parsed["groupId"]; !ok { + return nil, resourceids.NewSegmentNotSpecifiedError(id, "groupId", *parsed) + } + + if id.PlaId, ok = parsed.Parsed["plaId"]; !ok { + return nil, resourceids.NewSegmentNotSpecifiedError(id, "plaId", *parsed) + } + + return &id, nil +} + +// ValidatePrivateLinkAssociationID checks that 'input' can be parsed as a Private Link Association ID +func ValidatePrivateLinkAssociationID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParsePrivateLinkAssociationID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Private Link Association ID +func (id PrivateLinkAssociationId) ID() string { + fmtString := "/providers/Microsoft.Management/managementGroups/%s/providers/Microsoft.Authorization/privateLinkAssociations/%s" + return fmt.Sprintf(fmtString, id.GroupId, id.PlaId) +} + +// Segments returns a slice of Resource ID Segments which comprise this Private Link Association ID +func (id PrivateLinkAssociationId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftManagement", "Microsoft.Management", "Microsoft.Management"), + resourceids.StaticSegment("staticManagementGroups", "managementGroups", "managementGroups"), + resourceids.UserSpecifiedSegment("groupId", "groupIdValue"), + resourceids.StaticSegment("staticProviders2", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftAuthorization", "Microsoft.Authorization", "Microsoft.Authorization"), + resourceids.StaticSegment("staticPrivateLinkAssociations", "privateLinkAssociations", "privateLinkAssociations"), + resourceids.UserSpecifiedSegment("plaId", "plaIdValue"), + } +} + +// String returns a human-readable description of this Private Link Association ID +func (id PrivateLinkAssociationId) String() string { + components := []string{ + fmt.Sprintf("Group: %q", id.GroupId), + fmt.Sprintf("Pla: %q", id.PlaId), + } + return fmt.Sprintf("Private Link Association (%s)", strings.Join(components, "\n")) +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/resources/2020-05-01/privatelinkassociation/method_delete.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/resources/2020-05-01/privatelinkassociation/method_delete.go new file mode 100644 index 000000000000..1b27d0d39c08 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/resources/2020-05-01/privatelinkassociation/method_delete.go @@ -0,0 +1,47 @@ +package privatelinkassociation + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeleteOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// Delete ... +func (c PrivateLinkAssociationClient) Delete(ctx context.Context, id PrivateLinkAssociationId) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/resources/2020-05-01/privatelinkassociation/method_get.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/resources/2020-05-01/privatelinkassociation/method_get.go new file mode 100644 index 000000000000..74bfa7ef8381 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/resources/2020-05-01/privatelinkassociation/method_get.go @@ -0,0 +1,51 @@ +package privatelinkassociation + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *PrivateLinkAssociation +} + +// Get ... +func (c PrivateLinkAssociationClient) Get(ctx context.Context, id PrivateLinkAssociationId) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/resources/2020-05-01/privatelinkassociation/method_list.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/resources/2020-05-01/privatelinkassociation/method_list.go new file mode 100644 index 000000000000..0e98c75e06a8 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/resources/2020-05-01/privatelinkassociation/method_list.go @@ -0,0 +1,53 @@ +package privatelinkassociation + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *PrivateLinkAssociationGetResult +} + +// List ... +func (c PrivateLinkAssociationClient) List(ctx context.Context, id commonids.ManagementGroupId) (result ListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/providers/Microsoft.Authorization/privateLinkAssociations", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/resources/2020-05-01/privatelinkassociation/method_put.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/resources/2020-05-01/privatelinkassociation/method_put.go new file mode 100644 index 000000000000..1622db6c243f --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/resources/2020-05-01/privatelinkassociation/method_put.go @@ -0,0 +1,56 @@ +package privatelinkassociation + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PutOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *PrivateLinkAssociation +} + +// Put ... +func (c PrivateLinkAssociationClient) Put(ctx context.Context, id PrivateLinkAssociationId, input PrivateLinkAssociationObject) (result PutOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/resources/2020-05-01/privatelinkassociation/model_privatelinkassociation.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/resources/2020-05-01/privatelinkassociation/model_privatelinkassociation.go new file mode 100644 index 000000000000..ffb33c738b46 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/resources/2020-05-01/privatelinkassociation/model_privatelinkassociation.go @@ -0,0 +1,11 @@ +package privatelinkassociation + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrivateLinkAssociation struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *PrivateLinkAssociationPropertiesExpanded `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/resources/2020-05-01/privatelinkassociation/model_privatelinkassociationgetresult.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/resources/2020-05-01/privatelinkassociation/model_privatelinkassociationgetresult.go new file mode 100644 index 000000000000..a196acfb9c0e --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/resources/2020-05-01/privatelinkassociation/model_privatelinkassociationgetresult.go @@ -0,0 +1,8 @@ +package privatelinkassociation + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrivateLinkAssociationGetResult struct { + Value *[]PrivateLinkAssociation `json:"value,omitempty"` +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/resources/2020-05-01/privatelinkassociation/model_privatelinkassociationobject.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/resources/2020-05-01/privatelinkassociation/model_privatelinkassociationobject.go new file mode 100644 index 000000000000..a9c635335a53 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/resources/2020-05-01/privatelinkassociation/model_privatelinkassociationobject.go @@ -0,0 +1,8 @@ +package privatelinkassociation + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrivateLinkAssociationObject struct { + Properties *PrivateLinkAssociationProperties `json:"properties,omitempty"` +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/resources/2020-05-01/privatelinkassociation/model_privatelinkassociationproperties.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/resources/2020-05-01/privatelinkassociation/model_privatelinkassociationproperties.go new file mode 100644 index 000000000000..b63c5d5cebbe --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/resources/2020-05-01/privatelinkassociation/model_privatelinkassociationproperties.go @@ -0,0 +1,9 @@ +package privatelinkassociation + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrivateLinkAssociationProperties struct { + PrivateLink *string `json:"privateLink,omitempty"` + PublicNetworkAccess *PublicNetworkAccessOptions `json:"publicNetworkAccess,omitempty"` +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/resources/2020-05-01/privatelinkassociation/model_privatelinkassociationpropertiesexpanded.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/resources/2020-05-01/privatelinkassociation/model_privatelinkassociationpropertiesexpanded.go new file mode 100644 index 000000000000..2f25e217f9d5 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/resources/2020-05-01/privatelinkassociation/model_privatelinkassociationpropertiesexpanded.go @@ -0,0 +1,11 @@ +package privatelinkassociation + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrivateLinkAssociationPropertiesExpanded struct { + PrivateLink *string `json:"privateLink,omitempty"` + PublicNetworkAccess *PublicNetworkAccessOptions `json:"publicNetworkAccess,omitempty"` + Scope *string `json:"scope,omitempty"` + TenantID *string `json:"tenantID,omitempty"` +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/resources/2020-05-01/privatelinkassociation/version.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/resources/2020-05-01/privatelinkassociation/version.go new file mode 100644 index 000000000000..91aa6cdb35fc --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/resources/2020-05-01/privatelinkassociation/version.go @@ -0,0 +1,12 @@ +package privatelinkassociation + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2020-05-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/privatelinkassociation/%s", defaultApiVersion) +} diff --git a/vendor/modules.txt b/vendor/modules.txt index 6e45f4273d68..f6a7b5b6cd40 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -836,6 +836,7 @@ github.com/hashicorp/go-azure-sdk/resource-manager/relay/2021-11-01/hybridconnec github.com/hashicorp/go-azure-sdk/resource-manager/relay/2021-11-01/namespaces github.com/hashicorp/go-azure-sdk/resource-manager/resourceconnector/2022-10-27/appliances github.com/hashicorp/go-azure-sdk/resource-manager/resources/2020-05-01/managementlocks +github.com/hashicorp/go-azure-sdk/resource-manager/resources/2020-05-01/privatelinkassociation github.com/hashicorp/go-azure-sdk/resource-manager/resources/2020-05-01/resourcemanagementprivatelink github.com/hashicorp/go-azure-sdk/resource-manager/resources/2020-10-01/deploymentscripts github.com/hashicorp/go-azure-sdk/resource-manager/resources/2021-07-01/features diff --git a/website/docs/r/resource_management_private_link_association.html.markdown b/website/docs/r/resource_management_private_link_association.html.markdown new file mode 100644 index 000000000000..4a7755b03344 --- /dev/null +++ b/website/docs/r/resource_management_private_link_association.html.markdown @@ -0,0 +1,95 @@ +--- +subcategory: "Management" +layout: "azurerm" +page_title: "Azure Resource Manager: azurerm_resource_management_private_link_association" +description: |- + Manages a Resource Management Private Link Association. +--- + +# azurerm_resource_management_private_link_association + +Manages a Resource Management Private Link Association. + +## Example Usage + +```hcl +data "azurerm_client_config" "example" {} + +data "azurerm_management_group" "example" { + name = data.azurerm_client_config.example.tenant_id +} + +resource "azurerm_resource_group" "example" { + name = "example" + location = "West Europe" +} + +resource "azurerm_resource_management_private_link" "example" { + name = "example" + resource_group_name = azurerm_resource_group.example.name + location = azurerm_resource_group.example.location +} + +resource "random_uuid" "example" { +} + +resource "azurerm_resource_management_private_link_association" "example" { + name = random_uuid.example.result + management_group_id = azurerm_management_group.example.id + resource_management_private_link_id = azurerm_resource_management_private_link.example.id + public_network_access_enabled = true +} + +``` + +## Arguments Reference + +The following arguments are supported: + +* `management_group_id` - (Required) Specifies the Management Group ID within which this Private Link Association should exist. Changing this forces a new Private Link Association to be created. + +**Note:** For now, `management_group_id` must be the ID of [Root Management Group](https://learn.microsoft.com/en-us/azure/governance/management-groups/overview#root-management-group-for-each-directory). + +* `resource_management_private_link_id` - (Required) The Resource ID of Resource Management Private Link. Changing this forces a new Private Link Association to be created. + +* `public_network_access_enabled` - (Required) Whether public network access is allowed. Changing this forces a new Private Link Association to be created. + +* `name` - (Optional) Specifies the name of this Private Link Association, which should be a UUID. If `name` is not provided, a UUID will be generated, you should use [the `ignore_changes` attribute to ignore changes to this field](https://www.terraform.io/language/meta-arguments/lifecycle#ignore_changess). Changing this forces a new Private Link Association to be created. + +```hcl +resource "azurerm_resource_management_private_link_association" "example" { + management_group_id = azurerm_management_group.example.id + resource_management_private_link_id = azurerm_resource_management_private_link.example.id + public_network_access_enabled = true + lifecycle { + ignore_changes = [name] + } +} + +``` + +## Attributes Reference + +In addition to the Arguments listed above - the following Attributes are exported: + +* `id` - The ID of the Private Link Association. + +* `tenant_id` - The Tenant ID. + +--- + +## Timeouts + +The `timeouts` block allows you to specify [timeouts](https://www.terraform.io/docs/configuration/resources.html#timeouts) for certain actions: + +* `create` - (Defaults to 30 minutes) Used when creating this Private Link Association. +* `delete` - (Defaults to 30 minutes) Used when deleting this Private Link Association. +* `read` - (Defaults to 5 minutes) Used when retrieving this Private Link Association. + +## Import + +An existing Private Link Association can be imported into Terraform using the `resource id`, e.g. + +```shell +terraform import azurerm_resource_management_private_link_association.example /providers/Microsoft.Management/managementGroups/00000000-0000-0000-0000-000000000000/providers/Microsoft.Authorization/privateLinkAssociations/00000000-0000-0000-0000-000000000000 +```