diff --git a/internal/services/dashboard/client/client.go b/internal/services/dashboard/client/client.go index a9c543b2f015..e0e3715c8fdc 100644 --- a/internal/services/dashboard/client/client.go +++ b/internal/services/dashboard/client/client.go @@ -7,11 +7,13 @@ import ( "fmt" "github.com/hashicorp/go-azure-sdk/resource-manager/dashboard/2023-09-01/grafanaresource" + "github.com/hashicorp/go-azure-sdk/resource-manager/dashboard/2023-09-01/managedprivateendpoints" "github.com/hashicorp/terraform-provider-azurerm/internal/common" ) type Client struct { - GrafanaResourceClient *grafanaresource.GrafanaResourceClient + GrafanaResourceClient *grafanaresource.GrafanaResourceClient + ManagedPrivateEndpointsClient *managedprivateendpoints.ManagedPrivateEndpointsClient } func NewClient(o *common.ClientOptions) (*Client, error) { @@ -21,7 +23,14 @@ func NewClient(o *common.ClientOptions) (*Client, error) { } o.Configure(grafanaResourceClient.Client, o.Authorizers.ResourceManager) + managedPrivateEndpointsClient, err := managedprivateendpoints.NewManagedPrivateEndpointsClientWithBaseURI(o.Environment.ResourceManager) + if err != nil { + return nil, fmt.Errorf("building ManagedPrivateEndpoints client: %+v", err) + } + + o.Configure(managedPrivateEndpointsClient.Client, o.Authorizers.ResourceManager) return &Client{ - GrafanaResourceClient: grafanaResourceClient, + GrafanaResourceClient: grafanaResourceClient, + ManagedPrivateEndpointsClient: managedPrivateEndpointsClient, }, nil } diff --git a/internal/services/dashboard/dashboard_grafana_managed_private_endpoint_resource.go b/internal/services/dashboard/dashboard_grafana_managed_private_endpoint_resource.go new file mode 100644 index 000000000000..c6ed997ad23d --- /dev/null +++ b/internal/services/dashboard/dashboard_grafana_managed_private_endpoint_resource.go @@ -0,0 +1,260 @@ +package dashboard + +import ( + "context" + "fmt" + "regexp" + "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/location" + "github.com/hashicorp/go-azure-sdk/resource-manager/dashboard/2023-09-01/grafanaresource" + "github.com/hashicorp/go-azure-sdk/resource-manager/dashboard/2023-09-01/managedprivateendpoints" + "github.com/hashicorp/terraform-provider-azurerm/helpers/azure" + "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 ManagedPrivateEndpointResource struct{} + +type ManagedPrivateEndpointModel struct { + Name string `tfschema:"name"` + Location string `tfschema:"location"` + GrafanaId string `tfschema:"grafana_id"` + PrivateLinkResourceId string `tfschema:"private_link_resource_id"` + PrivateLinkResourceRegion string `tfschema:"private_link_resource_region"` + Tags map[string]string `tfschema:"tags"` + GroupIds []string `tfschema:"group_ids"` + RequestMessage string `tfschema:"request_message"` +} + +type ManagedPrivateEndpointId struct { + SubscriptionId string + ResourceGroupName string + GrafanaName string + ManagedPrivateEndpointName string +} + +func (r ManagedPrivateEndpointResource) ModelObject() interface{} { + return &ManagedPrivateEndpointModel{} +} + +func (r ManagedPrivateEndpointResource) ResourceType() string { + return "azurerm_dashboard_grafana_managed_private_endpoint" +} + +func (r ManagedPrivateEndpointResource) IDValidationFunc() pluginsdk.SchemaValidateFunc { + return managedprivateendpoints.ValidateManagedPrivateEndpointID +} + +func (r ManagedPrivateEndpointResource) Arguments() map[string]*pluginsdk.Schema { + return map[string]*pluginsdk.Schema{ + "name": { + Type: pluginsdk.TypeString, + Required: true, + ForceNew: true, + ValidateFunc: validation.StringMatch( + regexp.MustCompile(`\A([a-zA-Z]{1}[a-zA-Z0-9\-]{1,19}[a-zA-Z0-9]{1})\z`), + `Name length can only consist of alphanumeric characters or dashes, and must be between 2 and 20 characters long. It must begin with a letter and end with a letter or digit.`, + ), + }, + + "location": commonschema.Location(), + + "tags": commonschema.Tags(), + + "grafana_id": { + Type: pluginsdk.TypeString, + Required: true, + ForceNew: true, + ValidateFunc: grafanaresource.ValidateGrafanaID, + }, + + "private_link_resource_id": { + Type: pluginsdk.TypeString, + Required: true, + ForceNew: true, + ValidateFunc: azure.ValidateResourceID, + }, + + "group_ids": { + Type: pluginsdk.TypeList, + Optional: true, + ForceNew: true, + Elem: &pluginsdk.Schema{ + Type: pluginsdk.TypeString, + }, + // no validation here because an empty group id is valid for a generic private link resource + }, + + "private_link_resource_region": { + Type: pluginsdk.TypeString, + Optional: true, + ForceNew: true, + ValidateFunc: validation.StringIsNotEmpty, + }, + + "request_message": { + Type: pluginsdk.TypeString, + Optional: true, + ValidateFunc: validation.StringIsNotEmpty, + }, + } +} + +func (r ManagedPrivateEndpointResource) Attributes() map[string]*pluginsdk.Schema { + return map[string]*pluginsdk.Schema{} +} + +func (r ManagedPrivateEndpointResource) Create() sdk.ResourceFunc { + return sdk.ResourceFunc{ + Timeout: 30 * time.Minute, + Func: func(ctx context.Context, metadata sdk.ResourceMetaData) error { + var model ManagedPrivateEndpointModel + if err := metadata.Decode(&model); err != nil { + return err + } + + client := metadata.Client.Dashboard.ManagedPrivateEndpointsClient + subscriptionId := metadata.Client.Account.SubscriptionId + grafanaId, err := grafanaresource.ParseGrafanaID(model.GrafanaId) + if err != nil { + return err + } + id := managedprivateendpoints.NewManagedPrivateEndpointID(subscriptionId, grafanaId.ResourceGroupName, grafanaId.GrafanaName, model.Name) + + existing, err := client.Get(ctx, id) + if err != nil && !response.WasNotFound(existing.HttpResponse) { + return fmt.Errorf("checking for presence of existing %s: %+v", id, err) + } + if !response.WasNotFound(existing.HttpResponse) { + return metadata.ResourceRequiresImport(r.ResourceType(), id) + } + + props := managedprivateendpoints.ManagedPrivateEndpointModel{ + Location: location.Normalize(model.Location), + Name: &model.Name, + Properties: &managedprivateendpoints.ManagedPrivateEndpointModelProperties{ + GroupIds: &model.GroupIds, + PrivateLinkResourceId: &model.PrivateLinkResourceId, + PrivateLinkResourceRegion: &model.PrivateLinkResourceRegion, + RequestMessage: &model.RequestMessage, + }, + Tags: &model.Tags, + } + + if err := client.CreateThenPoll(ctx, id, props); err != nil { + return fmt.Errorf("creating %s: %+v", id, err) + } + + metadata.SetID(id) + + return nil + }, + } +} + +func (r ManagedPrivateEndpointResource) Read() sdk.ResourceFunc { + return sdk.ResourceFunc{ + Timeout: 5 * time.Minute, + Func: func(ctx context.Context, metadata sdk.ResourceMetaData) error { + client := metadata.Client.Dashboard.ManagedPrivateEndpointsClient + id, err := managedprivateendpoints.ParseManagedPrivateEndpointID(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) + } + + grafanaId := grafanaresource.NewGrafanaID(id.SubscriptionId, id.ResourceGroupName, id.GrafanaName) + state := ManagedPrivateEndpointModel{ + Name: id.ManagedPrivateEndpointName, + GrafanaId: grafanaId.ID(), + } + + if model := resp.Model; model != nil { + state.Location = location.Normalize(model.Location) + state.Tags = pointer.From(model.Tags) + + if props := model.Properties; props != nil { + state.GroupIds = pointer.From(props.GroupIds) + state.PrivateLinkResourceId = pointer.From(props.PrivateLinkResourceId) + state.PrivateLinkResourceRegion = pointer.From(props.PrivateLinkResourceRegion) + state.RequestMessage = pointer.From(props.RequestMessage) + } + } + + return metadata.Encode(&state) + }, + } +} + +func (r ManagedPrivateEndpointResource) Delete() sdk.ResourceFunc { + return sdk.ResourceFunc{ + Timeout: 5 * time.Minute, + Func: func(ctx context.Context, metadata sdk.ResourceMetaData) error { + client := metadata.Client.Dashboard.ManagedPrivateEndpointsClient + id, err := managedprivateendpoints.ParseManagedPrivateEndpointID(metadata.ResourceData.Id()) + if err != nil { + return err + } + + metadata.Logger.Infof("deleting %s", *id) + + if err := client.DeleteThenPoll(ctx, *id); err != nil { + return fmt.Errorf("deleting %s: %+v", *id, err) + } + + return nil + }, + } +} + +func (r ManagedPrivateEndpointResource) Update() sdk.ResourceFunc { + return sdk.ResourceFunc{ + Timeout: 30 * time.Minute, + Func: func(ctx context.Context, metadata sdk.ResourceMetaData) error { + client := metadata.Client.Dashboard.ManagedPrivateEndpointsClient + + id, err := managedprivateendpoints.ParseManagedPrivateEndpointID(metadata.ResourceData.Id()) + + if err != nil { + return err + } + + var mpe ManagedPrivateEndpointModel + if err := metadata.Decode(&mpe); err != nil { + return fmt.Errorf("decoding: %+v", err) + } + + resp, err := client.Get(ctx, *id) + if err != nil { + return fmt.Errorf("retrieving %s: %+v", *id, err) + } + + model := resp.Model + if resp.Model == nil { + return fmt.Errorf("retrieving %s: `model` was nil", id) + } + + if metadata.ResourceData.HasChange("tags") { + model.Tags = &mpe.Tags + } + + if err := client.CreateThenPoll(ctx, *id, *model); err != nil { + return fmt.Errorf("updating %s: %+v", *id, err) + } + + return nil + }, + } +} diff --git a/internal/services/dashboard/dashboard_grafana_managed_private_endpoint_resource_test.go b/internal/services/dashboard/dashboard_grafana_managed_private_endpoint_resource_test.go new file mode 100644 index 000000000000..92f4ae2b4290 --- /dev/null +++ b/internal/services/dashboard/dashboard_grafana_managed_private_endpoint_resource_test.go @@ -0,0 +1,194 @@ +// // Copyright (c) HashiCorp, Inc. +// // SPDX-License-Identifier: MPL-2.0 + +package dashboard_test + +import ( + "context" + "fmt" + "testing" + + "github.com/hashicorp/go-azure-helpers/lang/pointer" + "github.com/hashicorp/go-azure-sdk/resource-manager/dashboard/2023-09-01/managedprivateendpoints" + "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" +) + +type ManagedPrivateEndpointResource struct{} + +func TestAccDashboardGrafanaManagedPrivateEndpoint_basic(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_dashboard_grafana_managed_private_endpoint", "test") + r := ManagedPrivateEndpointResource{} + data.ResourceSequentialTest(t, r, []acceptance.TestStep{ + { + Config: r.basic(data), + Check: acceptance.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + ), + }, + data.ImportStep(), + }) +} + +func TestAccDashboardGrafanaManagedPrivateEndpoint_requiresImport(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_dashboard_grafana_managed_private_endpoint", "test") + r := ManagedPrivateEndpointResource{} + data.ResourceSequentialTest(t, r, []acceptance.TestStep{ + { + Config: r.basic(data), + Check: acceptance.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + ), + }, + data.RequiresImportErrorStep(r.requiresImport), + }) +} + +func TestAccDashboardGrafanaManagedPrivateEndpoint_complete(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_dashboard_grafana_managed_private_endpoint", "test") + r := ManagedPrivateEndpointResource{} + data.ResourceSequentialTest(t, r, []acceptance.TestStep{ + { + Config: r.complete(data), + Check: acceptance.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + ), + }, + }) +} + +func TestAccDashboardGrafanaManagedPrivateEndpoint_update(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_dashboard_grafana_managed_private_endpoint", "test") + r := ManagedPrivateEndpointResource{} + data.ResourceSequentialTest(t, r, []acceptance.TestStep{ + { + Config: r.complete(data), + Check: acceptance.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + ), + }, + { + Config: r.update(data), + Check: acceptance.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + ), + }, + }) +} + +func (r ManagedPrivateEndpointResource) Exists(ctx context.Context, clients *clients.Client, state *pluginsdk.InstanceState) (*bool, error) { + id, err := managedprivateendpoints.ParseManagedPrivateEndpointID(state.ID) + if err != nil { + return nil, err + } + + client := clients.Dashboard.ManagedPrivateEndpointsClient + resp, err := client.Get(ctx, *id) + if err != nil { + return nil, fmt.Errorf("retrieving %s: %+v", id, err) + } + return pointer.To(resp.Model != nil), nil +} + +func (r ManagedPrivateEndpointResource) template(data acceptance.TestData) string { + return fmt.Sprintf(` +provider "azurerm" { + features {} +} + +resource "azurerm_resource_group" "test" { + name = "acctest-rg-%d" + location = "%s" +} + +resource "azurerm_dashboard_grafana" "test" { + name = "a-dg-%d" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location + grafana_major_version = "10" +} + +resource "azurerm_monitor_workspace" "test" { + name = "acctest-mw-%d" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location +} +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) +} + +func (r ManagedPrivateEndpointResource) basic(data acceptance.TestData) string { + template := r.template(data) + return fmt.Sprintf(` + %s + +resource "azurerm_dashboard_grafana_managed_private_endpoint" "test" { + grafana_id = azurerm_dashboard_grafana.test.id + name = "acctest-mpe-%d" + location = azurerm_dashboard_grafana.test.location + private_link_resource_id = azurerm_monitor_workspace.test.id + group_ids = ["prometheusMetrics"] + private_link_resource_region = azurerm_dashboard_grafana.test.location +} +`, template, data.RandomIntOfLength(8)) +} + +func (r ManagedPrivateEndpointResource) requiresImport(data acceptance.TestData) string { + config := r.basic(data) + return fmt.Sprintf(` + %s + +resource "azurerm_dashboard_grafana_managed_private_endpoint" "import" { + grafana_id = azurerm_dashboard_grafana_managed_private_endpoint.test.grafana_id + name = azurerm_dashboard_grafana_managed_private_endpoint.test.name + location = azurerm_dashboard_grafana_managed_private_endpoint.test.location + private_link_resource_id = azurerm_dashboard_grafana_managed_private_endpoint.test.private_link_resource_id +} +`, config) + +} + +func (r ManagedPrivateEndpointResource) complete(data acceptance.TestData) string { + template := r.template(data) + return fmt.Sprintf(` + %s + +resource "azurerm_dashboard_grafana_managed_private_endpoint" "test" { + grafana_id = azurerm_dashboard_grafana.test.id + name = "acctest-mpe-%d" + location = azurerm_dashboard_grafana.test.location + private_link_resource_id = azurerm_monitor_workspace.test.id + group_ids = ["prometheusMetrics"] + private_link_resource_region = azurerm_dashboard_grafana.test.location + + tags = { + key = "value" + } + + request_message = "please approve" +} +`, template, data.RandomIntOfLength(8)) +} + +func (r ManagedPrivateEndpointResource) update(data acceptance.TestData) string { + template := r.template(data) + return fmt.Sprintf(` + %s + +resource "azurerm_dashboard_grafana_managed_private_endpoint" "test" { + grafana_id = azurerm_dashboard_grafana.test.id + name = "acctest-mpe-%d" + location = azurerm_dashboard_grafana.test.location + private_link_resource_id = azurerm_monitor_workspace.test.id + group_ids = ["prometheusMetrics"] + private_link_resource_region = azurerm_dashboard_grafana.test.location + + tags = { + key2 = "value2" + } + + request_message = "please approve" +} +`, template, data.RandomIntOfLength(8)) +} diff --git a/internal/services/dashboard/registration.go b/internal/services/dashboard/registration.go index f492fbd99f94..a3ce796801e2 100644 --- a/internal/services/dashboard/registration.go +++ b/internal/services/dashboard/registration.go @@ -52,5 +52,6 @@ func (r Registration) DataSources() []sdk.DataSource { func (r Registration) Resources() []sdk.Resource { return []sdk.Resource{ DashboardGrafanaResource{}, + ManagedPrivateEndpointResource{}, } } diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/dashboard/2023-09-01/managedprivateendpoints/README.md b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/dashboard/2023-09-01/managedprivateendpoints/README.md new file mode 100644 index 000000000000..6d68e00ec461 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/dashboard/2023-09-01/managedprivateendpoints/README.md @@ -0,0 +1,111 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/dashboard/2023-09-01/managedprivateendpoints` Documentation + +The `managedprivateendpoints` SDK allows for interaction with Azure Resource Manager `dashboard` (API Version `2023-09-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/dashboard/2023-09-01/managedprivateendpoints" +``` + + +### Client Initialization + +```go +client := managedprivateendpoints.NewManagedPrivateEndpointsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `ManagedPrivateEndpointsClient.Create` + +```go +ctx := context.TODO() +id := managedprivateendpoints.NewManagedPrivateEndpointID("12345678-1234-9876-4563-123456789012", "example-resource-group", "grafanaName", "managedPrivateEndpointName") + +payload := managedprivateendpoints.ManagedPrivateEndpointModel{ + // ... +} + + +if err := client.CreateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `ManagedPrivateEndpointsClient.Delete` + +```go +ctx := context.TODO() +id := managedprivateendpoints.NewManagedPrivateEndpointID("12345678-1234-9876-4563-123456789012", "example-resource-group", "grafanaName", "managedPrivateEndpointName") + +if err := client.DeleteThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `ManagedPrivateEndpointsClient.Get` + +```go +ctx := context.TODO() +id := managedprivateendpoints.NewManagedPrivateEndpointID("12345678-1234-9876-4563-123456789012", "example-resource-group", "grafanaName", "managedPrivateEndpointName") + +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: `ManagedPrivateEndpointsClient.List` + +```go +ctx := context.TODO() +id := managedprivateendpoints.NewGrafanaID("12345678-1234-9876-4563-123456789012", "example-resource-group", "grafanaName") + +// alternatively `client.List(ctx, id)` can be used to do batched pagination +items, err := client.ListComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `ManagedPrivateEndpointsClient.Refresh` + +```go +ctx := context.TODO() +id := managedprivateendpoints.NewGrafanaID("12345678-1234-9876-4563-123456789012", "example-resource-group", "grafanaName") + +if err := client.RefreshThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `ManagedPrivateEndpointsClient.Update` + +```go +ctx := context.TODO() +id := managedprivateendpoints.NewManagedPrivateEndpointID("12345678-1234-9876-4563-123456789012", "example-resource-group", "grafanaName", "managedPrivateEndpointName") + +payload := managedprivateendpoints.ManagedPrivateEndpointUpdateParameters{ + // ... +} + + +if err := client.UpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/dashboard/2023-09-01/managedprivateendpoints/client.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/dashboard/2023-09-01/managedprivateendpoints/client.go new file mode 100644 index 000000000000..e02237558e49 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/dashboard/2023-09-01/managedprivateendpoints/client.go @@ -0,0 +1,26 @@ +package managedprivateendpoints + +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 ManagedPrivateEndpointsClient struct { + Client *resourcemanager.Client +} + +func NewManagedPrivateEndpointsClientWithBaseURI(sdkApi sdkEnv.Api) (*ManagedPrivateEndpointsClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "managedprivateendpoints", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating ManagedPrivateEndpointsClient: %+v", err) + } + + return &ManagedPrivateEndpointsClient{ + Client: client, + }, nil +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/dashboard/2023-09-01/managedprivateendpoints/constants.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/dashboard/2023-09-01/managedprivateendpoints/constants.go new file mode 100644 index 000000000000..b9d6b033782e --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/dashboard/2023-09-01/managedprivateendpoints/constants.go @@ -0,0 +1,119 @@ +package managedprivateendpoints + +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 ManagedPrivateEndpointConnectionStatus string + +const ( + ManagedPrivateEndpointConnectionStatusApproved ManagedPrivateEndpointConnectionStatus = "Approved" + ManagedPrivateEndpointConnectionStatusDisconnected ManagedPrivateEndpointConnectionStatus = "Disconnected" + ManagedPrivateEndpointConnectionStatusPending ManagedPrivateEndpointConnectionStatus = "Pending" + ManagedPrivateEndpointConnectionStatusRejected ManagedPrivateEndpointConnectionStatus = "Rejected" +) + +func PossibleValuesForManagedPrivateEndpointConnectionStatus() []string { + return []string{ + string(ManagedPrivateEndpointConnectionStatusApproved), + string(ManagedPrivateEndpointConnectionStatusDisconnected), + string(ManagedPrivateEndpointConnectionStatusPending), + string(ManagedPrivateEndpointConnectionStatusRejected), + } +} + +func (s *ManagedPrivateEndpointConnectionStatus) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseManagedPrivateEndpointConnectionStatus(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseManagedPrivateEndpointConnectionStatus(input string) (*ManagedPrivateEndpointConnectionStatus, error) { + vals := map[string]ManagedPrivateEndpointConnectionStatus{ + "approved": ManagedPrivateEndpointConnectionStatusApproved, + "disconnected": ManagedPrivateEndpointConnectionStatusDisconnected, + "pending": ManagedPrivateEndpointConnectionStatusPending, + "rejected": ManagedPrivateEndpointConnectionStatusRejected, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ManagedPrivateEndpointConnectionStatus(input) + return &out, nil +} + +type ProvisioningState string + +const ( + ProvisioningStateAccepted ProvisioningState = "Accepted" + ProvisioningStateCanceled ProvisioningState = "Canceled" + ProvisioningStateCreating ProvisioningState = "Creating" + ProvisioningStateDeleted ProvisioningState = "Deleted" + ProvisioningStateDeleting ProvisioningState = "Deleting" + ProvisioningStateFailed ProvisioningState = "Failed" + ProvisioningStateNotSpecified ProvisioningState = "NotSpecified" + ProvisioningStateSucceeded ProvisioningState = "Succeeded" + ProvisioningStateUpdating ProvisioningState = "Updating" +) + +func PossibleValuesForProvisioningState() []string { + return []string{ + string(ProvisioningStateAccepted), + string(ProvisioningStateCanceled), + string(ProvisioningStateCreating), + string(ProvisioningStateDeleted), + string(ProvisioningStateDeleting), + string(ProvisioningStateFailed), + string(ProvisioningStateNotSpecified), + string(ProvisioningStateSucceeded), + string(ProvisioningStateUpdating), + } +} + +func (s *ProvisioningState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseProvisioningState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseProvisioningState(input string) (*ProvisioningState, error) { + vals := map[string]ProvisioningState{ + "accepted": ProvisioningStateAccepted, + "canceled": ProvisioningStateCanceled, + "creating": ProvisioningStateCreating, + "deleted": ProvisioningStateDeleted, + "deleting": ProvisioningStateDeleting, + "failed": ProvisioningStateFailed, + "notspecified": ProvisioningStateNotSpecified, + "succeeded": ProvisioningStateSucceeded, + "updating": ProvisioningStateUpdating, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ProvisioningState(input) + return &out, nil +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/dashboard/2023-09-01/managedprivateendpoints/id_grafana.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/dashboard/2023-09-01/managedprivateendpoints/id_grafana.go new file mode 100644 index 000000000000..2a7fb9d4c021 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/dashboard/2023-09-01/managedprivateendpoints/id_grafana.go @@ -0,0 +1,130 @@ +package managedprivateendpoints + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "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. + +func init() { + recaser.RegisterResourceId(&GrafanaId{}) +} + +var _ resourceids.ResourceId = &GrafanaId{} + +// GrafanaId is a struct representing the Resource ID for a Grafana +type GrafanaId struct { + SubscriptionId string + ResourceGroupName string + GrafanaName string +} + +// NewGrafanaID returns a new GrafanaId struct +func NewGrafanaID(subscriptionId string, resourceGroupName string, grafanaName string) GrafanaId { + return GrafanaId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + GrafanaName: grafanaName, + } +} + +// ParseGrafanaID parses 'input' into a GrafanaId +func ParseGrafanaID(input string) (*GrafanaId, error) { + parser := resourceids.NewParserFromResourceIdType(&GrafanaId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := GrafanaId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseGrafanaIDInsensitively parses 'input' case-insensitively into a GrafanaId +// note: this method should only be used for API response data and not user input +func ParseGrafanaIDInsensitively(input string) (*GrafanaId, error) { + parser := resourceids.NewParserFromResourceIdType(&GrafanaId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := GrafanaId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *GrafanaId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.GrafanaName, ok = input.Parsed["grafanaName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "grafanaName", input) + } + + return nil +} + +// ValidateGrafanaID checks that 'input' can be parsed as a Grafana ID +func ValidateGrafanaID(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 := ParseGrafanaID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Grafana ID +func (id GrafanaId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Dashboard/grafana/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.GrafanaName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Grafana ID +func (id GrafanaId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftDashboard", "Microsoft.Dashboard", "Microsoft.Dashboard"), + resourceids.StaticSegment("staticGrafana", "grafana", "grafana"), + resourceids.UserSpecifiedSegment("grafanaName", "grafanaName"), + } +} + +// String returns a human-readable description of this Grafana ID +func (id GrafanaId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Grafana Name: %q", id.GrafanaName), + } + return fmt.Sprintf("Grafana (%s)", strings.Join(components, "\n")) +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/dashboard/2023-09-01/managedprivateendpoints/id_managedprivateendpoint.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/dashboard/2023-09-01/managedprivateendpoints/id_managedprivateendpoint.go new file mode 100644 index 000000000000..f62eda38b79a --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/dashboard/2023-09-01/managedprivateendpoints/id_managedprivateendpoint.go @@ -0,0 +1,139 @@ +package managedprivateendpoints + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "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. + +func init() { + recaser.RegisterResourceId(&ManagedPrivateEndpointId{}) +} + +var _ resourceids.ResourceId = &ManagedPrivateEndpointId{} + +// ManagedPrivateEndpointId is a struct representing the Resource ID for a Managed Private Endpoint +type ManagedPrivateEndpointId struct { + SubscriptionId string + ResourceGroupName string + GrafanaName string + ManagedPrivateEndpointName string +} + +// NewManagedPrivateEndpointID returns a new ManagedPrivateEndpointId struct +func NewManagedPrivateEndpointID(subscriptionId string, resourceGroupName string, grafanaName string, managedPrivateEndpointName string) ManagedPrivateEndpointId { + return ManagedPrivateEndpointId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + GrafanaName: grafanaName, + ManagedPrivateEndpointName: managedPrivateEndpointName, + } +} + +// ParseManagedPrivateEndpointID parses 'input' into a ManagedPrivateEndpointId +func ParseManagedPrivateEndpointID(input string) (*ManagedPrivateEndpointId, error) { + parser := resourceids.NewParserFromResourceIdType(&ManagedPrivateEndpointId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ManagedPrivateEndpointId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseManagedPrivateEndpointIDInsensitively parses 'input' case-insensitively into a ManagedPrivateEndpointId +// note: this method should only be used for API response data and not user input +func ParseManagedPrivateEndpointIDInsensitively(input string) (*ManagedPrivateEndpointId, error) { + parser := resourceids.NewParserFromResourceIdType(&ManagedPrivateEndpointId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ManagedPrivateEndpointId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ManagedPrivateEndpointId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.GrafanaName, ok = input.Parsed["grafanaName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "grafanaName", input) + } + + if id.ManagedPrivateEndpointName, ok = input.Parsed["managedPrivateEndpointName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "managedPrivateEndpointName", input) + } + + return nil +} + +// ValidateManagedPrivateEndpointID checks that 'input' can be parsed as a Managed Private Endpoint ID +func ValidateManagedPrivateEndpointID(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 := ParseManagedPrivateEndpointID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Managed Private Endpoint ID +func (id ManagedPrivateEndpointId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Dashboard/grafana/%s/managedPrivateEndpoints/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.GrafanaName, id.ManagedPrivateEndpointName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Managed Private Endpoint ID +func (id ManagedPrivateEndpointId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftDashboard", "Microsoft.Dashboard", "Microsoft.Dashboard"), + resourceids.StaticSegment("staticGrafana", "grafana", "grafana"), + resourceids.UserSpecifiedSegment("grafanaName", "grafanaName"), + resourceids.StaticSegment("staticManagedPrivateEndpoints", "managedPrivateEndpoints", "managedPrivateEndpoints"), + resourceids.UserSpecifiedSegment("managedPrivateEndpointName", "managedPrivateEndpointName"), + } +} + +// String returns a human-readable description of this Managed Private Endpoint ID +func (id ManagedPrivateEndpointId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Grafana Name: %q", id.GrafanaName), + fmt.Sprintf("Managed Private Endpoint Name: %q", id.ManagedPrivateEndpointName), + } + return fmt.Sprintf("Managed Private Endpoint (%s)", strings.Join(components, "\n")) +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/dashboard/2023-09-01/managedprivateendpoints/method_create.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/dashboard/2023-09-01/managedprivateendpoints/method_create.go new file mode 100644 index 000000000000..47504c5921de --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/dashboard/2023-09-01/managedprivateendpoints/method_create.go @@ -0,0 +1,75 @@ +package managedprivateendpoints + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "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 CreateOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *ManagedPrivateEndpointModel +} + +// Create ... +func (c ManagedPrivateEndpointsClient) Create(ctx context.Context, id ManagedPrivateEndpointId, input ManagedPrivateEndpointModel) (result CreateOperationResponse, 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 + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// CreateThenPoll performs Create then polls until it's completed +func (c ManagedPrivateEndpointsClient) CreateThenPoll(ctx context.Context, id ManagedPrivateEndpointId, input ManagedPrivateEndpointModel) error { + result, err := c.Create(ctx, id, input) + if err != nil { + return fmt.Errorf("performing Create: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after Create: %+v", err) + } + + return nil +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/dashboard/2023-09-01/managedprivateendpoints/method_delete.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/dashboard/2023-09-01/managedprivateendpoints/method_delete.go new file mode 100644 index 000000000000..98a0990b10a1 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/dashboard/2023-09-01/managedprivateendpoints/method_delete.go @@ -0,0 +1,71 @@ +package managedprivateendpoints + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "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 { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData +} + +// Delete ... +func (c ManagedPrivateEndpointsClient) Delete(ctx context.Context, id ManagedPrivateEndpointId) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + 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 + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// DeleteThenPoll performs Delete then polls until it's completed +func (c ManagedPrivateEndpointsClient) DeleteThenPoll(ctx context.Context, id ManagedPrivateEndpointId) error { + result, err := c.Delete(ctx, id) + if err != nil { + return fmt.Errorf("performing Delete: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after Delete: %+v", err) + } + + return nil +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/dashboard/2023-09-01/managedprivateendpoints/method_get.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/dashboard/2023-09-01/managedprivateendpoints/method_get.go new file mode 100644 index 000000000000..6840e6b45925 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/dashboard/2023-09-01/managedprivateendpoints/method_get.go @@ -0,0 +1,53 @@ +package managedprivateendpoints + +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 *ManagedPrivateEndpointModel +} + +// Get ... +func (c ManagedPrivateEndpointsClient) Get(ctx context.Context, id ManagedPrivateEndpointId) (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 + } + + var model ManagedPrivateEndpointModel + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/dashboard/2023-09-01/managedprivateendpoints/method_list.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/dashboard/2023-09-01/managedprivateendpoints/method_list.go new file mode 100644 index 000000000000..4c9b506e1dac --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/dashboard/2023-09-01/managedprivateendpoints/method_list.go @@ -0,0 +1,105 @@ +package managedprivateendpoints + +import ( + "context" + "fmt" + "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 ListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]ManagedPrivateEndpointModel +} + +type ListCompleteResult struct { + LatestHttpResponse *http.Response + Items []ManagedPrivateEndpointModel +} + +type ListCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// List ... +func (c ManagedPrivateEndpointsClient) List(ctx context.Context, id GrafanaId) (result ListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &ListCustomPager{}, + Path: fmt.Sprintf("%s/managedPrivateEndpoints", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]ManagedPrivateEndpointModel `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListComplete retrieves all the results into a single object +func (c ManagedPrivateEndpointsClient) ListComplete(ctx context.Context, id GrafanaId) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, ManagedPrivateEndpointModelOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c ManagedPrivateEndpointsClient) ListCompleteMatchingPredicate(ctx context.Context, id GrafanaId, predicate ManagedPrivateEndpointModelOperationPredicate) (result ListCompleteResult, err error) { + items := make([]ManagedPrivateEndpointModel, 0) + + resp, err := c.List(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/dashboard/2023-09-01/managedprivateendpoints/method_refresh.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/dashboard/2023-09-01/managedprivateendpoints/method_refresh.go new file mode 100644 index 000000000000..fb9fec3c6d97 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/dashboard/2023-09-01/managedprivateendpoints/method_refresh.go @@ -0,0 +1,70 @@ +package managedprivateendpoints + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "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 RefreshOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData +} + +// Refresh ... +func (c ManagedPrivateEndpointsClient) Refresh(ctx context.Context, id GrafanaId) (result RefreshOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/refreshManagedPrivateEndpoints", 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 + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// RefreshThenPoll performs Refresh then polls until it's completed +func (c ManagedPrivateEndpointsClient) RefreshThenPoll(ctx context.Context, id GrafanaId) error { + result, err := c.Refresh(ctx, id) + if err != nil { + return fmt.Errorf("performing Refresh: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after Refresh: %+v", err) + } + + return nil +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/dashboard/2023-09-01/managedprivateendpoints/method_update.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/dashboard/2023-09-01/managedprivateendpoints/method_update.go new file mode 100644 index 000000000000..6bfa37db056a --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/dashboard/2023-09-01/managedprivateendpoints/method_update.go @@ -0,0 +1,75 @@ +package managedprivateendpoints + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "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 UpdateOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *ManagedPrivateEndpointModel +} + +// Update ... +func (c ManagedPrivateEndpointsClient) Update(ctx context.Context, id ManagedPrivateEndpointId, input ManagedPrivateEndpointUpdateParameters) (result UpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodPatch, + 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 + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// UpdateThenPoll performs Update then polls until it's completed +func (c ManagedPrivateEndpointsClient) UpdateThenPoll(ctx context.Context, id ManagedPrivateEndpointId, input ManagedPrivateEndpointUpdateParameters) error { + result, err := c.Update(ctx, id, input) + if err != nil { + return fmt.Errorf("performing Update: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after Update: %+v", err) + } + + return nil +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/dashboard/2023-09-01/managedprivateendpoints/model_managedprivateendpointconnectionstate.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/dashboard/2023-09-01/managedprivateendpoints/model_managedprivateendpointconnectionstate.go new file mode 100644 index 000000000000..a24ead5087a1 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/dashboard/2023-09-01/managedprivateendpoints/model_managedprivateendpointconnectionstate.go @@ -0,0 +1,9 @@ +package managedprivateendpoints + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ManagedPrivateEndpointConnectionState struct { + Description *string `json:"description,omitempty"` + Status *ManagedPrivateEndpointConnectionStatus `json:"status,omitempty"` +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/dashboard/2023-09-01/managedprivateendpoints/model_managedprivateendpointmodel.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/dashboard/2023-09-01/managedprivateendpoints/model_managedprivateendpointmodel.go new file mode 100644 index 000000000000..109bc1c4e6e4 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/dashboard/2023-09-01/managedprivateendpoints/model_managedprivateendpointmodel.go @@ -0,0 +1,18 @@ +package managedprivateendpoints + +import ( + "github.com/hashicorp/go-azure-helpers/resourcemanager/systemdata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ManagedPrivateEndpointModel struct { + Id *string `json:"id,omitempty"` + Location string `json:"location"` + Name *string `json:"name,omitempty"` + Properties *ManagedPrivateEndpointModelProperties `json:"properties,omitempty"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Tags *map[string]string `json:"tags,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/dashboard/2023-09-01/managedprivateendpoints/model_managedprivateendpointmodelproperties.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/dashboard/2023-09-01/managedprivateendpoints/model_managedprivateendpointmodelproperties.go new file mode 100644 index 000000000000..babce0bcb68d --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/dashboard/2023-09-01/managedprivateendpoints/model_managedprivateendpointmodelproperties.go @@ -0,0 +1,15 @@ +package managedprivateendpoints + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ManagedPrivateEndpointModelProperties struct { + ConnectionState *ManagedPrivateEndpointConnectionState `json:"connectionState,omitempty"` + GroupIds *[]string `json:"groupIds,omitempty"` + PrivateLinkResourceId *string `json:"privateLinkResourceId,omitempty"` + PrivateLinkResourceRegion *string `json:"privateLinkResourceRegion,omitempty"` + PrivateLinkServicePrivateIP *string `json:"privateLinkServicePrivateIP,omitempty"` + PrivateLinkServiceURL *string `json:"privateLinkServiceUrl,omitempty"` + ProvisioningState *ProvisioningState `json:"provisioningState,omitempty"` + RequestMessage *string `json:"requestMessage,omitempty"` +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/dashboard/2023-09-01/managedprivateendpoints/model_managedprivateendpointupdateparameters.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/dashboard/2023-09-01/managedprivateendpoints/model_managedprivateendpointupdateparameters.go new file mode 100644 index 000000000000..f7322b801841 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/dashboard/2023-09-01/managedprivateendpoints/model_managedprivateendpointupdateparameters.go @@ -0,0 +1,8 @@ +package managedprivateendpoints + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ManagedPrivateEndpointUpdateParameters struct { + Tags *map[string]string `json:"tags,omitempty"` +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/dashboard/2023-09-01/managedprivateendpoints/predicates.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/dashboard/2023-09-01/managedprivateendpoints/predicates.go new file mode 100644 index 000000000000..108b63e5f74e --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/dashboard/2023-09-01/managedprivateendpoints/predicates.go @@ -0,0 +1,32 @@ +package managedprivateendpoints + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ManagedPrivateEndpointModelOperationPredicate struct { + Id *string + Location *string + Name *string + Type *string +} + +func (p ManagedPrivateEndpointModelOperationPredicate) Matches(input ManagedPrivateEndpointModel) bool { + + if p.Id != nil && (input.Id == nil || *p.Id != *input.Id) { + return false + } + + if p.Location != nil && *p.Location != input.Location { + return false + } + + if p.Name != nil && (input.Name == nil || *p.Name != *input.Name) { + return false + } + + if p.Type != nil && (input.Type == nil || *p.Type != *input.Type) { + return false + } + + return true +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/dashboard/2023-09-01/managedprivateendpoints/version.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/dashboard/2023-09-01/managedprivateendpoints/version.go new file mode 100644 index 000000000000..819d2c6107ff --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/dashboard/2023-09-01/managedprivateendpoints/version.go @@ -0,0 +1,10 @@ +package managedprivateendpoints + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2023-09-01" + +func userAgent() string { + return "hashicorp/go-azure-sdk/managedprivateendpoints/2023-09-01" +} diff --git a/vendor/modules.txt b/vendor/modules.txt index 93b602934b9a..223f0110cde3 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -416,6 +416,7 @@ github.com/hashicorp/go-azure-sdk/resource-manager/costmanagement/2022-10-01/sch github.com/hashicorp/go-azure-sdk/resource-manager/costmanagement/2022-10-01/views github.com/hashicorp/go-azure-sdk/resource-manager/customproviders/2018-09-01-preview/customresourceprovider github.com/hashicorp/go-azure-sdk/resource-manager/dashboard/2023-09-01/grafanaresource +github.com/hashicorp/go-azure-sdk/resource-manager/dashboard/2023-09-01/managedprivateendpoints github.com/hashicorp/go-azure-sdk/resource-manager/databoxedge/2022-03-01/devices github.com/hashicorp/go-azure-sdk/resource-manager/databoxedge/2022-03-01/orders github.com/hashicorp/go-azure-sdk/resource-manager/databricks/2022-04-01-preview/workspaces diff --git a/website/docs/r/dashboard_grafana_managed_private_endpoint.html.markdown b/website/docs/r/dashboard_grafana_managed_private_endpoint.html.markdown new file mode 100644 index 000000000000..7b3c5d0ba990 --- /dev/null +++ b/website/docs/r/dashboard_grafana_managed_private_endpoint.html.markdown @@ -0,0 +1,95 @@ +--- +subcategory: "Dashboard" +layout: "azurerm" +page_title: "Azure Resource Manager: azurerm_dashboard_grafana_managed_private_endpoint" +description: |- + Manages a Dashboard Grafana Managed Private Endpoint. +--- + +# azurerm_dashboard_grafana_managed_private_endpoint + +Manages a Dashboard Grafana Managed Private Endpoint. + +~> **NOTE:** This resource will _not_ approve the managed private endpoint connection on the linked resource. This will need to be done manually via Azure CLI, PowerShell, or AzAPI resources. See [here](https://github.com/hashicorp/terraform-provider-azurerm/issues/23950#issuecomment-2035109970) for an example that uses AzAPI. + +## Example Usage + +```hcl +resource "azurerm_resource_group" "example" { + name = "example-resources" + location = "Canada Central" +} + +resource "azurerm_monitor_workspace" "example" { + name = "example-mamw" + resource_group_name = azurerm_resource_group.example.name + location = azurerm_resource_group.example.location + public_network_access_enabled = false +} + +resource "azurerm_dashboard_grafana" "example" { + name = "example-dg" + resource_group_name = azurerm_resource_group.example.name + location = azurerm_resource_group.example.location + grafana_major_version = 10 + public_network_access_enabled = false + + azure_monitor_workspace_integrations { + resource_id = azurerm_monitor_workspace.example.id + } +} + +resource "azurerm_dashboard_grafana_managed_private_endpoint" "example" { + grafana_id = azurerm_dashboard_grafana.example.id + name = "example-mpe" + location = azurerm_dashboard_grafana.example.location + private_link_resource_id = azurerm_monitor_workspace.example.id + group_ids = ["prometheusMetrics"] + private_link_resource_region = azurerm_dashboard_grafana.example.location +} +``` + +## Arguments Reference + +The following arguments are supported: + +- `grafana_id` - (Required) The id of the associated managed Grafana. Changing this forces a new Dashboard Grafana Managed Private Endpoint to be created. + +- `location` - (Required) The Azure Region where the Dashboard Grafana Managed Private Endpoint should exist. Changing this forces a new Dashboard Grafana Managed Private Endpoint to be created. + +- `name` - (Required) The name which should be used for this Dashboard Grafana Managed Private Endpoint. Must be between 2 and 20 alphanumeric characters or dashes, must begin with letter and end with a letter or number. Changing this forces a new Dashboard Grafana Managed Private Endpoint to be created. + +- `private_link_resource_id` - (Required) The ID of the resource to which this Dashboard Grafana Managed Private Endpoint will connect. Changing this forces a new Dashboard Grafana Managed Private Endpoint to be created. + +--- + +- `group_ids` - (Optional) Specifies a list of private link group IDs. The value of this will depend on the private link resource to which you are connecting. Changing this forces a new Dashboard Grafana Managed Private Endpoint to be created. + +- `private_link_resource_region` - (Optional) The region in which to create the private link. Changing this forces a new Dashboard Grafana Managed Private Endpoint to be created. + +- `request_message` - (Optional) A message to provide in the request which will be seen by approvers. + +- `tags` - (Optional) A mapping of tags which should be assigned to the Dashboard Grafana Managed Private Endpoint. + +## Attributes Reference + +In addition to the Arguments listed above - the following Attributes are exported: + +- `id` - The ID of the Dashboard Grafana Managed Private Endpoint. + +## Timeouts + +The `timeouts` block allows you to specify [timeouts](https://www.terraform.io/language/resources/syntax#operation-timeouts) for certain actions: + +- `create` - (Defaults to 30 minutes) Used when creating the Dashboard Grafana Managed Private Endpoint. +- `read` - (Defaults to 5 minutes) Used when retrieving the Dashboard Grafana Managed Private Endpoint. +- `update` - (Defaults to 30 minutes) Used when updating the Dashboard Grafana Managed Private Endpoint. +- `delete` - (Defaults to 5 minutes) Used when deleting the Dashboard Grafana Managed Private Endpoint. + +## Import + +Dashboard Grafana Managed Private Endpoint Examples can be imported using the `resource id`, e.g. + +```shell +terraform import azurerm_dashboard_grafana_managed_private_endpoint.example /subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Dashboard/grafana/workspace1/managedPrivateEndpoints/endpoint1 +```