From 22f3a0c2d5559d02647b4c47d0e3e4e0f69bf801 Mon Sep 17 00:00:00 2001 From: Jiawei Tao Date: Mon, 18 Dec 2023 16:58:38 +0800 Subject: [PATCH] New Resource: azurerm_extended_location_custom_location --- .teamcity/components/generated/services.kt | 1 + internal/clients/client.go | 4 +- .../extendedlocation/client/client.go | 14 +- ...o => extended_location_custom_location.go} | 112 ++++++----- ...extended_location_custom_location_test.go} | 96 +++++++-- .../testdata/install_agent.py | 6 +- .../2021-08-15/customlocations/README.md | 10 +- .../2021-08-15/customlocations/client.go | 22 ++- .../2021-08-15/customlocations/constants.go | 19 +- .../customlocations/id_customlocation.go | 61 +++--- .../customlocations/method_createorupdate.go | 74 +++++++ .../method_createorupdate_autorest.go | 79 -------- .../customlocations/method_delete.go | 70 +++++++ .../customlocations/method_delete_autorest.go | 78 -------- .../2021-08-15/customlocations/method_get.go | 51 +++++ .../customlocations/method_get_autorest.go | 68 ------- .../method_listbyresourcegroup.go | 90 +++++++++ .../method_listbyresourcegroup_autorest.go | 187 ------------------ .../method_listbysubscription.go | 90 +++++++++ .../method_listbysubscription_autorest.go | 187 ------------------ .../method_listenabledresourcetypes.go | 89 +++++++++ ...ethod_listenabledresourcetypes_autorest.go | 186 ----------------- .../customlocations/method_update.go | 55 ++++++ .../customlocations/method_update_autorest.go | 69 ------- .../customlocations/model_customlocation.go | 2 +- .../model_customlocationproperties.go | 2 +- .../model_enabledresourcetype.go | 2 +- .../model_patchablecustomlocations.go | 2 +- .../2021-08-15/customlocations/predicates.go | 15 +- ...ded_location_custom_location.html.markdown | 105 ++++++++++ 30 files changed, 868 insertions(+), 978 deletions(-) rename internal/services/extendedlocation/{extended_location_custom_locations.go => extended_location_custom_location.go} (77%) rename internal/services/extendedlocation/{extended_location_custom_locations_test.go => extended_location_custom_location_test.go} (79%) create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/extendedlocation/2021-08-15/customlocations/method_createorupdate.go delete mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/extendedlocation/2021-08-15/customlocations/method_createorupdate_autorest.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/extendedlocation/2021-08-15/customlocations/method_delete.go delete mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/extendedlocation/2021-08-15/customlocations/method_delete_autorest.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/extendedlocation/2021-08-15/customlocations/method_get.go delete mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/extendedlocation/2021-08-15/customlocations/method_get_autorest.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/extendedlocation/2021-08-15/customlocations/method_listbyresourcegroup.go delete mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/extendedlocation/2021-08-15/customlocations/method_listbyresourcegroup_autorest.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/extendedlocation/2021-08-15/customlocations/method_listbysubscription.go delete mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/extendedlocation/2021-08-15/customlocations/method_listbysubscription_autorest.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/extendedlocation/2021-08-15/customlocations/method_listenabledresourcetypes.go delete mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/extendedlocation/2021-08-15/customlocations/method_listenabledresourcetypes_autorest.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/extendedlocation/2021-08-15/customlocations/method_update.go delete mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/extendedlocation/2021-08-15/customlocations/method_update_autorest.go create mode 100644 website/docs/r/extended_location_custom_location.html.markdown diff --git a/.teamcity/components/generated/services.kt b/.teamcity/components/generated/services.kt index 25cce5b39f70b..b392093f03995 100644 --- a/.teamcity/components/generated/services.kt +++ b/.teamcity/components/generated/services.kt @@ -52,6 +52,7 @@ var services = mapOf( "elasticsan" to "ElasticSan", "eventgrid" to "EventGrid", "eventhub" to "EventHub", + "extendedlocation" to "ExtendedLocation", "firewall" to "Firewall", "fluidrelay" to "Fluid Relay", "frontdoor" to "FrontDoor", diff --git a/internal/clients/client.go b/internal/clients/client.go index 3710c9ba80373..5782e752af2f0 100644 --- a/internal/clients/client.go +++ b/internal/clients/client.go @@ -430,7 +430,9 @@ func (client *Client) Build(ctx context.Context, o *common.ClientOptions) error if client.Eventhub, err = eventhub.NewClient(o); err != nil { return fmt.Errorf("building clients for Eventhub: %+v", err) } - client.ExtendedLocation = extendedlocation.NewClient(o) + if client.ExtendedLocation, err = extendedlocation.NewClient(o); err != nil { + return fmt.Errorf("building clients for ExtendedLocation: %+v", err) + } if client.FluidRelay, err = fluidrelay.NewClient(o); err != nil { return fmt.Errorf("building clients for FluidRelay: %+v", err) } diff --git a/internal/services/extendedlocation/client/client.go b/internal/services/extendedlocation/client/client.go index d84259825c709..4f889bb6531de 100644 --- a/internal/services/extendedlocation/client/client.go +++ b/internal/services/extendedlocation/client/client.go @@ -1,6 +1,7 @@ package client import ( + "fmt" "github.com/hashicorp/go-azure-sdk/resource-manager/extendedlocation/2021-08-15/customlocations" "github.com/hashicorp/terraform-provider-azurerm/internal/common" ) @@ -9,11 +10,14 @@ type Client struct { CustomLocationsClient *customlocations.CustomLocationsClient } -func NewClient(o *common.ClientOptions) *Client { - customLocationsClient := customlocations.NewCustomLocationsClientWithBaseURI(o.ResourceManagerEndpoint) - o.ConfigureClient(&customLocationsClient.Client, o.ResourceManagerAuthorizer) +func NewClient(o *common.ClientOptions) (*Client, error) { + customLocationsClient, err := customlocations.NewCustomLocationsClientWithBaseURI(o.Environment.ResourceManager) + if err != nil { + return nil, fmt.Errorf("building CustomLocations client: %+v", err) + } + o.Configure(customLocationsClient.Client, o.Authorizers.ResourceManager) return &Client{ - CustomLocationsClient: &customLocationsClient, - } + CustomLocationsClient: customLocationsClient, + }, nil } diff --git a/internal/services/extendedlocation/extended_location_custom_locations.go b/internal/services/extendedlocation/extended_location_custom_location.go similarity index 77% rename from internal/services/extendedlocation/extended_location_custom_locations.go rename to internal/services/extendedlocation/extended_location_custom_location.go index fff63c03add06..b0fc511cfcbc4 100644 --- a/internal/services/extendedlocation/extended_location_custom_locations.go +++ b/internal/services/extendedlocation/extended_location_custom_location.go @@ -3,33 +3,38 @@ package extendedlocation import ( "context" "fmt" + "github.com/hashicorp/go-azure-helpers/lang/pointer" + "time" + "github.com/hashicorp/go-azure-helpers/lang/response" "github.com/hashicorp/go-azure-sdk/resource-manager/extendedlocation/2021-08-15/customlocations" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "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" "github.com/hashicorp/terraform-provider-azurerm/utils" - "time" ) type CustomLocationResource struct{} type CustomLocationResourceModel struct { - Name string `tfschema:"name"` - ResourceGroupName string `tfschema:"resource_group_name"` - Location string `tfschema:"location"` - AuthenticationType string `tfschema:"authentication_type"` - AuthenticationValue string `tfschema:"authentication_value"` - ClusterExtensionIds []string `tfschema:"cluster_extension_ids"` - DisplayName string `tfschema:"display_name"` - HostResourceId string `tfschema:"host_resource_id"` - HostType string `tfschema:"host_type"` - Namespace string `tfschema:"namespace"` + Name string `tfschema:"name"` + ResourceGroupName string `tfschema:"resource_group_name"` + Location string `tfschema:"location"` + Authentication []AuthModel `tfschema:"authentication"` + ClusterExtensionIds []string `tfschema:"cluster_extension_ids"` + DisplayName string `tfschema:"display_name"` + HostResourceId string `tfschema:"host_resource_id"` + HostType string `tfschema:"host_type"` + Namespace string `tfschema:"namespace"` +} + +type AuthModel struct { + Type string `tfschema:"type"` + Value string `tfschema:"value"` } -func (r CustomLocationResource) Arguments() map[string]*schema.Schema { - return map[string]*schema.Schema{ +func (r CustomLocationResource) Arguments() map[string]*pluginsdk.Schema { + return map[string]*pluginsdk.Schema{ "name": { Type: pluginsdk.TypeString, Required: true, @@ -51,6 +56,13 @@ func (r CustomLocationResource) Arguments() map[string]*schema.Schema { ValidateFunc: validation.StringIsNotEmpty, }, + "namespace": { + Type: pluginsdk.TypeString, + Required: true, + ForceNew: true, + ValidateFunc: validation.StringIsNotEmpty, + }, + "cluster_extension_ids": { Type: pluginsdk.TypeList, Required: true, @@ -65,16 +77,24 @@ func (r CustomLocationResource) Arguments() map[string]*schema.Schema { ValidateFunc: validation.StringIsNotEmpty, }, - "authentication_type": { - Type: pluginsdk.TypeString, - Optional: true, - ValidateFunc: validation.StringIsNotEmpty, - }, - - "authentication_value": { - Type: pluginsdk.TypeString, - Optional: true, - ValidateFunc: validation.StringIsNotEmpty, + "authentication": { + Type: pluginsdk.TypeList, + Optional: true, + Elem: &pluginsdk.Resource{ + Schema: map[string]*pluginsdk.Schema{ + "type": { + Type: pluginsdk.TypeString, + Required: true, + ValidateFunc: validation.StringIsNotEmpty, + }, + + "value": { + Type: pluginsdk.TypeString, + Required: true, + ValidateFunc: validation.StringIsNotEmpty, + }, + }, + }, }, "display_name": { @@ -90,17 +110,11 @@ func (r CustomLocationResource) Arguments() map[string]*schema.Schema { string(customlocations.HostTypeKubernetes), }, false), }, - - "namespace": { - Type: pluginsdk.TypeString, - Optional: true, - ValidateFunc: validation.StringIsNotEmpty, - }, } } -func (r CustomLocationResource) Attributes() map[string]*schema.Schema { - return map[string]*schema.Schema{} +func (r CustomLocationResource) Attributes() map[string]*pluginsdk.Schema { + return map[string]*pluginsdk.Schema{} } func (r CustomLocationResource) ModelObject() interface{} { @@ -108,7 +122,7 @@ func (r CustomLocationResource) ModelObject() interface{} { } func (r CustomLocationResource) ResourceType() string { - return "azurerm_extended_custom_locations" + return "azurerm_extended_custom_location" } func (r CustomLocationResource) Create() sdk.ResourceFunc { @@ -135,10 +149,11 @@ func (r CustomLocationResource) Create() sdk.ResourceFunc { customLocationProps := customlocations.CustomLocationProperties{} - if model.AuthenticationValue != "" && model.AuthenticationType != "" { + if model.Authentication != nil { + auth := model.Authentication[0] customLocationProps.Authentication = &customlocations.CustomLocationPropertiesAuthentication{ - Type: &model.AuthenticationType, - Value: &model.AuthenticationValue, + Type: &auth.Type, + Value: &auth.Value, } } @@ -202,14 +217,20 @@ func (r CustomLocationResource) Read() sdk.ResourceFunc { props := model.Properties state := CustomLocationResourceModel{ - Name: id.ResourceName, + Name: id.CustomLocationName, ResourceGroupName: id.ResourceGroupName, Location: model.Location, } - if props.Authentication != nil && props.Authentication.Type != nil && props.Authentication.Value != nil { - state.AuthenticationType = *props.Authentication.Type - state.AuthenticationValue = *props.Authentication.Value + if props != nil && props.Authentication != nil { + authType := pointer.From(props.Authentication.Type) + authValue := pointer.From(props.Authentication.Value) + state.Authentication = []AuthModel{ + { + Type: authType, + Value: authValue, + }, + } } if props.ClusterExtensionIds != nil { @@ -280,10 +301,13 @@ func (r CustomLocationResource) Update() sdk.ResourceFunc { customLocationProps := customlocations.CustomLocationProperties{} d := metadata.ResourceData - if d.HasChanges("authentication_type", "authentication_value") { - customLocationProps.Authentication = &customlocations.CustomLocationPropertiesAuthentication{ - Type: &state.AuthenticationType, - Value: &state.AuthenticationValue, + if d.HasChanges("authentication") { + if state.Authentication != nil { + auth := state.Authentication[0] + customLocationProps.Authentication = &customlocations.CustomLocationPropertiesAuthentication{ + Type: &auth.Type, + Value: &auth.Value, + } } } diff --git a/internal/services/extendedlocation/extended_location_custom_locations_test.go b/internal/services/extendedlocation/extended_location_custom_location_test.go similarity index 79% rename from internal/services/extendedlocation/extended_location_custom_locations_test.go rename to internal/services/extendedlocation/extended_location_custom_location_test.go index 08475ec4dfd8f..ea356f6c89570 100644 --- a/internal/services/extendedlocation/extended_location_custom_locations_test.go +++ b/internal/services/extendedlocation/extended_location_custom_location_test.go @@ -8,6 +8,10 @@ import ( "encoding/base64" "encoding/pem" "fmt" + "math/rand" + "os" + "testing" + "github.com/hashicorp/go-azure-helpers/lang/response" "github.com/hashicorp/go-azure-sdk/resource-manager/extendedlocation/2021-08-15/customlocations" "github.com/hashicorp/terraform-plugin-testing/helper/resource" @@ -16,9 +20,6 @@ import ( "github.com/hashicorp/terraform-provider-azurerm/internal/clients" "github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk" "github.com/hashicorp/terraform-provider-azurerm/utils" - "math/rand" - "os" - "testing" ) type CustomLocationResource struct{} @@ -40,7 +41,7 @@ func (r CustomLocationResource) Exists(ctx context.Context, client *clients.Clie } func TestAccExtendedLocationCustomLocations_basic(t *testing.T) { - data := acceptance.BuildTestData(t, "azurerm_extended_custom_locations", "test") + data := acceptance.BuildTestData(t, "azurerm_extended_custom_location", "test") r := CustomLocationResource{} credential, privateKey, publicKey := r.getCredentials(t) @@ -55,20 +56,63 @@ func TestAccExtendedLocationCustomLocations_basic(t *testing.T) { }) } +func TestAccExtendedLocationCustomLocations_update(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_extended_custom_location", "test") + r := CustomLocationResource{} + credential, privateKey, publicKey := r.getCredentials(t) + + data.ResourceTest(t, r, []acceptance.TestStep{ + { + Config: r.basic(data, credential, privateKey, publicKey), + Check: acceptance.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + ), + }, + data.ImportStep(), + { + Config: r.update(data, credential, privateKey, publicKey), + Check: acceptance.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + ), + }, + data.ImportStep(), + }) +} + func (r CustomLocationResource) basic(data acceptance.TestData, credential string, privateKey string, publicKey string) string { template := r.template(data, credential, publicKey, privateKey) return fmt.Sprintf(` %s -resource "azurerm_extended_custom_locations" "test" { - name = "acctestcustomlocation%d" +resource "azurerm_extended_custom_location" "test" { + name = "acctestcustomlocation%d" resource_group_name = azurerm_resource_group.test.name - location = azurerm_resource_group.test.location + location = azurerm_resource_group.test.location cluster_extension_ids = [ - "${azurerm_arc_kubernetes_cluster_extension.test.id}" + "${azurerm_arc_kubernetes_cluster_extension.test.id}" ] - display_name = "customlocation%[2]d" - namespace = "namespace%[2]d" + display_name = "customlocation%[2]d" + namespace = "namespace%[2]d" + host_resource_id = azurerm_arc_kubernetes_cluster.test.id +} +`, template, data.RandomInteger) +} + +func (r CustomLocationResource) update(data acceptance.TestData, credential string, privateKey string, publicKey string) string { + template := r.template(data, credential, publicKey, privateKey) + return fmt.Sprintf(` +%s + +resource "azurerm_extended_custom_location" "test" { + name = "acctestcustomlocation%d" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location + cluster_extension_ids = [ + "${azurerm_arc_kubernetes_cluster_extension.test.id}", + ] + + display_name = "customlocationupdate%[2]d" + namespace = "namespace%[2]d" host_resource_id = azurerm_arc_kubernetes_cluster.test.id } `, template, data.RandomInteger) @@ -80,14 +124,14 @@ func (r CustomLocationResource) template(data acceptance.TestData, credential st return fmt.Sprintf(` provider "azurerm" { features { - resource_group { - prevent_deletion_if_contains_resources = false - } + resource_group { + prevent_deletion_if_contains_resources = false + } } } resource "azurerm_resource_group" "test" { - name = "acctestRG-%[1]d" + name = "acctestRG-%[1]d" location = "%[2]s" } @@ -139,6 +183,12 @@ resource "azurerm_network_security_group" "my_terraform_nsg" { source_address_prefix = "*" destination_address_prefix = "*" } + + lifecycle { + ignore_changes = [ + security_rule, + ] + } } resource "azurerm_network_interface_security_group_association" "example" { @@ -169,6 +219,13 @@ resource "azurerm_linux_virtual_machine" "test" { sku = "18.04-LTS" version = "latest" } + + lifecycle { + ignore_changes = [ + identity, + tags, + ] + } } resource "azurerm_arc_kubernetes_cluster" "test" { @@ -188,14 +245,13 @@ resource "azurerm_arc_kubernetes_cluster" "test" { } resource "azurerm_arc_kubernetes_cluster_extension" "test" { - name = "acctest-kce-%[1]d" - cluster_id = azurerm_arc_kubernetes_cluster.test.id - extension_type = "microsoft.contoso.clusters" - target_namespace = "tf-ns4" - version = "1.2.0" + name = "extension4" + cluster_id = azurerm_arc_kubernetes_cluster.test.id + extension_type = "microsoft.vmware" + release_namespace = "vmware-extension" configuration_settings = { - "Microsoft.CustomLocation.ServiceAccount" = "tf-operator" + "Microsoft.CustomLocation.ServiceAccount" = "vmware-operator" } identity { diff --git a/internal/services/extendedlocation/testdata/install_agent.py b/internal/services/extendedlocation/testdata/install_agent.py index d39bccfab4f2e..2513e9aa7cbb4 100644 --- a/internal/services/extendedlocation/testdata/install_agent.py +++ b/internal/services/extendedlocation/testdata/install_agent.py @@ -184,6 +184,10 @@ def helm_install_release(chart_path, subscription_id, kubernetes_distro, kuberne "--set", "global.azureEnvironment={}".format( cloud_name), "--set", "systemDefaultValues.clusterconnect-agent.enabled=true", + "--set", "systemDefaultValues.customLocations.enabled=true", + # 51dfe1e8-70c6-4de5-a08e-e18aff23d815 is from: az ad sp show --id bc313c14-388c-4e7d-a58e-70017303ee3b --query id -o tsv + # refs: https://learn.microsoft.com/en-us/azure/azure-arc/kubernetes/custom-locations#enable-custom-locations-on-your-cluster + "--set", "systemDefaultValues.customLocations.oid={}".format("51dfe1e8-70c6-4de5-a08e-e18aff23d815"), "--namespace", "{}".format("azure-arc-release"), "--create-namespace", "--output", "json"] @@ -225,7 +229,7 @@ def install_agent(): # Retrieving Helm chart OCI Artifact location registry_path = get_helm_registry("https://westeurope.dp.kubernetesconfiguration.azure.com") - + # Get helm chart path chart_path = get_chart_path( registry_path, None, None, helm_client_location) diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/extendedlocation/2021-08-15/customlocations/README.md b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/extendedlocation/2021-08-15/customlocations/README.md index 0788615890d2d..3f56bf0f4e5c1 100644 --- a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/extendedlocation/2021-08-15/customlocations/README.md +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/extendedlocation/2021-08-15/customlocations/README.md @@ -24,7 +24,7 @@ client.Client.Authorizer = authorizer ```go ctx := context.TODO() -id := customlocations.NewCustomLocationID("12345678-1234-9876-4563-123456789012", "example-resource-group", "resourceValue") +id := customlocations.NewCustomLocationID("12345678-1234-9876-4563-123456789012", "example-resource-group", "customLocationValue") payload := customlocations.CustomLocation{ // ... @@ -41,7 +41,7 @@ if err := client.CreateOrUpdateThenPoll(ctx, id, payload); err != nil { ```go ctx := context.TODO() -id := customlocations.NewCustomLocationID("12345678-1234-9876-4563-123456789012", "example-resource-group", "resourceValue") +id := customlocations.NewCustomLocationID("12345678-1234-9876-4563-123456789012", "example-resource-group", "customLocationValue") if err := client.DeleteThenPoll(ctx, id); err != nil { // handle the error @@ -53,7 +53,7 @@ if err := client.DeleteThenPoll(ctx, id); err != nil { ```go ctx := context.TODO() -id := customlocations.NewCustomLocationID("12345678-1234-9876-4563-123456789012", "example-resource-group", "resourceValue") +id := customlocations.NewCustomLocationID("12345678-1234-9876-4563-123456789012", "example-resource-group", "customLocationValue") read, err := client.Get(ctx, id) if err != nil { @@ -103,7 +103,7 @@ for _, item := range items { ```go ctx := context.TODO() -id := customlocations.NewCustomLocationID("12345678-1234-9876-4563-123456789012", "example-resource-group", "resourceValue") +id := customlocations.NewCustomLocationID("12345678-1234-9876-4563-123456789012", "example-resource-group", "customLocationValue") // alternatively `client.ListEnabledResourceTypes(ctx, id)` can be used to do batched pagination items, err := client.ListEnabledResourceTypesComplete(ctx, id) @@ -120,7 +120,7 @@ for _, item := range items { ```go ctx := context.TODO() -id := customlocations.NewCustomLocationID("12345678-1234-9876-4563-123456789012", "example-resource-group", "resourceValue") +id := customlocations.NewCustomLocationID("12345678-1234-9876-4563-123456789012", "example-resource-group", "customLocationValue") payload := customlocations.PatchableCustomLocations{ // ... diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/extendedlocation/2021-08-15/customlocations/client.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/extendedlocation/2021-08-15/customlocations/client.go index 7d21398b667ca..bd1bcb809a51d 100644 --- a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/extendedlocation/2021-08-15/customlocations/client.go +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/extendedlocation/2021-08-15/customlocations/client.go @@ -1,18 +1,26 @@ package customlocations -import "github.com/Azure/go-autorest/autorest" +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 CustomLocationsClient struct { - Client autorest.Client - baseUri string + Client *resourcemanager.Client } -func NewCustomLocationsClientWithBaseURI(endpoint string) CustomLocationsClient { - return CustomLocationsClient{ - Client: autorest.NewClientWithUserAgent(userAgent()), - baseUri: endpoint, +func NewCustomLocationsClientWithBaseURI(sdkApi sdkEnv.Api) (*CustomLocationsClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "customlocations", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating CustomLocationsClient: %+v", err) } + + return &CustomLocationsClient{ + Client: client, + }, nil } diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/extendedlocation/2021-08-15/customlocations/constants.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/extendedlocation/2021-08-15/customlocations/constants.go index cd4ce2c90b951..45e439f98aae6 100644 --- a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/extendedlocation/2021-08-15/customlocations/constants.go +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/extendedlocation/2021-08-15/customlocations/constants.go @@ -1,6 +1,10 @@ package customlocations -import "strings" +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. @@ -17,6 +21,19 @@ func PossibleValuesForHostType() []string { } } +func (s *HostType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseHostType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseHostType(input string) (*HostType, error) { vals := map[string]HostType{ "kubernetes": HostTypeKubernetes, diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/extendedlocation/2021-08-15/customlocations/id_customlocation.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/extendedlocation/2021-08-15/customlocations/id_customlocation.go index e2d883cc6c16e..2dcae63d1c91c 100644 --- a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/extendedlocation/2021-08-15/customlocations/id_customlocation.go +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/extendedlocation/2021-08-15/customlocations/id_customlocation.go @@ -7,21 +7,24 @@ import ( "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 = CustomLocationId{} // CustomLocationId is a struct representing the Resource ID for a Custom Location type CustomLocationId struct { - SubscriptionId string - ResourceGroupName string - ResourceName string + SubscriptionId string + ResourceGroupName string + CustomLocationName string } // NewCustomLocationID returns a new CustomLocationId struct -func NewCustomLocationID(subscriptionId string, resourceGroupName string, resourceName string) CustomLocationId { +func NewCustomLocationID(subscriptionId string, resourceGroupName string, customLocationName string) CustomLocationId { return CustomLocationId{ - SubscriptionId: subscriptionId, - ResourceGroupName: resourceGroupName, - ResourceName: resourceName, + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + CustomLocationName: customLocationName, } } @@ -33,19 +36,9 @@ func ParseCustomLocationID(input string) (*CustomLocationId, error) { return nil, fmt.Errorf("parsing %q: %+v", input, err) } - var ok bool id := CustomLocationId{} - - if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { - return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) - } - - if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { - return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) - } - - if id.ResourceName, ok = parsed.Parsed["resourceName"]; !ok { - return nil, fmt.Errorf("the segment 'resourceName' was not found in the resource id %q", input) + if err := id.FromParseResult(*parsed); err != nil { + return nil, err } return &id, nil @@ -60,22 +53,30 @@ func ParseCustomLocationIDInsensitively(input string) (*CustomLocationId, error) return nil, fmt.Errorf("parsing %q: %+v", input, err) } - var ok bool id := CustomLocationId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} - if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { - return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) +func (id *CustomLocationId) 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 = parsed.Parsed["resourceGroupName"]; !ok { - return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) } - if id.ResourceName, ok = parsed.Parsed["resourceName"]; !ok { - return nil, fmt.Errorf("the segment 'resourceName' was not found in the resource id %q", input) + if id.CustomLocationName, ok = input.Parsed["customLocationName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "customLocationName", input) } - return &id, nil + return nil } // ValidateCustomLocationID checks that 'input' can be parsed as a Custom Location ID @@ -96,7 +97,7 @@ func ValidateCustomLocationID(input interface{}, key string) (warnings []string, // ID returns the formatted Custom Location ID func (id CustomLocationId) ID() string { fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ExtendedLocation/customLocations/%s" - return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ResourceName) + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.CustomLocationName) } // Segments returns a slice of Resource ID Segments which comprise this Custom Location ID @@ -109,7 +110,7 @@ func (id CustomLocationId) Segments() []resourceids.Segment { resourceids.StaticSegment("staticProviders", "providers", "providers"), resourceids.ResourceProviderSegment("staticMicrosoftExtendedLocation", "Microsoft.ExtendedLocation", "Microsoft.ExtendedLocation"), resourceids.StaticSegment("staticCustomLocations", "customLocations", "customLocations"), - resourceids.UserSpecifiedSegment("resourceName", "resourceValue"), + resourceids.UserSpecifiedSegment("customLocationName", "customLocationValue"), } } @@ -118,7 +119,7 @@ func (id CustomLocationId) String() string { components := []string{ fmt.Sprintf("Subscription: %q", id.SubscriptionId), fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), - fmt.Sprintf("Resource Name: %q", id.ResourceName), + fmt.Sprintf("Custom Location Name: %q", id.CustomLocationName), } return fmt.Sprintf("Custom Location (%s)", strings.Join(components, "\n")) } diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/extendedlocation/2021-08-15/customlocations/method_createorupdate.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/extendedlocation/2021-08-15/customlocations/method_createorupdate.go new file mode 100644 index 0000000000000..2f160e0faa7ea --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/extendedlocation/2021-08-15/customlocations/method_createorupdate.go @@ -0,0 +1,74 @@ +package customlocations + +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 CreateOrUpdateOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData +} + +// CreateOrUpdate ... +func (c CustomLocationsClient) CreateOrUpdate(ctx context.Context, id CustomLocationId, input CustomLocation) (result CreateOrUpdateOperationResponse, 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 +} + +// CreateOrUpdateThenPoll performs CreateOrUpdate then polls until it's completed +func (c CustomLocationsClient) CreateOrUpdateThenPoll(ctx context.Context, id CustomLocationId, input CustomLocation) error { + result, err := c.CreateOrUpdate(ctx, id, input) + if err != nil { + return fmt.Errorf("performing CreateOrUpdate: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after CreateOrUpdate: %+v", err) + } + + return nil +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/extendedlocation/2021-08-15/customlocations/method_createorupdate_autorest.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/extendedlocation/2021-08-15/customlocations/method_createorupdate_autorest.go deleted file mode 100644 index f9b415ae1b049..0000000000000 --- a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/extendedlocation/2021-08-15/customlocations/method_createorupdate_autorest.go +++ /dev/null @@ -1,79 +0,0 @@ -package customlocations - -import ( - "context" - "fmt" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" - "github.com/hashicorp/go-azure-helpers/polling" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type CreateOrUpdateOperationResponse struct { - Poller polling.LongRunningPoller - HttpResponse *http.Response -} - -// CreateOrUpdate ... -func (c CustomLocationsClient) CreateOrUpdate(ctx context.Context, id CustomLocationId, input CustomLocation) (result CreateOrUpdateOperationResponse, err error) { - req, err := c.preparerForCreateOrUpdate(ctx, id, input) - if err != nil { - err = autorest.NewErrorWithError(err, "customlocations.CustomLocationsClient", "CreateOrUpdate", nil, "Failure preparing request") - return - } - - result, err = c.senderForCreateOrUpdate(ctx, req) - if err != nil { - err = autorest.NewErrorWithError(err, "customlocations.CustomLocationsClient", "CreateOrUpdate", result.HttpResponse, "Failure sending request") - return - } - - return -} - -// CreateOrUpdateThenPoll performs CreateOrUpdate then polls until it's completed -func (c CustomLocationsClient) CreateOrUpdateThenPoll(ctx context.Context, id CustomLocationId, input CustomLocation) error { - result, err := c.CreateOrUpdate(ctx, id, input) - if err != nil { - return fmt.Errorf("performing CreateOrUpdate: %+v", err) - } - - if err := result.Poller.PollUntilDone(); err != nil { - return fmt.Errorf("polling after CreateOrUpdate: %+v", err) - } - - return nil -} - -// preparerForCreateOrUpdate prepares the CreateOrUpdate request. -func (c CustomLocationsClient) preparerForCreateOrUpdate(ctx context.Context, id CustomLocationId, input CustomLocation) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsPut(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithJSON(input), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// senderForCreateOrUpdate sends the CreateOrUpdate request. The method will close the -// http.Response Body if it receives an error. -func (c CustomLocationsClient) senderForCreateOrUpdate(ctx context.Context, req *http.Request) (future CreateOrUpdateOperationResponse, err error) { - var resp *http.Response - resp, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - return - } - - future.Poller, err = polling.NewPollerFromResponse(ctx, resp, c.Client, req.Method) - return -} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/extendedlocation/2021-08-15/customlocations/method_delete.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/extendedlocation/2021-08-15/customlocations/method_delete.go new file mode 100644 index 0000000000000..46eca9192ec69 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/extendedlocation/2021-08-15/customlocations/method_delete.go @@ -0,0 +1,70 @@ +package customlocations + +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 CustomLocationsClient) Delete(ctx context.Context, id CustomLocationId) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusNoContent, + }, + 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 CustomLocationsClient) DeleteThenPoll(ctx context.Context, id CustomLocationId) 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/extendedlocation/2021-08-15/customlocations/method_delete_autorest.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/extendedlocation/2021-08-15/customlocations/method_delete_autorest.go deleted file mode 100644 index 5f71cda5e35ce..0000000000000 --- a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/extendedlocation/2021-08-15/customlocations/method_delete_autorest.go +++ /dev/null @@ -1,78 +0,0 @@ -package customlocations - -import ( - "context" - "fmt" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" - "github.com/hashicorp/go-azure-helpers/polling" -) - -// 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 polling.LongRunningPoller - HttpResponse *http.Response -} - -// Delete ... -func (c CustomLocationsClient) Delete(ctx context.Context, id CustomLocationId) (result DeleteOperationResponse, err error) { - req, err := c.preparerForDelete(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "customlocations.CustomLocationsClient", "Delete", nil, "Failure preparing request") - return - } - - result, err = c.senderForDelete(ctx, req) - if err != nil { - err = autorest.NewErrorWithError(err, "customlocations.CustomLocationsClient", "Delete", result.HttpResponse, "Failure sending request") - return - } - - return -} - -// DeleteThenPoll performs Delete then polls until it's completed -func (c CustomLocationsClient) DeleteThenPoll(ctx context.Context, id CustomLocationId) error { - result, err := c.Delete(ctx, id) - if err != nil { - return fmt.Errorf("performing Delete: %+v", err) - } - - if err := result.Poller.PollUntilDone(); err != nil { - return fmt.Errorf("polling after Delete: %+v", err) - } - - return nil -} - -// preparerForDelete prepares the Delete request. -func (c CustomLocationsClient) preparerForDelete(ctx context.Context, id CustomLocationId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsDelete(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// senderForDelete sends the Delete request. The method will close the -// http.Response Body if it receives an error. -func (c CustomLocationsClient) senderForDelete(ctx context.Context, req *http.Request) (future DeleteOperationResponse, err error) { - var resp *http.Response - resp, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - return - } - - future.Poller, err = polling.NewPollerFromResponse(ctx, resp, c.Client, req.Method) - return -} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/extendedlocation/2021-08-15/customlocations/method_get.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/extendedlocation/2021-08-15/customlocations/method_get.go new file mode 100644 index 0000000000000..ebf3e87791be9 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/extendedlocation/2021-08-15/customlocations/method_get.go @@ -0,0 +1,51 @@ +package customlocations + +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 *CustomLocation +} + +// Get ... +func (c CustomLocationsClient) Get(ctx context.Context, id CustomLocationId) (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/extendedlocation/2021-08-15/customlocations/method_get_autorest.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/extendedlocation/2021-08-15/customlocations/method_get_autorest.go deleted file mode 100644 index 475d52753db26..0000000000000 --- a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/extendedlocation/2021-08-15/customlocations/method_get_autorest.go +++ /dev/null @@ -1,68 +0,0 @@ -package customlocations - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// 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 - Model *CustomLocation -} - -// Get ... -func (c CustomLocationsClient) Get(ctx context.Context, id CustomLocationId) (result GetOperationResponse, err error) { - req, err := c.preparerForGet(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "customlocations.CustomLocationsClient", "Get", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "customlocations.CustomLocationsClient", "Get", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForGet(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "customlocations.CustomLocationsClient", "Get", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForGet prepares the Get request. -func (c CustomLocationsClient) preparerForGet(ctx context.Context, id CustomLocationId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForGet handles the response to the Get request. The method always -// closes the http.Response Body. -func (c CustomLocationsClient) responderForGet(resp *http.Response) (result GetOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&result.Model), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/extendedlocation/2021-08-15/customlocations/method_listbyresourcegroup.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/extendedlocation/2021-08-15/customlocations/method_listbyresourcegroup.go new file mode 100644 index 0000000000000..5637a2b48bcd2 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/extendedlocation/2021-08-15/customlocations/method_listbyresourcegroup.go @@ -0,0 +1,90 @@ +package customlocations + +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 ListByResourceGroupOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]CustomLocation +} + +type ListByResourceGroupCompleteResult struct { + Items []CustomLocation +} + +// ListByResourceGroup ... +func (c CustomLocationsClient) ListByResourceGroup(ctx context.Context, id commonids.ResourceGroupId) (result ListByResourceGroupOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/providers/Microsoft.ExtendedLocation/customLocations", 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 *[]CustomLocation `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByResourceGroupComplete retrieves all the results into a single object +func (c CustomLocationsClient) ListByResourceGroupComplete(ctx context.Context, id commonids.ResourceGroupId) (ListByResourceGroupCompleteResult, error) { + return c.ListByResourceGroupCompleteMatchingPredicate(ctx, id, CustomLocationOperationPredicate{}) +} + +// ListByResourceGroupCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c CustomLocationsClient) ListByResourceGroupCompleteMatchingPredicate(ctx context.Context, id commonids.ResourceGroupId, predicate CustomLocationOperationPredicate) (result ListByResourceGroupCompleteResult, err error) { + items := make([]CustomLocation, 0) + + resp, err := c.ListByResourceGroup(ctx, id) + if err != nil { + 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 = ListByResourceGroupCompleteResult{ + Items: items, + } + return +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/extendedlocation/2021-08-15/customlocations/method_listbyresourcegroup_autorest.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/extendedlocation/2021-08-15/customlocations/method_listbyresourcegroup_autorest.go deleted file mode 100644 index 5ed484831cd68..0000000000000 --- a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/extendedlocation/2021-08-15/customlocations/method_listbyresourcegroup_autorest.go +++ /dev/null @@ -1,187 +0,0 @@ -package customlocations - -import ( - "context" - "fmt" - "net/http" - "net/url" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" - "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type ListByResourceGroupOperationResponse struct { - HttpResponse *http.Response - Model *[]CustomLocation - - nextLink *string - nextPageFunc func(ctx context.Context, nextLink string) (ListByResourceGroupOperationResponse, error) -} - -type ListByResourceGroupCompleteResult struct { - Items []CustomLocation -} - -func (r ListByResourceGroupOperationResponse) HasMore() bool { - return r.nextLink != nil -} - -func (r ListByResourceGroupOperationResponse) LoadMore(ctx context.Context) (resp ListByResourceGroupOperationResponse, err error) { - if !r.HasMore() { - err = fmt.Errorf("no more pages returned") - return - } - return r.nextPageFunc(ctx, *r.nextLink) -} - -// ListByResourceGroup ... -func (c CustomLocationsClient) ListByResourceGroup(ctx context.Context, id commonids.ResourceGroupId) (resp ListByResourceGroupOperationResponse, err error) { - req, err := c.preparerForListByResourceGroup(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "customlocations.CustomLocationsClient", "ListByResourceGroup", nil, "Failure preparing request") - return - } - - resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "customlocations.CustomLocationsClient", "ListByResourceGroup", resp.HttpResponse, "Failure sending request") - return - } - - resp, err = c.responderForListByResourceGroup(resp.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "customlocations.CustomLocationsClient", "ListByResourceGroup", resp.HttpResponse, "Failure responding to request") - return - } - return -} - -// preparerForListByResourceGroup prepares the ListByResourceGroup request. -func (c CustomLocationsClient) preparerForListByResourceGroup(ctx context.Context, id commonids.ResourceGroupId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(fmt.Sprintf("%s/providers/Microsoft.ExtendedLocation/customLocations", id.ID())), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// preparerForListByResourceGroupWithNextLink prepares the ListByResourceGroup request with the given nextLink token. -func (c CustomLocationsClient) preparerForListByResourceGroupWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { - uri, err := url.Parse(nextLink) - if err != nil { - return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) - } - queryParameters := map[string]interface{}{} - for k, v := range uri.Query() { - if len(v) == 0 { - continue - } - val := v[0] - val = autorest.Encode("query", val) - queryParameters[k] = val - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(uri.Path), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForListByResourceGroup handles the response to the ListByResourceGroup request. The method always -// closes the http.Response Body. -func (c CustomLocationsClient) responderForListByResourceGroup(resp *http.Response) (result ListByResourceGroupOperationResponse, err error) { - type page struct { - Values []CustomLocation `json:"value"` - NextLink *string `json:"nextLink"` - } - var respObj page - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&respObj), - autorest.ByClosing()) - result.HttpResponse = resp - result.Model = &respObj.Values - result.nextLink = respObj.NextLink - if respObj.NextLink != nil { - result.nextPageFunc = func(ctx context.Context, nextLink string) (result ListByResourceGroupOperationResponse, err error) { - req, err := c.preparerForListByResourceGroupWithNextLink(ctx, nextLink) - if err != nil { - err = autorest.NewErrorWithError(err, "customlocations.CustomLocationsClient", "ListByResourceGroup", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "customlocations.CustomLocationsClient", "ListByResourceGroup", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForListByResourceGroup(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "customlocations.CustomLocationsClient", "ListByResourceGroup", result.HttpResponse, "Failure responding to request") - return - } - - return - } - } - return -} - -// ListByResourceGroupComplete retrieves all of the results into a single object -func (c CustomLocationsClient) ListByResourceGroupComplete(ctx context.Context, id commonids.ResourceGroupId) (ListByResourceGroupCompleteResult, error) { - return c.ListByResourceGroupCompleteMatchingPredicate(ctx, id, CustomLocationOperationPredicate{}) -} - -// ListByResourceGroupCompleteMatchingPredicate retrieves all of the results and then applied the predicate -func (c CustomLocationsClient) ListByResourceGroupCompleteMatchingPredicate(ctx context.Context, id commonids.ResourceGroupId, predicate CustomLocationOperationPredicate) (resp ListByResourceGroupCompleteResult, err error) { - items := make([]CustomLocation, 0) - - page, err := c.ListByResourceGroup(ctx, id) - if err != nil { - err = fmt.Errorf("loading the initial page: %+v", err) - return - } - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - - for page.HasMore() { - page, err = page.LoadMore(ctx) - if err != nil { - err = fmt.Errorf("loading the next page: %+v", err) - return - } - - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - } - - out := ListByResourceGroupCompleteResult{ - Items: items, - } - return out, nil -} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/extendedlocation/2021-08-15/customlocations/method_listbysubscription.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/extendedlocation/2021-08-15/customlocations/method_listbysubscription.go new file mode 100644 index 0000000000000..2c5015119ac44 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/extendedlocation/2021-08-15/customlocations/method_listbysubscription.go @@ -0,0 +1,90 @@ +package customlocations + +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 ListBySubscriptionOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]CustomLocation +} + +type ListBySubscriptionCompleteResult struct { + Items []CustomLocation +} + +// ListBySubscription ... +func (c CustomLocationsClient) ListBySubscription(ctx context.Context, id commonids.SubscriptionId) (result ListBySubscriptionOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/providers/Microsoft.ExtendedLocation/customLocations", 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 *[]CustomLocation `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListBySubscriptionComplete retrieves all the results into a single object +func (c CustomLocationsClient) ListBySubscriptionComplete(ctx context.Context, id commonids.SubscriptionId) (ListBySubscriptionCompleteResult, error) { + return c.ListBySubscriptionCompleteMatchingPredicate(ctx, id, CustomLocationOperationPredicate{}) +} + +// ListBySubscriptionCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c CustomLocationsClient) ListBySubscriptionCompleteMatchingPredicate(ctx context.Context, id commonids.SubscriptionId, predicate CustomLocationOperationPredicate) (result ListBySubscriptionCompleteResult, err error) { + items := make([]CustomLocation, 0) + + resp, err := c.ListBySubscription(ctx, id) + if err != nil { + 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 = ListBySubscriptionCompleteResult{ + Items: items, + } + return +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/extendedlocation/2021-08-15/customlocations/method_listbysubscription_autorest.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/extendedlocation/2021-08-15/customlocations/method_listbysubscription_autorest.go deleted file mode 100644 index fed94c9df8bef..0000000000000 --- a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/extendedlocation/2021-08-15/customlocations/method_listbysubscription_autorest.go +++ /dev/null @@ -1,187 +0,0 @@ -package customlocations - -import ( - "context" - "fmt" - "net/http" - "net/url" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" - "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type ListBySubscriptionOperationResponse struct { - HttpResponse *http.Response - Model *[]CustomLocation - - nextLink *string - nextPageFunc func(ctx context.Context, nextLink string) (ListBySubscriptionOperationResponse, error) -} - -type ListBySubscriptionCompleteResult struct { - Items []CustomLocation -} - -func (r ListBySubscriptionOperationResponse) HasMore() bool { - return r.nextLink != nil -} - -func (r ListBySubscriptionOperationResponse) LoadMore(ctx context.Context) (resp ListBySubscriptionOperationResponse, err error) { - if !r.HasMore() { - err = fmt.Errorf("no more pages returned") - return - } - return r.nextPageFunc(ctx, *r.nextLink) -} - -// ListBySubscription ... -func (c CustomLocationsClient) ListBySubscription(ctx context.Context, id commonids.SubscriptionId) (resp ListBySubscriptionOperationResponse, err error) { - req, err := c.preparerForListBySubscription(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "customlocations.CustomLocationsClient", "ListBySubscription", nil, "Failure preparing request") - return - } - - resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "customlocations.CustomLocationsClient", "ListBySubscription", resp.HttpResponse, "Failure sending request") - return - } - - resp, err = c.responderForListBySubscription(resp.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "customlocations.CustomLocationsClient", "ListBySubscription", resp.HttpResponse, "Failure responding to request") - return - } - return -} - -// preparerForListBySubscription prepares the ListBySubscription request. -func (c CustomLocationsClient) preparerForListBySubscription(ctx context.Context, id commonids.SubscriptionId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(fmt.Sprintf("%s/providers/Microsoft.ExtendedLocation/customLocations", id.ID())), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// preparerForListBySubscriptionWithNextLink prepares the ListBySubscription request with the given nextLink token. -func (c CustomLocationsClient) preparerForListBySubscriptionWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { - uri, err := url.Parse(nextLink) - if err != nil { - return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) - } - queryParameters := map[string]interface{}{} - for k, v := range uri.Query() { - if len(v) == 0 { - continue - } - val := v[0] - val = autorest.Encode("query", val) - queryParameters[k] = val - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(uri.Path), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForListBySubscription handles the response to the ListBySubscription request. The method always -// closes the http.Response Body. -func (c CustomLocationsClient) responderForListBySubscription(resp *http.Response) (result ListBySubscriptionOperationResponse, err error) { - type page struct { - Values []CustomLocation `json:"value"` - NextLink *string `json:"nextLink"` - } - var respObj page - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&respObj), - autorest.ByClosing()) - result.HttpResponse = resp - result.Model = &respObj.Values - result.nextLink = respObj.NextLink - if respObj.NextLink != nil { - result.nextPageFunc = func(ctx context.Context, nextLink string) (result ListBySubscriptionOperationResponse, err error) { - req, err := c.preparerForListBySubscriptionWithNextLink(ctx, nextLink) - if err != nil { - err = autorest.NewErrorWithError(err, "customlocations.CustomLocationsClient", "ListBySubscription", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "customlocations.CustomLocationsClient", "ListBySubscription", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForListBySubscription(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "customlocations.CustomLocationsClient", "ListBySubscription", result.HttpResponse, "Failure responding to request") - return - } - - return - } - } - return -} - -// ListBySubscriptionComplete retrieves all of the results into a single object -func (c CustomLocationsClient) ListBySubscriptionComplete(ctx context.Context, id commonids.SubscriptionId) (ListBySubscriptionCompleteResult, error) { - return c.ListBySubscriptionCompleteMatchingPredicate(ctx, id, CustomLocationOperationPredicate{}) -} - -// ListBySubscriptionCompleteMatchingPredicate retrieves all of the results and then applied the predicate -func (c CustomLocationsClient) ListBySubscriptionCompleteMatchingPredicate(ctx context.Context, id commonids.SubscriptionId, predicate CustomLocationOperationPredicate) (resp ListBySubscriptionCompleteResult, err error) { - items := make([]CustomLocation, 0) - - page, err := c.ListBySubscription(ctx, id) - if err != nil { - err = fmt.Errorf("loading the initial page: %+v", err) - return - } - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - - for page.HasMore() { - page, err = page.LoadMore(ctx) - if err != nil { - err = fmt.Errorf("loading the next page: %+v", err) - return - } - - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - } - - out := ListBySubscriptionCompleteResult{ - Items: items, - } - return out, nil -} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/extendedlocation/2021-08-15/customlocations/method_listenabledresourcetypes.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/extendedlocation/2021-08-15/customlocations/method_listenabledresourcetypes.go new file mode 100644 index 0000000000000..1e20cc9e1ebba --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/extendedlocation/2021-08-15/customlocations/method_listenabledresourcetypes.go @@ -0,0 +1,89 @@ +package customlocations + +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 ListEnabledResourceTypesOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]EnabledResourceType +} + +type ListEnabledResourceTypesCompleteResult struct { + Items []EnabledResourceType +} + +// ListEnabledResourceTypes ... +func (c CustomLocationsClient) ListEnabledResourceTypes(ctx context.Context, id CustomLocationId) (result ListEnabledResourceTypesOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/enabledResourceTypes", 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 *[]EnabledResourceType `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListEnabledResourceTypesComplete retrieves all the results into a single object +func (c CustomLocationsClient) ListEnabledResourceTypesComplete(ctx context.Context, id CustomLocationId) (ListEnabledResourceTypesCompleteResult, error) { + return c.ListEnabledResourceTypesCompleteMatchingPredicate(ctx, id, EnabledResourceTypeOperationPredicate{}) +} + +// ListEnabledResourceTypesCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c CustomLocationsClient) ListEnabledResourceTypesCompleteMatchingPredicate(ctx context.Context, id CustomLocationId, predicate EnabledResourceTypeOperationPredicate) (result ListEnabledResourceTypesCompleteResult, err error) { + items := make([]EnabledResourceType, 0) + + resp, err := c.ListEnabledResourceTypes(ctx, id) + if err != nil { + 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 = ListEnabledResourceTypesCompleteResult{ + Items: items, + } + return +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/extendedlocation/2021-08-15/customlocations/method_listenabledresourcetypes_autorest.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/extendedlocation/2021-08-15/customlocations/method_listenabledresourcetypes_autorest.go deleted file mode 100644 index 5febee715d99e..0000000000000 --- a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/extendedlocation/2021-08-15/customlocations/method_listenabledresourcetypes_autorest.go +++ /dev/null @@ -1,186 +0,0 @@ -package customlocations - -import ( - "context" - "fmt" - "net/http" - "net/url" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type ListEnabledResourceTypesOperationResponse struct { - HttpResponse *http.Response - Model *[]EnabledResourceType - - nextLink *string - nextPageFunc func(ctx context.Context, nextLink string) (ListEnabledResourceTypesOperationResponse, error) -} - -type ListEnabledResourceTypesCompleteResult struct { - Items []EnabledResourceType -} - -func (r ListEnabledResourceTypesOperationResponse) HasMore() bool { - return r.nextLink != nil -} - -func (r ListEnabledResourceTypesOperationResponse) LoadMore(ctx context.Context) (resp ListEnabledResourceTypesOperationResponse, err error) { - if !r.HasMore() { - err = fmt.Errorf("no more pages returned") - return - } - return r.nextPageFunc(ctx, *r.nextLink) -} - -// ListEnabledResourceTypes ... -func (c CustomLocationsClient) ListEnabledResourceTypes(ctx context.Context, id CustomLocationId) (resp ListEnabledResourceTypesOperationResponse, err error) { - req, err := c.preparerForListEnabledResourceTypes(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "customlocations.CustomLocationsClient", "ListEnabledResourceTypes", nil, "Failure preparing request") - return - } - - resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "customlocations.CustomLocationsClient", "ListEnabledResourceTypes", resp.HttpResponse, "Failure sending request") - return - } - - resp, err = c.responderForListEnabledResourceTypes(resp.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "customlocations.CustomLocationsClient", "ListEnabledResourceTypes", resp.HttpResponse, "Failure responding to request") - return - } - return -} - -// preparerForListEnabledResourceTypes prepares the ListEnabledResourceTypes request. -func (c CustomLocationsClient) preparerForListEnabledResourceTypes(ctx context.Context, id CustomLocationId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(fmt.Sprintf("%s/enabledResourceTypes", id.ID())), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// preparerForListEnabledResourceTypesWithNextLink prepares the ListEnabledResourceTypes request with the given nextLink token. -func (c CustomLocationsClient) preparerForListEnabledResourceTypesWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { - uri, err := url.Parse(nextLink) - if err != nil { - return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) - } - queryParameters := map[string]interface{}{} - for k, v := range uri.Query() { - if len(v) == 0 { - continue - } - val := v[0] - val = autorest.Encode("query", val) - queryParameters[k] = val - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(uri.Path), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForListEnabledResourceTypes handles the response to the ListEnabledResourceTypes request. The method always -// closes the http.Response Body. -func (c CustomLocationsClient) responderForListEnabledResourceTypes(resp *http.Response) (result ListEnabledResourceTypesOperationResponse, err error) { - type page struct { - Values []EnabledResourceType `json:"value"` - NextLink *string `json:"nextLink"` - } - var respObj page - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&respObj), - autorest.ByClosing()) - result.HttpResponse = resp - result.Model = &respObj.Values - result.nextLink = respObj.NextLink - if respObj.NextLink != nil { - result.nextPageFunc = func(ctx context.Context, nextLink string) (result ListEnabledResourceTypesOperationResponse, err error) { - req, err := c.preparerForListEnabledResourceTypesWithNextLink(ctx, nextLink) - if err != nil { - err = autorest.NewErrorWithError(err, "customlocations.CustomLocationsClient", "ListEnabledResourceTypes", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "customlocations.CustomLocationsClient", "ListEnabledResourceTypes", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForListEnabledResourceTypes(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "customlocations.CustomLocationsClient", "ListEnabledResourceTypes", result.HttpResponse, "Failure responding to request") - return - } - - return - } - } - return -} - -// ListEnabledResourceTypesComplete retrieves all of the results into a single object -func (c CustomLocationsClient) ListEnabledResourceTypesComplete(ctx context.Context, id CustomLocationId) (ListEnabledResourceTypesCompleteResult, error) { - return c.ListEnabledResourceTypesCompleteMatchingPredicate(ctx, id, EnabledResourceTypeOperationPredicate{}) -} - -// ListEnabledResourceTypesCompleteMatchingPredicate retrieves all of the results and then applied the predicate -func (c CustomLocationsClient) ListEnabledResourceTypesCompleteMatchingPredicate(ctx context.Context, id CustomLocationId, predicate EnabledResourceTypeOperationPredicate) (resp ListEnabledResourceTypesCompleteResult, err error) { - items := make([]EnabledResourceType, 0) - - page, err := c.ListEnabledResourceTypes(ctx, id) - if err != nil { - err = fmt.Errorf("loading the initial page: %+v", err) - return - } - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - - for page.HasMore() { - page, err = page.LoadMore(ctx) - if err != nil { - err = fmt.Errorf("loading the next page: %+v", err) - return - } - - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - } - - out := ListEnabledResourceTypesCompleteResult{ - Items: items, - } - return out, nil -} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/extendedlocation/2021-08-15/customlocations/method_update.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/extendedlocation/2021-08-15/customlocations/method_update.go new file mode 100644 index 0000000000000..8a0507b085416 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/extendedlocation/2021-08-15/customlocations/method_update.go @@ -0,0 +1,55 @@ +package customlocations + +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 UpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *CustomLocation +} + +// Update ... +func (c CustomLocationsClient) Update(ctx context.Context, id CustomLocationId, input PatchableCustomLocations) (result UpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + 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 + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/extendedlocation/2021-08-15/customlocations/method_update_autorest.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/extendedlocation/2021-08-15/customlocations/method_update_autorest.go deleted file mode 100644 index d372dbf546d91..0000000000000 --- a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/extendedlocation/2021-08-15/customlocations/method_update_autorest.go +++ /dev/null @@ -1,69 +0,0 @@ -package customlocations - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// 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 { - HttpResponse *http.Response - Model *CustomLocation -} - -// Update ... -func (c CustomLocationsClient) Update(ctx context.Context, id CustomLocationId, input PatchableCustomLocations) (result UpdateOperationResponse, err error) { - req, err := c.preparerForUpdate(ctx, id, input) - if err != nil { - err = autorest.NewErrorWithError(err, "customlocations.CustomLocationsClient", "Update", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "customlocations.CustomLocationsClient", "Update", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForUpdate(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "customlocations.CustomLocationsClient", "Update", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForUpdate prepares the Update request. -func (c CustomLocationsClient) preparerForUpdate(ctx context.Context, id CustomLocationId, input PatchableCustomLocations) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsPatch(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithJSON(input), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForUpdate handles the response to the Update request. The method always -// closes the http.Response Body. -func (c CustomLocationsClient) responderForUpdate(resp *http.Response) (result UpdateOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&result.Model), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/extendedlocation/2021-08-15/customlocations/model_customlocation.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/extendedlocation/2021-08-15/customlocations/model_customlocation.go index 08779913a34d8..1206e9eb6355a 100644 --- a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/extendedlocation/2021-08-15/customlocations/model_customlocation.go +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/extendedlocation/2021-08-15/customlocations/model_customlocation.go @@ -13,7 +13,7 @@ type CustomLocation struct { Identity *identity.SystemAssigned `json:"identity,omitempty"` Location string `json:"location"` Name *string `json:"name,omitempty"` - Properties *CustomLocationProperties `json:"properties"` + Properties *CustomLocationProperties `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/extendedlocation/2021-08-15/customlocations/model_customlocationproperties.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/extendedlocation/2021-08-15/customlocations/model_customlocationproperties.go index aa074e5226cf8..8a1b9867bd69f 100644 --- a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/extendedlocation/2021-08-15/customlocations/model_customlocationproperties.go +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/extendedlocation/2021-08-15/customlocations/model_customlocationproperties.go @@ -4,7 +4,7 @@ package customlocations // Licensed under the MIT License. See NOTICE.txt in the project root for license information. type CustomLocationProperties struct { - Authentication *CustomLocationPropertiesAuthentication `json:"authentication"` + Authentication *CustomLocationPropertiesAuthentication `json:"authentication,omitempty"` ClusterExtensionIds *[]string `json:"clusterExtensionIds,omitempty"` DisplayName *string `json:"displayName,omitempty"` HostResourceId *string `json:"hostResourceId,omitempty"` diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/extendedlocation/2021-08-15/customlocations/model_enabledresourcetype.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/extendedlocation/2021-08-15/customlocations/model_enabledresourcetype.go index a9092e124d3dd..ea81da07f08fb 100644 --- a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/extendedlocation/2021-08-15/customlocations/model_enabledresourcetype.go +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/extendedlocation/2021-08-15/customlocations/model_enabledresourcetype.go @@ -10,7 +10,7 @@ import ( type EnabledResourceType struct { Id *string `json:"id,omitempty"` Name *string `json:"name,omitempty"` - Properties *EnabledResourceTypeProperties `json:"properties"` + Properties *EnabledResourceTypeProperties `json:"properties,omitempty"` SystemData *systemdata.SystemData `json:"systemData,omitempty"` Type *string `json:"type,omitempty"` } diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/extendedlocation/2021-08-15/customlocations/model_patchablecustomlocations.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/extendedlocation/2021-08-15/customlocations/model_patchablecustomlocations.go index deb24ffccf417..005fda74441bb 100644 --- a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/extendedlocation/2021-08-15/customlocations/model_patchablecustomlocations.go +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/extendedlocation/2021-08-15/customlocations/model_patchablecustomlocations.go @@ -9,6 +9,6 @@ import ( type PatchableCustomLocations struct { Identity *identity.SystemAssigned `json:"identity,omitempty"` - Properties *CustomLocationProperties `json:"properties"` + Properties *CustomLocationProperties `json:"properties,omitempty"` Tags *map[string]string `json:"tags,omitempty"` } diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/extendedlocation/2021-08-15/customlocations/predicates.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/extendedlocation/2021-08-15/customlocations/predicates.go index 27e83d9df5ea2..f18b5aa943f10 100644 --- a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/extendedlocation/2021-08-15/customlocations/predicates.go +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/extendedlocation/2021-08-15/customlocations/predicates.go @@ -1,5 +1,8 @@ package customlocations +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + type CustomLocationOperationPredicate struct { Id *string Location *string @@ -9,7 +12,7 @@ type CustomLocationOperationPredicate struct { func (p CustomLocationOperationPredicate) Matches(input CustomLocation) bool { - if p.Id != nil && (input.Id == nil && *p.Id != *input.Id) { + if p.Id != nil && (input.Id == nil || *p.Id != *input.Id) { return false } @@ -17,11 +20,11 @@ func (p CustomLocationOperationPredicate) Matches(input CustomLocation) bool { return false } - if p.Name != nil && (input.Name == nil && *p.Name != *input.Name) { + if p.Name != nil && (input.Name == nil || *p.Name != *input.Name) { return false } - if p.Type != nil && (input.Type == nil && *p.Type != *input.Type) { + if p.Type != nil && (input.Type == nil || *p.Type != *input.Type) { return false } @@ -36,15 +39,15 @@ type EnabledResourceTypeOperationPredicate struct { func (p EnabledResourceTypeOperationPredicate) Matches(input EnabledResourceType) bool { - if p.Id != nil && (input.Id == nil && *p.Id != *input.Id) { + if p.Id != nil && (input.Id == nil || *p.Id != *input.Id) { return false } - if p.Name != nil && (input.Name == nil && *p.Name != *input.Name) { + if p.Name != nil && (input.Name == nil || *p.Name != *input.Name) { return false } - if p.Type != nil && (input.Type == nil && *p.Type != *input.Type) { + if p.Type != nil && (input.Type == nil || *p.Type != *input.Type) { return false } diff --git a/website/docs/r/extended_location_custom_location.html.markdown b/website/docs/r/extended_location_custom_location.html.markdown new file mode 100644 index 0000000000000..b80df9484a67d --- /dev/null +++ b/website/docs/r/extended_location_custom_location.html.markdown @@ -0,0 +1,105 @@ +--- +subcategory: "Extended Location" +layout: "azurerm" +page_title: "Azure Resource Manager: azurerm_extended_location_custom_location" +description: |- + Manages a Custom Location within an Extended Location. +--- + +# azurerm_extended_location_custom_location + +Manages a Custom Location within an Extended Location. + +## Example Usage + +```hcl +resource "azurerm_resource_group" "example" { + name = "example-resources" + location = "West Europe" +} + +resource "azurerm_arc_kubernetes_cluster" "example" { + name = "example-akcc" + resource_group_name = azurerm_resource_group.example.name + location = "West Europe" + agent_public_key_certificate = filebase64("testdata/public.cer") + + identity { + type = "SystemAssigned" + } + + tags = { + ENV = "Test" + } +} + +resource "azurerm_arc_kubernetes_cluster_extension" "example" { + name = "example-ext" + cluster_id = azurerm_arc_kubernetes_cluster.example.id + extension_type = "microsoft.flux" +} + +resource "azurerm_extended_location_custom_location" "example" { + name = "example-custom-location" + resource_group_name = azurerm_resource_group.example.name + location = "West Europe" + cluster_extension_ids = [ + "${azurerm_arc_kubernetes_cluster_extension.test.id}" + ] + display_name = "example-custom-location" + namespace = "example-namespace" + host_resource_id = azurerm_arc_kubernetes_cluster.example.id +} +``` + +## Arguments Reference + +The following arguments are supported: + +* `name` - (Required) Specifies the name which should be used for this Custom Location. Changing this forces a new Custom Location to be created. + +* `resource_group_name` - (Required) Specifies the name of the Resource Group where the Custom Location should exist. Changing this forces a new Custom Location to be created. + +* `location` - (Required) Specifies the Azure location where the Custom Location should exist. Changing this forces a new Custom Location to be created. + +* `namespace` - (Required) Specifies the namespace of the Custom Location.Changing this forces a new Custom Location to be created. + +* `cluster_extension_ids` - (Required) Specifies the list of Cluster Extension IDs. + +* `host_resource_id` - (Required) Specifies the host resource ID. + +* `authentication` - (Optional) An `authentication` block as defined below. + +* `display_name` - (Optional) Specifies the display name of the Custom Location. + +* `host_type` - (Optional) Specifies the host type of the Custom Location. The only possible values is `KubernetesCluster`. + +--- + +An `authentication` block supports the following: + +* `type` - (Required) Specifies the type of authentication. + +* `value` - (Required) Specifies the value of authentication. + +## Attributes Reference + +* `id` - The ID of the Custom Location. + +## 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 Custom Location. +* `read` - (Defaults to 5 minutes) Used when retrieving the Custom Location. +* `update` - (Defaults to 30 minutes) Used when updating the Custom Location. +* `delete` - (Defaults to 30 minutes) Used when deleting the Custom Location. + +## Import + +Custom Locations can be imported using the resource id, e.g. + +```shell +terraform import azurerm_extended_location_custom_location.example /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/example-resources/providers/Microsoft.ExtendedLocation/customLocations/example-custom-location +``` +