diff --git a/internal/services/containers/client/client.go b/internal/services/containers/client/client.go index 87b96e3b33d6..aa65540a8444 100644 --- a/internal/services/containers/client/client.go +++ b/internal/services/containers/client/client.go @@ -9,6 +9,7 @@ import ( "github.com/hashicorp/go-azure-sdk/resource-manager/containerservice/2023-02-02-preview/agentpools" "github.com/hashicorp/go-azure-sdk/resource-manager/containerservice/2023-02-02-preview/maintenanceconfigurations" "github.com/hashicorp/go-azure-sdk/resource-manager/containerservice/2023-02-02-preview/managedclusters" + "github.com/hashicorp/go-azure-sdk/resource-manager/containerservice/2023-02-02-preview/snapshots" "github.com/hashicorp/go-azure-sdk/resource-manager/kubernetesconfiguration/2022-11-01/extensions" "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" "github.com/hashicorp/terraform-provider-azurerm/internal/common" @@ -24,6 +25,7 @@ type Client struct { KubernetesExtensionsClient *extensions.ExtensionsClient MaintenanceConfigurationsClient *maintenanceconfigurations.MaintenanceConfigurationsClient ServicesClient *containerservices.ContainerServicesClient + SnapshotClient *snapshots.SnapshotsClient Environment azure.Environment } @@ -61,6 +63,9 @@ func NewContainersClient(o *common.ClientOptions) (*Client, error) { servicesClient := containerservices.NewContainerServicesClientWithBaseURI(o.ResourceManagerEndpoint) o.ConfigureClient(&servicesClient.Client, o.ResourceManagerAuthorizer) + snapshotClient := snapshots.NewSnapshotsClientWithBaseURI(o.ResourceManagerEndpoint) + o.ConfigureClient(&snapshotClient.Client, o.ResourceManagerAuthorizer) + return &Client{ AgentPoolsClient: &agentPoolsClient, ContainerInstanceClient: &containerInstanceClient, @@ -70,6 +75,7 @@ func NewContainersClient(o *common.ClientOptions) (*Client, error) { KubernetesExtensionsClient: &kubernetesExtensionsClient, MaintenanceConfigurationsClient: &maintenanceConfigurationsClient, ServicesClient: &servicesClient, + SnapshotClient: &snapshotClient, Environment: o.AzureEnvironment, }, nil } diff --git a/internal/services/containers/kubernetes_cluster_node_pool_resource.go b/internal/services/containers/kubernetes_cluster_node_pool_resource.go index b063be57e0c3..a4bdb1de57ef 100644 --- a/internal/services/containers/kubernetes_cluster_node_pool_resource.go +++ b/internal/services/containers/kubernetes_cluster_node_pool_resource.go @@ -16,6 +16,7 @@ import ( "github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-01/proximityplacementgroups" "github.com/hashicorp/go-azure-sdk/resource-manager/containerservice/2023-02-02-preview/agentpools" "github.com/hashicorp/go-azure-sdk/resource-manager/containerservice/2023-02-02-preview/managedclusters" + "github.com/hashicorp/go-azure-sdk/resource-manager/containerservice/2023-02-02-preview/snapshots" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-provider-azurerm/helpers/tf" "github.com/hashicorp/terraform-provider-azurerm/internal/clients" @@ -294,6 +295,13 @@ func resourceKubernetesClusterNodePool() *pluginsdk.Resource { ValidateFunc: proximityplacementgroups.ValidateProximityPlacementGroupID, }, + "snapshot_id": { + Type: pluginsdk.TypeString, + Optional: true, + ForceNew: true, + ValidateFunc: snapshots.ValidateSnapshotID, + }, + "spot_max_price": { Type: pluginsdk.TypeFloat, Optional: true, @@ -582,6 +590,12 @@ func resourceKubernetesClusterNodePoolCreate(d *pluginsdk.ResourceData, meta int profile.NetworkProfile = expandAgentPoolNetworkProfile(networkProfile) } + if snapshotId := d.Get("snapshot_id").(string); snapshotId != "" { + profile.CreationData = &agentpools.CreationData{ + SourceResourceId: utils.String(snapshotId), + } + } + parameters := agentpools.AgentPool{ Name: utils.String(id.AgentPoolName), Properties: &profile, @@ -812,6 +826,10 @@ func resourceKubernetesClusterNodePoolRead(d *pluginsdk.ResourceData, meta inter d.Set("kubelet_disk_type", string(*v)) } + if props.CreationData != nil { + d.Set("snapshot_id", props.CreationData.SourceResourceId) + } + scaleDownMode := string(managedclusters.ScaleDownModeDelete) if v := props.ScaleDownMode; v != nil { scaleDownMode = string(*v) diff --git a/internal/services/containers/kubernetes_cluster_node_pool_resource_test.go b/internal/services/containers/kubernetes_cluster_node_pool_resource_test.go index 8e9298d9957a..f07b725eced3 100644 --- a/internal/services/containers/kubernetes_cluster_node_pool_resource_test.go +++ b/internal/services/containers/kubernetes_cluster_node_pool_resource_test.go @@ -10,6 +10,8 @@ import ( "github.com/hashicorp/go-azure-helpers/lang/response" "github.com/hashicorp/go-azure-sdk/resource-manager/containerservice/2023-02-02-preview/agentpools" "github.com/hashicorp/go-azure-sdk/resource-manager/containerservice/2023-02-02-preview/managedclusters" + "github.com/hashicorp/go-azure-sdk/resource-manager/containerservice/2023-02-02-preview/snapshots" + "github.com/hashicorp/terraform-plugin-testing/terraform" "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" @@ -955,6 +957,65 @@ func TestAccKubernetesClusterNodePool_nodeIPTags(t *testing.T) { }) } +func TestAccKubernetesClusterNodePool_snapshotId(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_kubernetes_cluster_node_pool", "test") + r := KubernetesClusterNodePoolResource{} + + data.ResourceTest(t, r, []acceptance.TestStep{ + { + Config: r.snapshotSource(data), + Check: acceptance.ComposeTestCheckFunc( + data.CheckWithClientForResource(func(ctx context.Context, clients *clients.Client, state *terraform.InstanceState) error { + client := clients.Containers.SnapshotClient + poolId, err := agentpools.ParseAgentPoolID(state.ID) + if err != nil { + return err + } + id := snapshots.NewSnapshotID(poolId.SubscriptionId, poolId.ResourceGroupName, data.RandomString) + snapshot := snapshots.Snapshot{ + Location: data.Locations.Primary, + Properties: &snapshots.SnapshotProperties{ + CreationData: &snapshots.CreationData{ + SourceResourceId: utils.String(poolId.ID()), + }, + }, + } + _, err = client.CreateOrUpdate(ctx, id, snapshot) + if err != nil { + return fmt.Errorf("creating %s: %+v", id, err) + } + return nil + }, "azurerm_kubernetes_cluster_node_pool.source"), + ), + }, + { + Config: r.snapshotRestore(data), + Check: acceptance.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + ), + }, + data.ImportStep(), + { + Config: r.snapshotSource(data), + Check: acceptance.ComposeTestCheckFunc( + data.CheckWithClientForResource(func(ctx context.Context, clients *clients.Client, state *terraform.InstanceState) error { + client := clients.Containers.SnapshotClient + poolId, err := agentpools.ParseAgentPoolID(state.ID) + if err != nil { + return err + } + id := snapshots.NewSnapshotID(poolId.SubscriptionId, poolId.ResourceGroupName, data.RandomString) + _, err = client.Delete(ctx, id) + if err != nil { + return fmt.Errorf("creating %s: %+v", id, err) + } + return nil + }, "azurerm_kubernetes_cluster_node_pool.source"), + ), + }, + }) +} + func (t KubernetesClusterNodePoolResource) Exists(ctx context.Context, clients *clients.Client, state *pluginsdk.InstanceState) (*bool, error) { id, err := agentpools.ParseAgentPoolID(state.ID) if err != nil { @@ -2544,3 +2605,87 @@ resource "azurerm_kubernetes_cluster_node_pool" "test" { } `, data.Locations.Primary, data.RandomInteger) } + +func (KubernetesClusterNodePoolResource) snapshotSource(data acceptance.TestData) string { + return fmt.Sprintf(` +provider "azurerm" { + features {} +} + +resource "azurerm_resource_group" "test" { + name = "acctestRG-aks-%[2]d" + location = "%[1]s" +} + +resource "azurerm_kubernetes_cluster" "test" { + name = "acctestaks%[2]d" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name + dns_prefix = "acctestaks%[2]d" + default_node_pool { + name = "default" + node_count = 1 + vm_size = "Standard_D2s_v3" + } + identity { + type = "SystemAssigned" + } +} + +resource "azurerm_kubernetes_cluster_node_pool" "source" { + name = "source" + kubernetes_cluster_id = azurerm_kubernetes_cluster.test.id + vm_size = "Standard_D2s_v3" +} + `, data.Locations.Primary, data.RandomInteger) +} + +func (KubernetesClusterNodePoolResource) snapshotRestore(data acceptance.TestData) string { + return fmt.Sprintf(` +provider "azurerm" { + features {} +} + +resource "azurerm_resource_group" "test" { + name = "acctestRG-aks-%[2]d" + location = "%[1]s" +} + +resource "azurerm_kubernetes_cluster" "test" { + name = "acctestaks%[2]d" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name + dns_prefix = "acctestaks%[2]d" + default_node_pool { + name = "default" + node_count = 1 + vm_size = "Standard_D2s_v3" + } + identity { + type = "SystemAssigned" + } +} + +resource "azurerm_kubernetes_cluster_node_pool" "source" { + name = "source" + kubernetes_cluster_id = azurerm_kubernetes_cluster.test.id + vm_size = "Standard_D2s_v3" +} + +data "azurerm_kubernetes_snapshot" "test" { + name = "%[3]s" + resource_group_name = azurerm_resource_group.test.name +} + +resource "azurerm_kubernetes_cluster_node_pool" "test" { + name = "new" + kubernetes_cluster_id = azurerm_kubernetes_cluster.test.id + vm_size = "Standard_DS2_v2" + node_count = 1 + snapshot_id = data.azurerm_kubernetes_snapshot.test.id + depends_on = [ + azurerm_kubernetes_cluster_node_pool.source + ] +} + `, data.Locations.Primary, data.RandomInteger, data.RandomString) +} diff --git a/internal/services/containers/kubernetes_snapshot_data_source.go b/internal/services/containers/kubernetes_snapshot_data_source.go new file mode 100644 index 000000000000..3536dd083db1 --- /dev/null +++ b/internal/services/containers/kubernetes_snapshot_data_source.go @@ -0,0 +1,108 @@ +package containers + +import ( + "context" + "fmt" + "time" + + "github.com/hashicorp/go-azure-helpers/lang/pointer" + "github.com/hashicorp/go-azure-helpers/lang/response" + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonschema" + "github.com/hashicorp/go-azure-sdk/resource-manager/containerservice/2023-02-02-preview/agentpools" + "github.com/hashicorp/go-azure-sdk/resource-manager/containerservice/2023-02-02-preview/snapshots" + "github.com/hashicorp/terraform-provider-azurerm/internal/sdk" + "github.com/hashicorp/terraform-provider-azurerm/internal/tags" + "github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk" + "github.com/hashicorp/terraform-provider-azurerm/internal/tf/validation" +) + +type KubernetesSnapshotDataSourceModel struct { + Name string `tfschema:"name"` + ResourceGroup string `tfschema:"resource_group_name"` + SourceResourceId string `tfschema:"source_resource_id"` + Tags map[string]string `tfschema:"tags"` +} + +type KubernetesSnapshotDataSource struct{} + +var _ sdk.DataSource = KubernetesSnapshotDataSource{} + +func (r KubernetesSnapshotDataSource) ResourceType() string { + return "azurerm_kubernetes_snapshot" +} + +func (r KubernetesSnapshotDataSource) ModelObject() interface{} { + return &KubernetesSnapshotDataSourceModel{} +} + +func (r KubernetesSnapshotDataSource) IDValidationFunc() pluginsdk.SchemaValidateFunc { + return snapshots.ValidateSnapshotID +} + +func (r KubernetesSnapshotDataSource) Arguments() map[string]*pluginsdk.Schema { + return map[string]*pluginsdk.Schema{ + "name": { + Type: pluginsdk.TypeString, + Required: true, + ValidateFunc: validation.StringIsNotEmpty, + }, + + "resource_group_name": commonschema.ResourceGroupNameForDataSource(), + } +} + +func (r KubernetesSnapshotDataSource) Attributes() map[string]*pluginsdk.Schema { + return map[string]*pluginsdk.Schema{ + "source_resource_id": { + Type: pluginsdk.TypeString, + Computed: true, + }, + + "tags": tags.SchemaDataSource(), + } +} + +func (r KubernetesSnapshotDataSource) Read() sdk.ResourceFunc { + return sdk.ResourceFunc{ + Timeout: 5 * time.Minute, + Func: func(ctx context.Context, metadata sdk.ResourceMetaData) error { + client := metadata.Client.Containers.SnapshotClient + subscriptionId := metadata.Client.Account.SubscriptionId + + var state KubernetesSnapshotDataSourceModel + if err := metadata.Decode(&state); err != nil { + return fmt.Errorf("decoding: %+v", err) + } + + id := snapshots.NewSnapshotID(subscriptionId, state.ResourceGroup, state.Name) + + resp, err := client.Get(ctx, id) + if err != nil { + if response.WasNotFound(resp.HttpResponse) { + return fmt.Errorf("%s was not found", id) + } + return fmt.Errorf("retrieving %s: %v", id, err) + } + + state.Name = id.SnapshotName + + if model := resp.Model; model != nil { + state.Tags = pointer.From(model.Tags) + + if props := model.Properties; props != nil { + if props.CreationData != nil && props.CreationData.SourceResourceId != nil { + nodePoolId, err := agentpools.ParseAgentPoolIDInsensitively(*props.CreationData.SourceResourceId) + if err != nil { + return err + } + state.SourceResourceId = nodePoolId.ID() + } + } + } + + metadata.SetID(id) + + return metadata.Encode(&state) + }, + } +} diff --git a/internal/services/containers/kubernetes_snapshot_data_source_test.go b/internal/services/containers/kubernetes_snapshot_data_source_test.go new file mode 100644 index 000000000000..785267548fda --- /dev/null +++ b/internal/services/containers/kubernetes_snapshot_data_source_test.go @@ -0,0 +1,149 @@ +package containers_test + +import ( + "context" + "fmt" + "testing" + + "github.com/hashicorp/go-azure-sdk/resource-manager/containerservice/2023-02-02-preview/agentpools" + "github.com/hashicorp/go-azure-sdk/resource-manager/containerservice/2023-02-02-preview/snapshots" + "github.com/hashicorp/terraform-plugin-testing/terraform" + "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/utils" +) + +type KubernetesSnapshotDataSource struct{} + +func TestAccDataSourceKubernetesSnapshot_basic(t *testing.T) { + data := acceptance.BuildTestData(t, "data.azurerm_kubernetes_snapshot", "test") + r := KubernetesSnapshotDataSource{} + + data.DataSourceTest(t, []acceptance.TestStep{ + { + Config: r.snapshotSource(data), + Check: acceptance.ComposeTestCheckFunc( + data.CheckWithClientForResource(func(ctx context.Context, clients *clients.Client, state *terraform.InstanceState) error { + client := clients.Containers.SnapshotClient + poolId, err := agentpools.ParseAgentPoolID(state.ID) + if err != nil { + return err + } + id := snapshots.NewSnapshotID(poolId.SubscriptionId, poolId.ResourceGroupName, data.RandomString) + snapshot := snapshots.Snapshot{ + Location: data.Locations.Primary, + Properties: &snapshots.SnapshotProperties{ + CreationData: &snapshots.CreationData{ + SourceResourceId: utils.String(poolId.ID()), + }, + }, + } + _, err = client.CreateOrUpdate(ctx, id, snapshot) + if err != nil { + return fmt.Errorf("creating %s: %+v", id, err) + } + return nil + }, "azurerm_kubernetes_cluster_node_pool.source"), + ), + }, + { + Config: r.snapshotRestore(data), + Check: acceptance.ComposeTestCheckFunc( + check.That(data.ResourceName).Key("source_resource_id").IsNotEmpty(), + ), + }, + { + Config: r.snapshotSource(data), + Check: acceptance.ComposeTestCheckFunc( + data.CheckWithClientForResource(func(ctx context.Context, clients *clients.Client, state *terraform.InstanceState) error { + client := clients.Containers.SnapshotClient + poolId, err := agentpools.ParseAgentPoolID(state.ID) + if err != nil { + return err + } + id := snapshots.NewSnapshotID(poolId.SubscriptionId, poolId.ResourceGroupName, data.RandomString) + _, err = client.Delete(ctx, id) + if err != nil { + return fmt.Errorf("creating %s: %+v", id, err) + } + return nil + }, "azurerm_kubernetes_cluster_node_pool.source"), + ), + }, + }) +} + +func (KubernetesSnapshotDataSource) snapshotSource(data acceptance.TestData) string { + return fmt.Sprintf(` +provider "azurerm" { + features {} +} + +resource "azurerm_resource_group" "test" { + name = "acctestRG-aks-%[2]d" + location = "%[1]s" +} + +resource "azurerm_kubernetes_cluster" "test" { + name = "acctestaks%[2]d" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name + dns_prefix = "acctestaks%[2]d" + default_node_pool { + name = "default" + node_count = 1 + vm_size = "Standard_D2s_v3" + } + identity { + type = "SystemAssigned" + } +} + +resource "azurerm_kubernetes_cluster_node_pool" "source" { + name = "source" + kubernetes_cluster_id = azurerm_kubernetes_cluster.test.id + vm_size = "Standard_D2s_v3" +} + `, data.Locations.Primary, data.RandomInteger) +} + +func (KubernetesSnapshotDataSource) snapshotRestore(data acceptance.TestData) string { + return fmt.Sprintf(` +provider "azurerm" { + features {} +} + +resource "azurerm_resource_group" "test" { + name = "acctestRG-aks-%[2]d" + location = "%[1]s" +} + +resource "azurerm_kubernetes_cluster" "test" { + name = "acctestaks%[2]d" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name + dns_prefix = "acctestaks%[2]d" + default_node_pool { + name = "default" + node_count = 1 + vm_size = "Standard_D2s_v3" + } + identity { + type = "SystemAssigned" + } +} + +resource "azurerm_kubernetes_cluster_node_pool" "source" { + name = "source" + kubernetes_cluster_id = azurerm_kubernetes_cluster.test.id + vm_size = "Standard_D2s_v3" +} + + +data "azurerm_kubernetes_snapshot" "test" { + name = "%[3]s" + resource_group_name = azurerm_resource_group.test.name +} + `, data.Locations.Primary, data.RandomInteger, data.RandomString) +} diff --git a/internal/services/containers/registration.go b/internal/services/containers/registration.go index ddcf9735fa7e..9040b13f760d 100644 --- a/internal/services/containers/registration.go +++ b/internal/services/containers/registration.go @@ -58,6 +58,7 @@ func (r Registration) SupportedResources() map[string]*pluginsdk.Resource { func (r Registration) DataSources() []sdk.DataSource { dataSources := []sdk.DataSource{} dataSources = append(dataSources, r.autoRegistration.DataSources()...) + dataSources = append(dataSources, KubernetesSnapshotDataSource{}) return dataSources } diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/containerservice/2023-02-02-preview/snapshots/README.md b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/containerservice/2023-02-02-preview/snapshots/README.md new file mode 100644 index 000000000000..bd965e67035d --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/containerservice/2023-02-02-preview/snapshots/README.md @@ -0,0 +1,128 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/containerservice/2023-02-02-preview/snapshots` Documentation + +The `snapshots` SDK allows for interaction with the Azure Resource Manager Service `containerservice` (API Version `2023-02-02-preview`). + +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/containerservice/2023-02-02-preview/snapshots" +``` + + +### Client Initialization + +```go +client := snapshots.NewSnapshotsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `SnapshotsClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := snapshots.NewSnapshotID("12345678-1234-9876-4563-123456789012", "example-resource-group", "snapshotValue") + +payload := snapshots.Snapshot{ + // ... +} + + +read, err := client.CreateOrUpdate(ctx, id, payload) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `SnapshotsClient.Delete` + +```go +ctx := context.TODO() +id := snapshots.NewSnapshotID("12345678-1234-9876-4563-123456789012", "example-resource-group", "snapshotValue") + +read, err := client.Delete(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `SnapshotsClient.Get` + +```go +ctx := context.TODO() +id := snapshots.NewSnapshotID("12345678-1234-9876-4563-123456789012", "example-resource-group", "snapshotValue") + +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: `SnapshotsClient.List` + +```go +ctx := context.TODO() +id := snapshots.NewSubscriptionID("12345678-1234-9876-4563-123456789012") + +// 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: `SnapshotsClient.ListByResourceGroup` + +```go +ctx := context.TODO() +id := snapshots.NewResourceGroupID("12345678-1234-9876-4563-123456789012", "example-resource-group") + +// alternatively `client.ListByResourceGroup(ctx, id)` can be used to do batched pagination +items, err := client.ListByResourceGroupComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `SnapshotsClient.UpdateTags` + +```go +ctx := context.TODO() +id := snapshots.NewSnapshotID("12345678-1234-9876-4563-123456789012", "example-resource-group", "snapshotValue") + +payload := snapshots.TagsObject{ + // ... +} + + +read, err := client.UpdateTags(ctx, id, payload) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/containerservice/2023-02-02-preview/snapshots/client.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/containerservice/2023-02-02-preview/snapshots/client.go new file mode 100644 index 000000000000..62d2a1323835 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/containerservice/2023-02-02-preview/snapshots/client.go @@ -0,0 +1,18 @@ +package snapshots + +import "github.com/Azure/go-autorest/autorest" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SnapshotsClient struct { + Client autorest.Client + baseUri string +} + +func NewSnapshotsClientWithBaseURI(endpoint string) SnapshotsClient { + return SnapshotsClient{ + Client: autorest.NewClientWithUserAgent(userAgent()), + baseUri: endpoint, + } +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/containerservice/2023-02-02-preview/snapshots/constants.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/containerservice/2023-02-02-preview/snapshots/constants.go new file mode 100644 index 000000000000..69ba232110a1 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/containerservice/2023-02-02-preview/snapshots/constants.go @@ -0,0 +1,99 @@ +package snapshots + +import "strings" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type OSSKU string + +const ( + OSSKUCBLMariner OSSKU = "CBLMariner" + OSSKUMariner OSSKU = "Mariner" + OSSKUUbuntu OSSKU = "Ubuntu" + OSSKUWindowsTwoZeroOneNine OSSKU = "Windows2019" + OSSKUWindowsTwoZeroTwoTwo OSSKU = "Windows2022" +) + +func PossibleValuesForOSSKU() []string { + return []string{ + string(OSSKUCBLMariner), + string(OSSKUMariner), + string(OSSKUUbuntu), + string(OSSKUWindowsTwoZeroOneNine), + string(OSSKUWindowsTwoZeroTwoTwo), + } +} + +func parseOSSKU(input string) (*OSSKU, error) { + vals := map[string]OSSKU{ + "cblmariner": OSSKUCBLMariner, + "mariner": OSSKUMariner, + "ubuntu": OSSKUUbuntu, + "windows2019": OSSKUWindowsTwoZeroOneNine, + "windows2022": OSSKUWindowsTwoZeroTwoTwo, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := OSSKU(input) + return &out, nil +} + +type OSType string + +const ( + OSTypeLinux OSType = "Linux" + OSTypeWindows OSType = "Windows" +) + +func PossibleValuesForOSType() []string { + return []string{ + string(OSTypeLinux), + string(OSTypeWindows), + } +} + +func parseOSType(input string) (*OSType, error) { + vals := map[string]OSType{ + "linux": OSTypeLinux, + "windows": OSTypeWindows, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := OSType(input) + return &out, nil +} + +type SnapshotType string + +const ( + SnapshotTypeManagedCluster SnapshotType = "ManagedCluster" + SnapshotTypeNodePool SnapshotType = "NodePool" +) + +func PossibleValuesForSnapshotType() []string { + return []string{ + string(SnapshotTypeManagedCluster), + string(SnapshotTypeNodePool), + } +} + +func parseSnapshotType(input string) (*SnapshotType, error) { + vals := map[string]SnapshotType{ + "managedcluster": SnapshotTypeManagedCluster, + "nodepool": SnapshotTypeNodePool, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := SnapshotType(input) + return &out, nil +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/containerservice/2023-02-02-preview/snapshots/id_snapshot.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/containerservice/2023-02-02-preview/snapshots/id_snapshot.go new file mode 100644 index 000000000000..3f9d417cab8a --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/containerservice/2023-02-02-preview/snapshots/id_snapshot.go @@ -0,0 +1,127 @@ +package snapshots + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = SnapshotId{} + +// SnapshotId is a struct representing the Resource ID for a Snapshot +type SnapshotId struct { + SubscriptionId string + ResourceGroupName string + SnapshotName string +} + +// NewSnapshotID returns a new SnapshotId struct +func NewSnapshotID(subscriptionId string, resourceGroupName string, snapshotName string) SnapshotId { + return SnapshotId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + SnapshotName: snapshotName, + } +} + +// ParseSnapshotID parses 'input' into a SnapshotId +func ParseSnapshotID(input string) (*SnapshotId, error) { + parser := resourceids.NewParserFromResourceIdType(SnapshotId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := SnapshotId{} + + 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.SnapshotName, ok = parsed.Parsed["snapshotName"]; !ok { + return nil, fmt.Errorf("the segment 'snapshotName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ParseSnapshotIDInsensitively parses 'input' case-insensitively into a SnapshotId +// note: this method should only be used for API response data and not user input +func ParseSnapshotIDInsensitively(input string) (*SnapshotId, error) { + parser := resourceids.NewParserFromResourceIdType(SnapshotId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := SnapshotId{} + + 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.SnapshotName, ok = parsed.Parsed["snapshotName"]; !ok { + return nil, fmt.Errorf("the segment 'snapshotName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ValidateSnapshotID checks that 'input' can be parsed as a Snapshot ID +func ValidateSnapshotID(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 := ParseSnapshotID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Snapshot ID +func (id SnapshotId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ContainerService/snapshots/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.SnapshotName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Snapshot ID +func (id SnapshotId) 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("staticMicrosoftContainerService", "Microsoft.ContainerService", "Microsoft.ContainerService"), + resourceids.StaticSegment("staticSnapshots", "snapshots", "snapshots"), + resourceids.UserSpecifiedSegment("snapshotName", "snapshotValue"), + } +} + +// String returns a human-readable description of this Snapshot ID +func (id SnapshotId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Snapshot Name: %q", id.SnapshotName), + } + return fmt.Sprintf("Snapshot (%s)", strings.Join(components, "\n")) +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/containerservice/2023-02-02-preview/snapshots/method_createorupdate_autorest.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/containerservice/2023-02-02-preview/snapshots/method_createorupdate_autorest.go new file mode 100644 index 000000000000..29d10e44f6e3 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/containerservice/2023-02-02-preview/snapshots/method_createorupdate_autorest.go @@ -0,0 +1,69 @@ +package snapshots + +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 CreateOrUpdateOperationResponse struct { + HttpResponse *http.Response + Model *Snapshot +} + +// CreateOrUpdate ... +func (c SnapshotsClient) CreateOrUpdate(ctx context.Context, id SnapshotId, input Snapshot) (result CreateOrUpdateOperationResponse, err error) { + req, err := c.preparerForCreateOrUpdate(ctx, id, input) + if err != nil { + err = autorest.NewErrorWithError(err, "snapshots.SnapshotsClient", "CreateOrUpdate", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "snapshots.SnapshotsClient", "CreateOrUpdate", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForCreateOrUpdate(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "snapshots.SnapshotsClient", "CreateOrUpdate", result.HttpResponse, "Failure responding to request") + return + } + + return +} + +// preparerForCreateOrUpdate prepares the CreateOrUpdate request. +func (c SnapshotsClient) preparerForCreateOrUpdate(ctx context.Context, id SnapshotId, input Snapshot) (*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)) +} + +// responderForCreateOrUpdate handles the response to the CreateOrUpdate request. The method always +// closes the http.Response Body. +func (c SnapshotsClient) responderForCreateOrUpdate(resp *http.Response) (result CreateOrUpdateOperationResponse, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusCreated, http.StatusOK), + autorest.ByUnmarshallingJSON(&result.Model), + autorest.ByClosing()) + result.HttpResponse = resp + + return +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/containerservice/2023-02-02-preview/snapshots/method_delete_autorest.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/containerservice/2023-02-02-preview/snapshots/method_delete_autorest.go new file mode 100644 index 000000000000..11173f290039 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/containerservice/2023-02-02-preview/snapshots/method_delete_autorest.go @@ -0,0 +1,66 @@ +package snapshots + +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 DeleteOperationResponse struct { + HttpResponse *http.Response +} + +// Delete ... +func (c SnapshotsClient) Delete(ctx context.Context, id SnapshotId) (result DeleteOperationResponse, err error) { + req, err := c.preparerForDelete(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "snapshots.SnapshotsClient", "Delete", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "snapshots.SnapshotsClient", "Delete", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForDelete(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "snapshots.SnapshotsClient", "Delete", result.HttpResponse, "Failure responding to request") + return + } + + return +} + +// preparerForDelete prepares the Delete request. +func (c SnapshotsClient) preparerForDelete(ctx context.Context, id SnapshotId) (*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)) +} + +// responderForDelete handles the response to the Delete request. The method always +// closes the http.Response Body. +func (c SnapshotsClient) responderForDelete(resp *http.Response) (result DeleteOperationResponse, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusNoContent, http.StatusOK), + autorest.ByClosing()) + result.HttpResponse = resp + + return +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/containerservice/2023-02-02-preview/snapshots/method_get_autorest.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/containerservice/2023-02-02-preview/snapshots/method_get_autorest.go new file mode 100644 index 000000000000..b328ad1cf52e --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/containerservice/2023-02-02-preview/snapshots/method_get_autorest.go @@ -0,0 +1,68 @@ +package snapshots + +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 *Snapshot +} + +// Get ... +func (c SnapshotsClient) Get(ctx context.Context, id SnapshotId) (result GetOperationResponse, err error) { + req, err := c.preparerForGet(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "snapshots.SnapshotsClient", "Get", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "snapshots.SnapshotsClient", "Get", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForGet(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "snapshots.SnapshotsClient", "Get", result.HttpResponse, "Failure responding to request") + return + } + + return +} + +// preparerForGet prepares the Get request. +func (c SnapshotsClient) preparerForGet(ctx context.Context, id SnapshotId) (*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 SnapshotsClient) 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/containerservice/2023-02-02-preview/snapshots/method_list_autorest.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/containerservice/2023-02-02-preview/snapshots/method_list_autorest.go new file mode 100644 index 000000000000..6222a23b06d6 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/containerservice/2023-02-02-preview/snapshots/method_list_autorest.go @@ -0,0 +1,187 @@ +package snapshots + +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 ListOperationResponse struct { + HttpResponse *http.Response + Model *[]Snapshot + + nextLink *string + nextPageFunc func(ctx context.Context, nextLink string) (ListOperationResponse, error) +} + +type ListCompleteResult struct { + Items []Snapshot +} + +func (r ListOperationResponse) HasMore() bool { + return r.nextLink != nil +} + +func (r ListOperationResponse) LoadMore(ctx context.Context) (resp ListOperationResponse, err error) { + if !r.HasMore() { + err = fmt.Errorf("no more pages returned") + return + } + return r.nextPageFunc(ctx, *r.nextLink) +} + +// List ... +func (c SnapshotsClient) List(ctx context.Context, id commonids.SubscriptionId) (resp ListOperationResponse, err error) { + req, err := c.preparerForList(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "snapshots.SnapshotsClient", "List", nil, "Failure preparing request") + return + } + + resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "snapshots.SnapshotsClient", "List", resp.HttpResponse, "Failure sending request") + return + } + + resp, err = c.responderForList(resp.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "snapshots.SnapshotsClient", "List", resp.HttpResponse, "Failure responding to request") + return + } + return +} + +// preparerForList prepares the List request. +func (c SnapshotsClient) preparerForList(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.ContainerService/snapshots", id.ID())), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// preparerForListWithNextLink prepares the List request with the given nextLink token. +func (c SnapshotsClient) preparerForListWithNextLink(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)) +} + +// responderForList handles the response to the List request. The method always +// closes the http.Response Body. +func (c SnapshotsClient) responderForList(resp *http.Response) (result ListOperationResponse, err error) { + type page struct { + Values []Snapshot `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 ListOperationResponse, err error) { + req, err := c.preparerForListWithNextLink(ctx, nextLink) + if err != nil { + err = autorest.NewErrorWithError(err, "snapshots.SnapshotsClient", "List", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "snapshots.SnapshotsClient", "List", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForList(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "snapshots.SnapshotsClient", "List", result.HttpResponse, "Failure responding to request") + return + } + + return + } + } + return +} + +// ListComplete retrieves all of the results into a single object +func (c SnapshotsClient) ListComplete(ctx context.Context, id commonids.SubscriptionId) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, SnapshotOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all of the results and then applied the predicate +func (c SnapshotsClient) ListCompleteMatchingPredicate(ctx context.Context, id commonids.SubscriptionId, predicate SnapshotOperationPredicate) (resp ListCompleteResult, err error) { + items := make([]Snapshot, 0) + + page, err := c.List(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 := ListCompleteResult{ + Items: items, + } + return out, nil +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/containerservice/2023-02-02-preview/snapshots/method_listbyresourcegroup_autorest.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/containerservice/2023-02-02-preview/snapshots/method_listbyresourcegroup_autorest.go new file mode 100644 index 000000000000..f034336ecfe8 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/containerservice/2023-02-02-preview/snapshots/method_listbyresourcegroup_autorest.go @@ -0,0 +1,187 @@ +package snapshots + +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 *[]Snapshot + + nextLink *string + nextPageFunc func(ctx context.Context, nextLink string) (ListByResourceGroupOperationResponse, error) +} + +type ListByResourceGroupCompleteResult struct { + Items []Snapshot +} + +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 SnapshotsClient) ListByResourceGroup(ctx context.Context, id commonids.ResourceGroupId) (resp ListByResourceGroupOperationResponse, err error) { + req, err := c.preparerForListByResourceGroup(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "snapshots.SnapshotsClient", "ListByResourceGroup", nil, "Failure preparing request") + return + } + + resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "snapshots.SnapshotsClient", "ListByResourceGroup", resp.HttpResponse, "Failure sending request") + return + } + + resp, err = c.responderForListByResourceGroup(resp.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "snapshots.SnapshotsClient", "ListByResourceGroup", resp.HttpResponse, "Failure responding to request") + return + } + return +} + +// preparerForListByResourceGroup prepares the ListByResourceGroup request. +func (c SnapshotsClient) 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.ContainerService/snapshots", id.ID())), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// preparerForListByResourceGroupWithNextLink prepares the ListByResourceGroup request with the given nextLink token. +func (c SnapshotsClient) 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 SnapshotsClient) responderForListByResourceGroup(resp *http.Response) (result ListByResourceGroupOperationResponse, err error) { + type page struct { + Values []Snapshot `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, "snapshots.SnapshotsClient", "ListByResourceGroup", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "snapshots.SnapshotsClient", "ListByResourceGroup", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForListByResourceGroup(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "snapshots.SnapshotsClient", "ListByResourceGroup", result.HttpResponse, "Failure responding to request") + return + } + + return + } + } + return +} + +// ListByResourceGroupComplete retrieves all of the results into a single object +func (c SnapshotsClient) ListByResourceGroupComplete(ctx context.Context, id commonids.ResourceGroupId) (ListByResourceGroupCompleteResult, error) { + return c.ListByResourceGroupCompleteMatchingPredicate(ctx, id, SnapshotOperationPredicate{}) +} + +// ListByResourceGroupCompleteMatchingPredicate retrieves all of the results and then applied the predicate +func (c SnapshotsClient) ListByResourceGroupCompleteMatchingPredicate(ctx context.Context, id commonids.ResourceGroupId, predicate SnapshotOperationPredicate) (resp ListByResourceGroupCompleteResult, err error) { + items := make([]Snapshot, 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/containerservice/2023-02-02-preview/snapshots/method_updatetags_autorest.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/containerservice/2023-02-02-preview/snapshots/method_updatetags_autorest.go new file mode 100644 index 000000000000..e370c6b54a58 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/containerservice/2023-02-02-preview/snapshots/method_updatetags_autorest.go @@ -0,0 +1,69 @@ +package snapshots + +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 UpdateTagsOperationResponse struct { + HttpResponse *http.Response + Model *Snapshot +} + +// UpdateTags ... +func (c SnapshotsClient) UpdateTags(ctx context.Context, id SnapshotId, input TagsObject) (result UpdateTagsOperationResponse, err error) { + req, err := c.preparerForUpdateTags(ctx, id, input) + if err != nil { + err = autorest.NewErrorWithError(err, "snapshots.SnapshotsClient", "UpdateTags", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "snapshots.SnapshotsClient", "UpdateTags", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForUpdateTags(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "snapshots.SnapshotsClient", "UpdateTags", result.HttpResponse, "Failure responding to request") + return + } + + return +} + +// preparerForUpdateTags prepares the UpdateTags request. +func (c SnapshotsClient) preparerForUpdateTags(ctx context.Context, id SnapshotId, input TagsObject) (*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)) +} + +// responderForUpdateTags handles the response to the UpdateTags request. The method always +// closes the http.Response Body. +func (c SnapshotsClient) responderForUpdateTags(resp *http.Response) (result UpdateTagsOperationResponse, 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/containerservice/2023-02-02-preview/snapshots/model_creationdata.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/containerservice/2023-02-02-preview/snapshots/model_creationdata.go new file mode 100644 index 000000000000..132e3459c828 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/containerservice/2023-02-02-preview/snapshots/model_creationdata.go @@ -0,0 +1,8 @@ +package snapshots + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CreationData struct { + SourceResourceId *string `json:"sourceResourceId,omitempty"` +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/containerservice/2023-02-02-preview/snapshots/model_snapshot.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/containerservice/2023-02-02-preview/snapshots/model_snapshot.go new file mode 100644 index 000000000000..b2feb4ccdaee --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/containerservice/2023-02-02-preview/snapshots/model_snapshot.go @@ -0,0 +1,18 @@ +package snapshots + +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 Snapshot struct { + Id *string `json:"id,omitempty"` + Location string `json:"location"` + Name *string `json:"name,omitempty"` + Properties *SnapshotProperties `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/containerservice/2023-02-02-preview/snapshots/model_snapshotproperties.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/containerservice/2023-02-02-preview/snapshots/model_snapshotproperties.go new file mode 100644 index 000000000000..962aa32598f7 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/containerservice/2023-02-02-preview/snapshots/model_snapshotproperties.go @@ -0,0 +1,15 @@ +package snapshots + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SnapshotProperties struct { + CreationData *CreationData `json:"creationData,omitempty"` + EnableFIPS *bool `json:"enableFIPS,omitempty"` + KubernetesVersion *string `json:"kubernetesVersion,omitempty"` + NodeImageVersion *string `json:"nodeImageVersion,omitempty"` + OsSku *OSSKU `json:"osSku,omitempty"` + OsType *OSType `json:"osType,omitempty"` + SnapshotType *SnapshotType `json:"snapshotType,omitempty"` + VMSize *string `json:"vmSize,omitempty"` +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/containerservice/2023-02-02-preview/snapshots/model_tagsobject.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/containerservice/2023-02-02-preview/snapshots/model_tagsobject.go new file mode 100644 index 000000000000..30f646c1c9fb --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/containerservice/2023-02-02-preview/snapshots/model_tagsobject.go @@ -0,0 +1,8 @@ +package snapshots + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type TagsObject struct { + Tags *map[string]string `json:"tags,omitempty"` +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/containerservice/2023-02-02-preview/snapshots/predicates.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/containerservice/2023-02-02-preview/snapshots/predicates.go new file mode 100644 index 000000000000..e2b6b4d636b1 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/containerservice/2023-02-02-preview/snapshots/predicates.go @@ -0,0 +1,32 @@ +package snapshots + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SnapshotOperationPredicate struct { + Id *string + Location *string + Name *string + Type *string +} + +func (p SnapshotOperationPredicate) Matches(input Snapshot) 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/containerservice/2023-02-02-preview/snapshots/version.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/containerservice/2023-02-02-preview/snapshots/version.go new file mode 100644 index 000000000000..f033316d57c9 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/containerservice/2023-02-02-preview/snapshots/version.go @@ -0,0 +1,12 @@ +package snapshots + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2023-02-02-preview" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/snapshots/%s", defaultApiVersion) +} diff --git a/vendor/modules.txt b/vendor/modules.txt index 3fd66143abbc..5e33f1deb960 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -256,6 +256,7 @@ github.com/hashicorp/go-azure-sdk/resource-manager/containerservice/2022-09-02-p github.com/hashicorp/go-azure-sdk/resource-manager/containerservice/2023-02-02-preview/agentpools github.com/hashicorp/go-azure-sdk/resource-manager/containerservice/2023-02-02-preview/maintenanceconfigurations github.com/hashicorp/go-azure-sdk/resource-manager/containerservice/2023-02-02-preview/managedclusters +github.com/hashicorp/go-azure-sdk/resource-manager/containerservice/2023-02-02-preview/snapshots github.com/hashicorp/go-azure-sdk/resource-manager/cosmosdb/2022-05-15/cosmosdb github.com/hashicorp/go-azure-sdk/resource-manager/cosmosdb/2022-05-15/managedcassandras github.com/hashicorp/go-azure-sdk/resource-manager/cosmosdb/2022-05-15/sqldedicatedgateway diff --git a/website/docs/d/kubernetes_snapshot.html.markdown b/website/docs/d/kubernetes_snapshot.html.markdown new file mode 100644 index 000000000000..72321791692f --- /dev/null +++ b/website/docs/d/kubernetes_snapshot.html.markdown @@ -0,0 +1,42 @@ +--- +subcategory: "Container" +layout: "azurerm" +page_title: "Azure Resource Manager: azurerm_kubernetes_snapshot" +description: |- + Gets information about an existing Kubernetes Snapshot +--- + +# Data Source: azurerm_kubernetes_snapshot + +Use this data source to access information about an existing Kubernetes Snapshot. + +## Example Usage + +```hcl +data "azurerm_kubernetes_snapshot" "example" { + name = "example" + resource_group_name = "example-resources" +} +``` + +## Argument Reference + +The following arguments are supported: + +* `name` - The name of the Kubernetes Snapshot. + +* `resource_group_name` - The name of the Resource Group in which the Kubernetes Snapshot exists. + +## Attributes Reference + +The following attributes are exported: + +* `id` - The ID of the Kubernetes Snapshot. + +* `source_resource_id` - The ID of the source resource. + +## Timeouts + +The `timeouts` block allows you to specify [timeouts](https://www.terraform.io/language/resources/syntax#operation-timeouts) for certain actions: + +* `read` - (Defaults to 5 minutes) Used when retrieving the Kubernetes Snapshot. diff --git a/website/docs/r/kubernetes_cluster_node_pool.html.markdown b/website/docs/r/kubernetes_cluster_node_pool.html.markdown index dc7ff361f403..36094d36f7ef 100644 --- a/website/docs/r/kubernetes_cluster_node_pool.html.markdown +++ b/website/docs/r/kubernetes_cluster_node_pool.html.markdown @@ -138,6 +138,8 @@ The following arguments are supported: ~> **Note:** This field can only be configured when `priority` is set to `Spot`. +* `snapshot_id` - (Optional) The ID of the Snapshot which should be used to create this Node Pool. Changing this forces a new resource to be created. + * `tags` - (Optional) A mapping of tags to assign to the resource. ~> At this time there's a bug in the AKS API where Tags for a Node Pool are not stored in the correct case - you [may wish to use Terraform's `ignore_changes` functionality to ignore changes to the casing](https://www.terraform.io/language/meta-arguments/lifecycle#ignore_changess) until this is fixed in the AKS API.