From d12271f4c31dbcb732a24ffb32cb415179c44496 Mon Sep 17 00:00:00 2001 From: Heng Lu Date: Mon, 25 Dec 2023 15:37:16 +0800 Subject: [PATCH 1/6] new resource: `azurerm_kubernetes_fleet_update_strategy` --- internal/services/containers/client/client.go | 6 + ...bernetes_fleet_update_strategy_resource.go | 307 ++++++++++++++++++ ...tes_fleet_update_strategy_resource_test.go | 183 +++++++++++ internal/services/containers/registration.go | 1 + .../fleetupdatestrategies/README.md | 82 +++++ .../fleetupdatestrategies/client.go | 18 + .../fleetupdatestrategies/constants.go | 37 +++ .../fleetupdatestrategies/id_fleet.go | 125 +++++++ .../id_updatestrategy.go | 134 ++++++++ .../method_createorupdate_autorest.go | 113 +++++++ .../method_delete_autorest.go | 107 ++++++ .../method_get_autorest.go | 68 ++++ .../method_listbyfleet_autorest.go | 186 +++++++++++ .../model_fleetupdatestrategy.go | 17 + .../model_fleetupdatestrategyproperties.go | 9 + .../model_updategroup.go | 8 + .../model_updaterunstrategy.go | 8 + .../model_updatestage.go | 10 + .../fleetupdatestrategies/predicates.go | 32 ++ .../fleetupdatestrategies/version.go | 12 + vendor/modules.txt | 1 + ...rnetes_fleet_update_strategy.html.markdown | 98 ++++++ 22 files changed, 1562 insertions(+) create mode 100644 internal/services/containers/kubernetes_fleet_update_strategy_resource.go create mode 100644 internal/services/containers/kubernetes_fleet_update_strategy_resource_test.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/containerservice/2023-10-15/fleetupdatestrategies/README.md create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/containerservice/2023-10-15/fleetupdatestrategies/client.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/containerservice/2023-10-15/fleetupdatestrategies/constants.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/containerservice/2023-10-15/fleetupdatestrategies/id_fleet.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/containerservice/2023-10-15/fleetupdatestrategies/id_updatestrategy.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/containerservice/2023-10-15/fleetupdatestrategies/method_createorupdate_autorest.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/containerservice/2023-10-15/fleetupdatestrategies/method_delete_autorest.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/containerservice/2023-10-15/fleetupdatestrategies/method_get_autorest.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/containerservice/2023-10-15/fleetupdatestrategies/method_listbyfleet_autorest.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/containerservice/2023-10-15/fleetupdatestrategies/model_fleetupdatestrategy.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/containerservice/2023-10-15/fleetupdatestrategies/model_fleetupdatestrategyproperties.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/containerservice/2023-10-15/fleetupdatestrategies/model_updategroup.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/containerservice/2023-10-15/fleetupdatestrategies/model_updaterunstrategy.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/containerservice/2023-10-15/fleetupdatestrategies/model_updatestage.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/containerservice/2023-10-15/fleetupdatestrategies/predicates.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/containerservice/2023-10-15/fleetupdatestrategies/version.go create mode 100644 website/docs/r/kubernetes_fleet_update_strategy.html.markdown diff --git a/internal/services/containers/client/client.go b/internal/services/containers/client/client.go index 1384195c4b99..0019d216e410 100644 --- a/internal/services/containers/client/client.go +++ b/internal/services/containers/client/client.go @@ -15,6 +15,7 @@ import ( "github.com/hashicorp/go-azure-sdk/resource-manager/containerservice/2023-04-02-preview/maintenanceconfigurations" "github.com/hashicorp/go-azure-sdk/resource-manager/containerservice/2023-04-02-preview/managedclusters" "github.com/hashicorp/go-azure-sdk/resource-manager/containerservice/2023-04-02-preview/snapshots" + "github.com/hashicorp/go-azure-sdk/resource-manager/containerservice/2023-10-15/fleetupdatestrategies" "github.com/hashicorp/go-azure-sdk/resource-manager/kubernetesconfiguration/2022-11-01/extensions" "github.com/hashicorp/go-azure-sdk/resource-manager/kubernetesconfiguration/2022-11-01/fluxconfiguration" "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" @@ -27,6 +28,7 @@ type Client struct { ContainerRegistryClient_v2021_08_01_preview *containerregistry_v2021_08_01_preview.Client // v2019_06_01_preview is needed for container registry agent pools and tasks ContainerRegistryClient_v2019_06_01_preview *containerregistry_v2019_06_01_preview.Client + FleetUpdateStrategiesClient *fleetupdatestrategies.FleetUpdateStrategiesClient KubernetesClustersClient *managedclusters.ManagedClustersClient KubernetesExtensionsClient *extensions.ExtensionsClient KubernetesFluxConfigurationClient *fluxconfiguration.FluxConfigurationClient @@ -55,6 +57,9 @@ func NewContainersClient(o *common.ClientOptions) (*Client, error) { } // AKS + fleetUpdateStrategiesClient := fleetupdatestrategies.NewFleetUpdateStrategiesClientWithBaseURI(o.ResourceManagerEndpoint) + o.ConfigureClient(&fleetUpdateStrategiesClient.Client, o.ResourceManagerAuthorizer) + kubernetesClustersClient := managedclusters.NewManagedClustersClientWithBaseURI(o.ResourceManagerEndpoint) o.ConfigureClient(&kubernetesClustersClient.Client, o.ResourceManagerAuthorizer) @@ -87,6 +92,7 @@ func NewContainersClient(o *common.ClientOptions) (*Client, error) { ContainerInstanceClient: &containerInstanceClient, ContainerRegistryClient_v2021_08_01_preview: containerRegistryClient_v2021_08_01_preview, ContainerRegistryClient_v2019_06_01_preview: containerRegistryClient_v2019_06_01_preview, + FleetUpdateStrategiesClient: &fleetUpdateStrategiesClient, KubernetesClustersClient: &kubernetesClustersClient, KubernetesExtensionsClient: kubernetesExtensionsClient, KubernetesFluxConfigurationClient: fluxConfigurationClient, diff --git a/internal/services/containers/kubernetes_fleet_update_strategy_resource.go b/internal/services/containers/kubernetes_fleet_update_strategy_resource.go new file mode 100644 index 000000000000..db7f8449ed5e --- /dev/null +++ b/internal/services/containers/kubernetes_fleet_update_strategy_resource.go @@ -0,0 +1,307 @@ +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/commonids" + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonschema" + "github.com/hashicorp/go-azure-sdk/resource-manager/containerservice/2023-10-15/fleetupdatestrategies" + "github.com/hashicorp/terraform-provider-azurerm/internal/sdk" + "github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk" + "github.com/hashicorp/terraform-provider-azurerm/internal/tf/validation" +) + +var _ sdk.Resource = KubernetesFleetUpdateStrategyResource{} +var _ sdk.ResourceWithUpdate = KubernetesFleetUpdateStrategyResource{} + +type KubernetesFleetUpdateStrategyResource struct{} + +func (r KubernetesFleetUpdateStrategyResource) ModelObject() interface{} { + return &KubernetesFleetUpdateStrategyResourceSchema{} +} + +type KubernetesFleetUpdateStrategyResourceSchema struct { + FleetId string `tfschema:"fleet_manager_id"` + Name string `tfschema:"name"` + Strategy []KubernetesFleetUpdateStrategyResourceUpdateRunStrategySchema `tfschema:"strategy"` +} + +type KubernetesFleetUpdateStrategyResourceUpdateGroupSchema struct { + Name string `tfschema:"name"` +} + +type KubernetesFleetUpdateStrategyResourceUpdateRunStrategySchema struct { + Stage []KubernetesFleetUpdateStrategyResourceUpdateStageSchema `tfschema:"stage"` +} + +type KubernetesFleetUpdateStrategyResourceUpdateStageSchema struct { + AfterStageWaitInSeconds int64 `tfschema:"after_stage_wait_in_seconds"` + Group []KubernetesFleetUpdateStrategyResourceUpdateGroupSchema `tfschema:"group"` + Name string `tfschema:"name"` +} + +func (r KubernetesFleetUpdateStrategyResource) IDValidationFunc() pluginsdk.SchemaValidateFunc { + return fleetupdatestrategies.ValidateUpdateStrategyID +} + +func (r KubernetesFleetUpdateStrategyResource) ResourceType() string { + return "azurerm_kubernetes_fleet_update_strategy" +} + +func (r KubernetesFleetUpdateStrategyResource) Arguments() map[string]*pluginsdk.Schema { + return map[string]*pluginsdk.Schema{ + "name": { + ForceNew: true, + Required: true, + Type: pluginsdk.TypeString, + }, + + "fleet_manager_id": commonschema.ResourceIDReferenceRequiredForceNew(fleetupdatestrategies.FleetId{}), + + "strategy": { + Required: true, + MaxItems: 1, + Type: pluginsdk.TypeList, + Elem: &pluginsdk.Resource{ + Schema: map[string]*pluginsdk.Schema{ + "stage": { + Required: true, + Type: pluginsdk.TypeList, + Elem: &pluginsdk.Resource{ + Schema: map[string]*pluginsdk.Schema{ + "name": { + Required: true, + Type: pluginsdk.TypeString, + ValidateFunc: validation.StringIsNotEmpty, + }, + + "group": { + Required: true, + Type: pluginsdk.TypeList, + MinItems: 1, + Elem: &pluginsdk.Resource{ + Schema: map[string]*pluginsdk.Schema{ + "name": { + Required: true, + Type: pluginsdk.TypeString, + ValidateFunc: validation.StringIsNotEmpty, + }, + }, + }, + }, + + "after_stage_wait_in_seconds": { + Optional: true, + Type: pluginsdk.TypeInt, + }, + }, + }, + }, + }, + }, + }, + } +} + +func (r KubernetesFleetUpdateStrategyResource) Attributes() map[string]*pluginsdk.Schema { + return map[string]*pluginsdk.Schema{} +} + +func (r KubernetesFleetUpdateStrategyResource) Create() sdk.ResourceFunc { + return sdk.ResourceFunc{ + Timeout: 30 * time.Minute, + Func: func(ctx context.Context, metadata sdk.ResourceMetaData) error { + client := metadata.Client.Containers.FleetUpdateStrategiesClient + + var config KubernetesFleetUpdateStrategyResourceSchema + if err := metadata.Decode(&config); err != nil { + return fmt.Errorf("decoding: %+v", err) + } + + fleetId, err := commonids.ParseFleetID(config.FleetId) + if err != nil { + return err + } + + id := fleetupdatestrategies.NewUpdateStrategyID(fleetId.SubscriptionId, fleetId.ResourceGroupName, fleetId.FleetName, config.Name) + + existing, err := client.Get(ctx, id) + if err != nil { + if !response.WasNotFound(existing.HttpResponse) { + return fmt.Errorf("checking for the presence of an existing %s: %+v", id, err) + } + } + if !response.WasNotFound(existing.HttpResponse) { + return metadata.ResourceRequiresImport(r.ResourceType(), id) + } + + payload := fleetupdatestrategies.FleetUpdateStrategy{ + Properties: &fleetupdatestrategies.FleetUpdateStrategyProperties{ + Strategy: expandKubernetesFleetUpdateStrategy(config.Strategy), + }, + } + + if err := client.CreateOrUpdateThenPoll(ctx, id, payload, fleetupdatestrategies.DefaultCreateOrUpdateOperationOptions()); err != nil { + return fmt.Errorf("creating %s: %+v", id, err) + } + + metadata.SetID(id) + return nil + }, + } +} + +func (r KubernetesFleetUpdateStrategyResource) Update() sdk.ResourceFunc { + return sdk.ResourceFunc{ + Timeout: 30 * time.Minute, + Func: func(ctx context.Context, metadata sdk.ResourceMetaData) error { + client := metadata.Client.Containers.FleetUpdateStrategiesClient + + id, err := fleetupdatestrategies.ParseUpdateStrategyID(metadata.ResourceData.Id()) + if err != nil { + return err + } + + var config KubernetesFleetUpdateStrategyResourceSchema + if err := metadata.Decode(&config); err != nil { + return fmt.Errorf("decoding: %+v", err) + } + + existing, err := client.Get(ctx, *id) + if err != nil { + return fmt.Errorf("retrieving existing %s: %+v", *id, err) + } + if existing.Model == nil { + return fmt.Errorf("retrieving existing %s: properties was nil", *id) + } + payload := *existing.Model + + if metadata.ResourceData.HasChange("strategy") { + payload.Properties.Strategy.Stages = expandKubernetesFleetUpdateStrategyStage(config.Strategy[0].Stage) + } + + if err := client.CreateOrUpdateThenPoll(ctx, *id, payload, fleetupdatestrategies.DefaultCreateOrUpdateOperationOptions()); err != nil { + return fmt.Errorf("updating %s: %+v", *id, err) + } + + return nil + }, + } +} + +func (r KubernetesFleetUpdateStrategyResource) Read() sdk.ResourceFunc { + return sdk.ResourceFunc{ + Timeout: 5 * time.Minute, + Func: func(ctx context.Context, metadata sdk.ResourceMetaData) error { + client := metadata.Client.Containers.FleetUpdateStrategiesClient + schema := KubernetesFleetUpdateStrategyResourceSchema{} + + id, err := fleetupdatestrategies.ParseUpdateStrategyID(metadata.ResourceData.Id()) + if err != nil { + return err + } + + resp, err := client.Get(ctx, *id) + if err != nil { + if response.WasNotFound(resp.HttpResponse) { + return metadata.MarkAsGone(*id) + } + return fmt.Errorf("retrieving %s: %+v", *id, err) + } + + if model := resp.Model; model != nil { + schema.Name = id.UpdateStrategyName + schema.FleetId = fleetupdatestrategies.NewFleetID(id.SubscriptionId, id.ResourceGroupName, id.FleetName).ID() + if model.Properties != nil { + schema.Strategy = flattenKubernetesFleetUpdateStrategy(model.Properties.Strategy) + } + } + + return metadata.Encode(&schema) + }, + } +} +func (r KubernetesFleetUpdateStrategyResource) Delete() sdk.ResourceFunc { + return sdk.ResourceFunc{ + Timeout: 30 * time.Minute, + Func: func(ctx context.Context, metadata sdk.ResourceMetaData) error { + client := metadata.Client.Containers.FleetUpdateStrategiesClient + + id, err := fleetupdatestrategies.ParseUpdateStrategyID(metadata.ResourceData.Id()) + if err != nil { + return err + } + + if err := client.DeleteThenPoll(ctx, *id, fleetupdatestrategies.DefaultDeleteOperationOptions()); err != nil { + return fmt.Errorf("deleting %s: %+v", *id, err) + } + + return nil + }, + } +} + +func expandKubernetesFleetUpdateStrategy(input []KubernetesFleetUpdateStrategyResourceUpdateRunStrategySchema) fleetupdatestrategies.UpdateRunStrategy { + output := fleetupdatestrategies.UpdateRunStrategy{} + if len(input) > 0 { + output.Stages = expandKubernetesFleetUpdateStrategyStage(input[0].Stage) + } + return output +} + +func expandKubernetesFleetUpdateStrategyStage(input []KubernetesFleetUpdateStrategyResourceUpdateStageSchema) []fleetupdatestrategies.UpdateStage { + output := make([]fleetupdatestrategies.UpdateStage, 0) + for _, stage := range input { + output = append(output, fleetupdatestrategies.UpdateStage{ + Name: stage.Name, + AfterStageWaitInSeconds: pointer.FromInt64(stage.AfterStageWaitInSeconds), + Groups: expandKubernetesFleetUpdateStrategyGroup(stage.Group), + }) + } + return output +} + +func expandKubernetesFleetUpdateStrategyGroup(input []KubernetesFleetUpdateStrategyResourceUpdateGroupSchema) *[]fleetupdatestrategies.UpdateGroup { + output := make([]fleetupdatestrategies.UpdateGroup, 0) + for _, group := range input { + output = append(output, fleetupdatestrategies.UpdateGroup{ + Name: group.Name, + }) + } + return &output +} + +func flattenKubernetesFleetUpdateStrategy(input fleetupdatestrategies.UpdateRunStrategy) []KubernetesFleetUpdateStrategyResourceUpdateRunStrategySchema { + output := make([]KubernetesFleetUpdateStrategyResourceUpdateRunStrategySchema, 0) + output = append(output, KubernetesFleetUpdateStrategyResourceUpdateRunStrategySchema{ + Stage: flattenKubernetesFleetUpdateStrategyStage(input.Stages), + }) + return output +} + +func flattenKubernetesFleetUpdateStrategyStage(input []fleetupdatestrategies.UpdateStage) []KubernetesFleetUpdateStrategyResourceUpdateStageSchema { + output := make([]KubernetesFleetUpdateStrategyResourceUpdateStageSchema, 0) + for _, stage := range input { + output = append(output, KubernetesFleetUpdateStrategyResourceUpdateStageSchema{ + Name: stage.Name, + AfterStageWaitInSeconds: pointer.ToInt64(stage.AfterStageWaitInSeconds), + Group: flattenKubernetesFleetUpdateStrategyGroup(stage.Groups), + }) + } + return output + +} + +func flattenKubernetesFleetUpdateStrategyGroup(input *[]fleetupdatestrategies.UpdateGroup) []KubernetesFleetUpdateStrategyResourceUpdateGroupSchema { + output := make([]KubernetesFleetUpdateStrategyResourceUpdateGroupSchema, 0) + for _, group := range *input { + output = append(output, KubernetesFleetUpdateStrategyResourceUpdateGroupSchema{ + Name: group.Name, + }) + } + return output +} diff --git a/internal/services/containers/kubernetes_fleet_update_strategy_resource_test.go b/internal/services/containers/kubernetes_fleet_update_strategy_resource_test.go new file mode 100644 index 000000000000..3cddd694e649 --- /dev/null +++ b/internal/services/containers/kubernetes_fleet_update_strategy_resource_test.go @@ -0,0 +1,183 @@ +package containers_test + +import ( + "context" + "fmt" + "testing" + + "github.com/hashicorp/go-azure-sdk/resource-manager/containerservice/2023-10-15/fleetupdatestrategies" + "github.com/hashicorp/terraform-provider-azurerm/internal/acceptance" + "github.com/hashicorp/terraform-provider-azurerm/internal/acceptance/check" + "github.com/hashicorp/terraform-provider-azurerm/internal/clients" + "github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk" + "github.com/hashicorp/terraform-provider-azurerm/utils" +) + +type KubernetesFleetUpdateStrategyTestResource struct{} + +func TestAccKubernetesFleetUpdateStrategy_basic(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_kubernetes_fleet_update_strategy", "test") + r := KubernetesFleetUpdateStrategyTestResource{} + + data.ResourceTest(t, r, []acceptance.TestStep{ + { + Config: r.basic(data), + Check: acceptance.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + ), + }, + data.ImportStep(), + }) +} + +func TestAccKubernetesFleetUpdateStrategy_requiresImport(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_kubernetes_fleet_update_strategy", "test") + r := KubernetesFleetUpdateStrategyTestResource{} + + data.ResourceTest(t, r, []acceptance.TestStep{ + { + Config: r.basic(data), + Check: acceptance.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + ), + }, + data.RequiresImportErrorStep(r.requiresImport), + }) +} + +func TestAccKubernetesFleetUpdateStrategy_complete(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_kubernetes_fleet_update_strategy", "test") + r := KubernetesFleetUpdateStrategyTestResource{} + + data.ResourceTest(t, r, []acceptance.TestStep{ + { + Config: r.complete(data), + Check: acceptance.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + ), + }, + data.ImportStep(), + }) +} + +func TestAccKubernetesFleetUpdateStrategy_update(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_kubernetes_fleet_update_strategy", "test") + r := KubernetesFleetUpdateStrategyTestResource{} + + data.ResourceTest(t, r, []acceptance.TestStep{ + { + Config: r.basic(data), + Check: acceptance.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + ), + }, + data.ImportStep(), + { + Config: r.complete(data), + Check: acceptance.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + ), + }, + data.ImportStep(), + { + Config: r.basic(data), + Check: acceptance.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + ), + }, + data.ImportStep(), + }) +} +func (r KubernetesFleetUpdateStrategyTestResource) Exists(ctx context.Context, clients *clients.Client, state *pluginsdk.InstanceState) (*bool, error) { + id, err := fleetupdatestrategies.ParseUpdateStrategyID(state.ID) + if err != nil { + return nil, err + } + + resp, err := clients.Containers.FleetUpdateStrategiesClient.Get(ctx, *id) + if err != nil { + return nil, fmt.Errorf("reading %s: %+v", *id, err) + } + + return utils.Bool(resp.Model != nil), nil +} +func (r KubernetesFleetUpdateStrategyTestResource) basic(data acceptance.TestData) string { + return fmt.Sprintf(` +%s + +resource "azurerm_kubernetes_fleet_update_strategy" "test" { + name = "acctestfus-%[2]d" + fleet_manager_id = azurerm_kubernetes_fleet_manager.test.id + strategy { + stage { + name = "acctestfus-%[2]d" + group { + name = "acctestfus-%[2]d" + } + } + } +} +`, r.template(data), data.RandomInteger) +} + +func (r KubernetesFleetUpdateStrategyTestResource) requiresImport(data acceptance.TestData) string { + return fmt.Sprintf(` +%s + +resource "azurerm_kubernetes_fleet_update_strategy" "import" { + name = azurerm_kubernetes_fleet_update_strategy.test.name + fleet_manager_id = azurerm_kubernetes_fleet_update_strategy.test.fleet_manager_id + strategy { + stage { + name = "acctestfus-%[2]d" + group { + name = "acctestfus-%[2]d" + } + } + } +} +`, r.basic(data), data.RandomInteger) +} + +func (r KubernetesFleetUpdateStrategyTestResource) complete(data acceptance.TestData) string { + return fmt.Sprintf(` +%s + +resource "azurerm_kubernetes_fleet_update_strategy" "test" { + name = "acctestfus-%[2]d" + fleet_manager_id = azurerm_kubernetes_fleet_manager.test.id + strategy { + stage { + name = "acctestfus-%[2]d" + group { + name = "acctestfus-%[2]d" + } + after_stage_wait_in_seconds = 21 + } + } +} +`, r.template(data), data.RandomInteger) +} + +func (r KubernetesFleetUpdateStrategyTestResource) template(data acceptance.TestData) string { + return fmt.Sprintf(` + +provider "azurerm" { + features {} +} + +resource "azurerm_resource_group" "test" { + name = "acctest-rg-%[2]d" + location = "%[1]s" +} + +resource "azurerm_kubernetes_fleet_manager" "test" { + location = azurerm_resource_group.test.location + name = "acctestkfm-%[2]d" + resource_group_name = azurerm_resource_group.test.name + hub_profile { + dns_prefix = "val-%[2]d" + } +} +`, data.Locations.Primary, data.RandomInteger) +} diff --git a/internal/services/containers/registration.go b/internal/services/containers/registration.go index 4033a389066a..b2658f5d1c37 100644 --- a/internal/services/containers/registration.go +++ b/internal/services/containers/registration.go @@ -74,6 +74,7 @@ func (r Registration) Resources() []sdk.Resource { ContainerConnectedRegistryResource{}, KubernetesClusterExtensionResource{}, KubernetesFluxConfigurationResource{}, + KubernetesFleetUpdateStrategyResource{}, } resources = append(resources, r.autoRegistration.Resources()...) return resources diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/containerservice/2023-10-15/fleetupdatestrategies/README.md b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/containerservice/2023-10-15/fleetupdatestrategies/README.md new file mode 100644 index 000000000000..f00c6e04a149 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/containerservice/2023-10-15/fleetupdatestrategies/README.md @@ -0,0 +1,82 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/containerservice/2023-10-15/fleetupdatestrategies` Documentation + +The `fleetupdatestrategies` SDK allows for interaction with the Azure Resource Manager Service `containerservice` (API Version `2023-10-15`). + +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-10-15/fleetupdatestrategies" +``` + + +### Client Initialization + +```go +client := fleetupdatestrategies.NewFleetUpdateStrategiesClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `FleetUpdateStrategiesClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := fleetupdatestrategies.NewUpdateStrategyID("12345678-1234-9876-4563-123456789012", "example-resource-group", "fleetValue", "updateStrategyValue") + +payload := fleetupdatestrategies.FleetUpdateStrategy{ + // ... +} + + +if err := client.CreateOrUpdateThenPoll(ctx, id, payload, fleetupdatestrategies.DefaultCreateOrUpdateOperationOptions()); err != nil { + // handle the error +} +``` + + +### Example Usage: `FleetUpdateStrategiesClient.Delete` + +```go +ctx := context.TODO() +id := fleetupdatestrategies.NewUpdateStrategyID("12345678-1234-9876-4563-123456789012", "example-resource-group", "fleetValue", "updateStrategyValue") + +if err := client.DeleteThenPoll(ctx, id, fleetupdatestrategies.DefaultDeleteOperationOptions()); err != nil { + // handle the error +} +``` + + +### Example Usage: `FleetUpdateStrategiesClient.Get` + +```go +ctx := context.TODO() +id := fleetupdatestrategies.NewUpdateStrategyID("12345678-1234-9876-4563-123456789012", "example-resource-group", "fleetValue", "updateStrategyValue") + +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: `FleetUpdateStrategiesClient.ListByFleet` + +```go +ctx := context.TODO() +id := fleetupdatestrategies.NewFleetID("12345678-1234-9876-4563-123456789012", "example-resource-group", "fleetValue") + +// alternatively `client.ListByFleet(ctx, id)` can be used to do batched pagination +items, err := client.ListByFleetComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/containerservice/2023-10-15/fleetupdatestrategies/client.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/containerservice/2023-10-15/fleetupdatestrategies/client.go new file mode 100644 index 000000000000..0a3e82a874a4 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/containerservice/2023-10-15/fleetupdatestrategies/client.go @@ -0,0 +1,18 @@ +package fleetupdatestrategies + +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 FleetUpdateStrategiesClient struct { + Client autorest.Client + baseUri string +} + +func NewFleetUpdateStrategiesClientWithBaseURI(endpoint string) FleetUpdateStrategiesClient { + return FleetUpdateStrategiesClient{ + Client: autorest.NewClientWithUserAgent(userAgent()), + baseUri: endpoint, + } +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/containerservice/2023-10-15/fleetupdatestrategies/constants.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/containerservice/2023-10-15/fleetupdatestrategies/constants.go new file mode 100644 index 000000000000..f523368a5c3e --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/containerservice/2023-10-15/fleetupdatestrategies/constants.go @@ -0,0 +1,37 @@ +package fleetupdatestrategies + +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 FleetUpdateStrategyProvisioningState string + +const ( + FleetUpdateStrategyProvisioningStateCanceled FleetUpdateStrategyProvisioningState = "Canceled" + FleetUpdateStrategyProvisioningStateFailed FleetUpdateStrategyProvisioningState = "Failed" + FleetUpdateStrategyProvisioningStateSucceeded FleetUpdateStrategyProvisioningState = "Succeeded" +) + +func PossibleValuesForFleetUpdateStrategyProvisioningState() []string { + return []string{ + string(FleetUpdateStrategyProvisioningStateCanceled), + string(FleetUpdateStrategyProvisioningStateFailed), + string(FleetUpdateStrategyProvisioningStateSucceeded), + } +} + +func parseFleetUpdateStrategyProvisioningState(input string) (*FleetUpdateStrategyProvisioningState, error) { + vals := map[string]FleetUpdateStrategyProvisioningState{ + "canceled": FleetUpdateStrategyProvisioningStateCanceled, + "failed": FleetUpdateStrategyProvisioningStateFailed, + "succeeded": FleetUpdateStrategyProvisioningStateSucceeded, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := FleetUpdateStrategyProvisioningState(input) + return &out, nil +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/containerservice/2023-10-15/fleetupdatestrategies/id_fleet.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/containerservice/2023-10-15/fleetupdatestrategies/id_fleet.go new file mode 100644 index 000000000000..fec85c2c85f5 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/containerservice/2023-10-15/fleetupdatestrategies/id_fleet.go @@ -0,0 +1,125 @@ +package fleetupdatestrategies + +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 = FleetId{} + +// FleetId is a struct representing the Resource ID for a Fleet +type FleetId struct { + SubscriptionId string + ResourceGroupName string + FleetName string +} + +// NewFleetID returns a new FleetId struct +func NewFleetID(subscriptionId string, resourceGroupName string, fleetName string) FleetId { + return FleetId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + FleetName: fleetName, + } +} + +// ParseFleetID parses 'input' into a FleetId +func ParseFleetID(input string) (*FleetId, error) { + parser := resourceids.NewParserFromResourceIdType(FleetId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := FleetId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseFleetIDInsensitively parses 'input' case-insensitively into a FleetId +// note: this method should only be used for API response data and not user input +func ParseFleetIDInsensitively(input string) (*FleetId, error) { + parser := resourceids.NewParserFromResourceIdType(FleetId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := FleetId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *FleetId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.FleetName, ok = input.Parsed["fleetName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "fleetName", input) + } + + return nil +} + +// ValidateFleetID checks that 'input' can be parsed as a Fleet ID +func ValidateFleetID(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 := ParseFleetID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Fleet ID +func (id FleetId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ContainerService/fleets/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.FleetName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Fleet ID +func (id FleetId) 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("staticFleets", "fleets", "fleets"), + resourceids.UserSpecifiedSegment("fleetName", "fleetValue"), + } +} + +// String returns a human-readable description of this Fleet ID +func (id FleetId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Fleet Name: %q", id.FleetName), + } + return fmt.Sprintf("Fleet (%s)", strings.Join(components, "\n")) +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/containerservice/2023-10-15/fleetupdatestrategies/id_updatestrategy.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/containerservice/2023-10-15/fleetupdatestrategies/id_updatestrategy.go new file mode 100644 index 000000000000..6b236372bd9b --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/containerservice/2023-10-15/fleetupdatestrategies/id_updatestrategy.go @@ -0,0 +1,134 @@ +package fleetupdatestrategies + +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 = UpdateStrategyId{} + +// UpdateStrategyId is a struct representing the Resource ID for a Update Strategy +type UpdateStrategyId struct { + SubscriptionId string + ResourceGroupName string + FleetName string + UpdateStrategyName string +} + +// NewUpdateStrategyID returns a new UpdateStrategyId struct +func NewUpdateStrategyID(subscriptionId string, resourceGroupName string, fleetName string, updateStrategyName string) UpdateStrategyId { + return UpdateStrategyId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + FleetName: fleetName, + UpdateStrategyName: updateStrategyName, + } +} + +// ParseUpdateStrategyID parses 'input' into a UpdateStrategyId +func ParseUpdateStrategyID(input string) (*UpdateStrategyId, error) { + parser := resourceids.NewParserFromResourceIdType(UpdateStrategyId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := UpdateStrategyId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseUpdateStrategyIDInsensitively parses 'input' case-insensitively into a UpdateStrategyId +// note: this method should only be used for API response data and not user input +func ParseUpdateStrategyIDInsensitively(input string) (*UpdateStrategyId, error) { + parser := resourceids.NewParserFromResourceIdType(UpdateStrategyId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := UpdateStrategyId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *UpdateStrategyId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.FleetName, ok = input.Parsed["fleetName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "fleetName", input) + } + + if id.UpdateStrategyName, ok = input.Parsed["updateStrategyName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "updateStrategyName", input) + } + + return nil +} + +// ValidateUpdateStrategyID checks that 'input' can be parsed as a Update Strategy ID +func ValidateUpdateStrategyID(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 := ParseUpdateStrategyID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Update Strategy ID +func (id UpdateStrategyId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ContainerService/fleets/%s/updateStrategies/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.FleetName, id.UpdateStrategyName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Update Strategy ID +func (id UpdateStrategyId) 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("staticFleets", "fleets", "fleets"), + resourceids.UserSpecifiedSegment("fleetName", "fleetValue"), + resourceids.StaticSegment("staticUpdateStrategies", "updateStrategies", "updateStrategies"), + resourceids.UserSpecifiedSegment("updateStrategyName", "updateStrategyValue"), + } +} + +// String returns a human-readable description of this Update Strategy ID +func (id UpdateStrategyId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Fleet Name: %q", id.FleetName), + fmt.Sprintf("Update Strategy Name: %q", id.UpdateStrategyName), + } + return fmt.Sprintf("Update Strategy (%s)", strings.Join(components, "\n")) +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/containerservice/2023-10-15/fleetupdatestrategies/method_createorupdate_autorest.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/containerservice/2023-10-15/fleetupdatestrategies/method_createorupdate_autorest.go new file mode 100644 index 000000000000..8f38f5b68b6f --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/containerservice/2023-10-15/fleetupdatestrategies/method_createorupdate_autorest.go @@ -0,0 +1,113 @@ +package fleetupdatestrategies + +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 +} + +type CreateOrUpdateOperationOptions struct { + IfMatch *string + IfNoneMatch *string +} + +func DefaultCreateOrUpdateOperationOptions() CreateOrUpdateOperationOptions { + return CreateOrUpdateOperationOptions{} +} + +func (o CreateOrUpdateOperationOptions) toHeaders() map[string]interface{} { + out := make(map[string]interface{}) + + if o.IfMatch != nil { + out["If-Match"] = *o.IfMatch + } + + if o.IfNoneMatch != nil { + out["If-None-Match"] = *o.IfNoneMatch + } + + return out +} + +func (o CreateOrUpdateOperationOptions) toQueryString() map[string]interface{} { + out := make(map[string]interface{}) + + return out +} + +// CreateOrUpdate ... +func (c FleetUpdateStrategiesClient) CreateOrUpdate(ctx context.Context, id UpdateStrategyId, input FleetUpdateStrategy, options CreateOrUpdateOperationOptions) (result CreateOrUpdateOperationResponse, err error) { + req, err := c.preparerForCreateOrUpdate(ctx, id, input, options) + if err != nil { + err = autorest.NewErrorWithError(err, "fleetupdatestrategies.FleetUpdateStrategiesClient", "CreateOrUpdate", nil, "Failure preparing request") + return + } + + result, err = c.senderForCreateOrUpdate(ctx, req) + if err != nil { + err = autorest.NewErrorWithError(err, "fleetupdatestrategies.FleetUpdateStrategiesClient", "CreateOrUpdate", result.HttpResponse, "Failure sending request") + return + } + + return +} + +// CreateOrUpdateThenPoll performs CreateOrUpdate then polls until it's completed +func (c FleetUpdateStrategiesClient) CreateOrUpdateThenPoll(ctx context.Context, id UpdateStrategyId, input FleetUpdateStrategy, options CreateOrUpdateOperationOptions) error { + result, err := c.CreateOrUpdate(ctx, id, input, options) + 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 FleetUpdateStrategiesClient) preparerForCreateOrUpdate(ctx context.Context, id UpdateStrategyId, input FleetUpdateStrategy, options CreateOrUpdateOperationOptions) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + for k, v := range options.toQueryString() { + queryParameters[k] = autorest.Encode("query", v) + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPut(), + autorest.WithBaseURL(c.baseUri), + autorest.WithHeaders(options.toHeaders()), + 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 FleetUpdateStrategiesClient) 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/containerservice/2023-10-15/fleetupdatestrategies/method_delete_autorest.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/containerservice/2023-10-15/fleetupdatestrategies/method_delete_autorest.go new file mode 100644 index 000000000000..ae9d272a95f9 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/containerservice/2023-10-15/fleetupdatestrategies/method_delete_autorest.go @@ -0,0 +1,107 @@ +package fleetupdatestrategies + +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 +} + +type DeleteOperationOptions struct { + IfMatch *string +} + +func DefaultDeleteOperationOptions() DeleteOperationOptions { + return DeleteOperationOptions{} +} + +func (o DeleteOperationOptions) toHeaders() map[string]interface{} { + out := make(map[string]interface{}) + + if o.IfMatch != nil { + out["If-Match"] = *o.IfMatch + } + + return out +} + +func (o DeleteOperationOptions) toQueryString() map[string]interface{} { + out := make(map[string]interface{}) + + return out +} + +// Delete ... +func (c FleetUpdateStrategiesClient) Delete(ctx context.Context, id UpdateStrategyId, options DeleteOperationOptions) (result DeleteOperationResponse, err error) { + req, err := c.preparerForDelete(ctx, id, options) + if err != nil { + err = autorest.NewErrorWithError(err, "fleetupdatestrategies.FleetUpdateStrategiesClient", "Delete", nil, "Failure preparing request") + return + } + + result, err = c.senderForDelete(ctx, req) + if err != nil { + err = autorest.NewErrorWithError(err, "fleetupdatestrategies.FleetUpdateStrategiesClient", "Delete", result.HttpResponse, "Failure sending request") + return + } + + return +} + +// DeleteThenPoll performs Delete then polls until it's completed +func (c FleetUpdateStrategiesClient) DeleteThenPoll(ctx context.Context, id UpdateStrategyId, options DeleteOperationOptions) error { + result, err := c.Delete(ctx, id, options) + 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 FleetUpdateStrategiesClient) preparerForDelete(ctx context.Context, id UpdateStrategyId, options DeleteOperationOptions) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + for k, v := range options.toQueryString() { + queryParameters[k] = autorest.Encode("query", v) + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsDelete(), + autorest.WithBaseURL(c.baseUri), + autorest.WithHeaders(options.toHeaders()), + 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 FleetUpdateStrategiesClient) 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/containerservice/2023-10-15/fleetupdatestrategies/method_get_autorest.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/containerservice/2023-10-15/fleetupdatestrategies/method_get_autorest.go new file mode 100644 index 000000000000..8aa71ed7aabe --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/containerservice/2023-10-15/fleetupdatestrategies/method_get_autorest.go @@ -0,0 +1,68 @@ +package fleetupdatestrategies + +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 *FleetUpdateStrategy +} + +// Get ... +func (c FleetUpdateStrategiesClient) Get(ctx context.Context, id UpdateStrategyId) (result GetOperationResponse, err error) { + req, err := c.preparerForGet(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "fleetupdatestrategies.FleetUpdateStrategiesClient", "Get", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "fleetupdatestrategies.FleetUpdateStrategiesClient", "Get", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForGet(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "fleetupdatestrategies.FleetUpdateStrategiesClient", "Get", result.HttpResponse, "Failure responding to request") + return + } + + return +} + +// preparerForGet prepares the Get request. +func (c FleetUpdateStrategiesClient) preparerForGet(ctx context.Context, id UpdateStrategyId) (*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 FleetUpdateStrategiesClient) 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-10-15/fleetupdatestrategies/method_listbyfleet_autorest.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/containerservice/2023-10-15/fleetupdatestrategies/method_listbyfleet_autorest.go new file mode 100644 index 000000000000..88cb6a179aa4 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/containerservice/2023-10-15/fleetupdatestrategies/method_listbyfleet_autorest.go @@ -0,0 +1,186 @@ +package fleetupdatestrategies + +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 ListByFleetOperationResponse struct { + HttpResponse *http.Response + Model *[]FleetUpdateStrategy + + nextLink *string + nextPageFunc func(ctx context.Context, nextLink string) (ListByFleetOperationResponse, error) +} + +type ListByFleetCompleteResult struct { + Items []FleetUpdateStrategy +} + +func (r ListByFleetOperationResponse) HasMore() bool { + return r.nextLink != nil +} + +func (r ListByFleetOperationResponse) LoadMore(ctx context.Context) (resp ListByFleetOperationResponse, err error) { + if !r.HasMore() { + err = fmt.Errorf("no more pages returned") + return + } + return r.nextPageFunc(ctx, *r.nextLink) +} + +// ListByFleet ... +func (c FleetUpdateStrategiesClient) ListByFleet(ctx context.Context, id FleetId) (resp ListByFleetOperationResponse, err error) { + req, err := c.preparerForListByFleet(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "fleetupdatestrategies.FleetUpdateStrategiesClient", "ListByFleet", nil, "Failure preparing request") + return + } + + resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "fleetupdatestrategies.FleetUpdateStrategiesClient", "ListByFleet", resp.HttpResponse, "Failure sending request") + return + } + + resp, err = c.responderForListByFleet(resp.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "fleetupdatestrategies.FleetUpdateStrategiesClient", "ListByFleet", resp.HttpResponse, "Failure responding to request") + return + } + return +} + +// preparerForListByFleet prepares the ListByFleet request. +func (c FleetUpdateStrategiesClient) preparerForListByFleet(ctx context.Context, id FleetId) (*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/updateStrategies", id.ID())), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// preparerForListByFleetWithNextLink prepares the ListByFleet request with the given nextLink token. +func (c FleetUpdateStrategiesClient) preparerForListByFleetWithNextLink(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)) +} + +// responderForListByFleet handles the response to the ListByFleet request. The method always +// closes the http.Response Body. +func (c FleetUpdateStrategiesClient) responderForListByFleet(resp *http.Response) (result ListByFleetOperationResponse, err error) { + type page struct { + Values []FleetUpdateStrategy `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 ListByFleetOperationResponse, err error) { + req, err := c.preparerForListByFleetWithNextLink(ctx, nextLink) + if err != nil { + err = autorest.NewErrorWithError(err, "fleetupdatestrategies.FleetUpdateStrategiesClient", "ListByFleet", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "fleetupdatestrategies.FleetUpdateStrategiesClient", "ListByFleet", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForListByFleet(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "fleetupdatestrategies.FleetUpdateStrategiesClient", "ListByFleet", result.HttpResponse, "Failure responding to request") + return + } + + return + } + } + return +} + +// ListByFleetComplete retrieves all of the results into a single object +func (c FleetUpdateStrategiesClient) ListByFleetComplete(ctx context.Context, id FleetId) (ListByFleetCompleteResult, error) { + return c.ListByFleetCompleteMatchingPredicate(ctx, id, FleetUpdateStrategyOperationPredicate{}) +} + +// ListByFleetCompleteMatchingPredicate retrieves all of the results and then applied the predicate +func (c FleetUpdateStrategiesClient) ListByFleetCompleteMatchingPredicate(ctx context.Context, id FleetId, predicate FleetUpdateStrategyOperationPredicate) (resp ListByFleetCompleteResult, err error) { + items := make([]FleetUpdateStrategy, 0) + + page, err := c.ListByFleet(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 := ListByFleetCompleteResult{ + Items: items, + } + return out, nil +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/containerservice/2023-10-15/fleetupdatestrategies/model_fleetupdatestrategy.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/containerservice/2023-10-15/fleetupdatestrategies/model_fleetupdatestrategy.go new file mode 100644 index 000000000000..7b4b67c9a736 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/containerservice/2023-10-15/fleetupdatestrategies/model_fleetupdatestrategy.go @@ -0,0 +1,17 @@ +package fleetupdatestrategies + +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 FleetUpdateStrategy struct { + ETag *string `json:"eTag,omitempty"` + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *FleetUpdateStrategyProperties `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/containerservice/2023-10-15/fleetupdatestrategies/model_fleetupdatestrategyproperties.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/containerservice/2023-10-15/fleetupdatestrategies/model_fleetupdatestrategyproperties.go new file mode 100644 index 000000000000..c8e5d4ca7fa9 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/containerservice/2023-10-15/fleetupdatestrategies/model_fleetupdatestrategyproperties.go @@ -0,0 +1,9 @@ +package fleetupdatestrategies + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type FleetUpdateStrategyProperties struct { + ProvisioningState *FleetUpdateStrategyProvisioningState `json:"provisioningState,omitempty"` + Strategy UpdateRunStrategy `json:"strategy"` +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/containerservice/2023-10-15/fleetupdatestrategies/model_updategroup.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/containerservice/2023-10-15/fleetupdatestrategies/model_updategroup.go new file mode 100644 index 000000000000..fd63375417e8 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/containerservice/2023-10-15/fleetupdatestrategies/model_updategroup.go @@ -0,0 +1,8 @@ +package fleetupdatestrategies + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type UpdateGroup struct { + Name string `json:"name"` +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/containerservice/2023-10-15/fleetupdatestrategies/model_updaterunstrategy.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/containerservice/2023-10-15/fleetupdatestrategies/model_updaterunstrategy.go new file mode 100644 index 000000000000..e4d0b18bf09e --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/containerservice/2023-10-15/fleetupdatestrategies/model_updaterunstrategy.go @@ -0,0 +1,8 @@ +package fleetupdatestrategies + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type UpdateRunStrategy struct { + Stages []UpdateStage `json:"stages"` +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/containerservice/2023-10-15/fleetupdatestrategies/model_updatestage.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/containerservice/2023-10-15/fleetupdatestrategies/model_updatestage.go new file mode 100644 index 000000000000..3eb8bedc82a8 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/containerservice/2023-10-15/fleetupdatestrategies/model_updatestage.go @@ -0,0 +1,10 @@ +package fleetupdatestrategies + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type UpdateStage struct { + AfterStageWaitInSeconds *int64 `json:"afterStageWaitInSeconds,omitempty"` + Groups *[]UpdateGroup `json:"groups,omitempty"` + Name string `json:"name"` +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/containerservice/2023-10-15/fleetupdatestrategies/predicates.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/containerservice/2023-10-15/fleetupdatestrategies/predicates.go new file mode 100644 index 000000000000..6288080dc83e --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/containerservice/2023-10-15/fleetupdatestrategies/predicates.go @@ -0,0 +1,32 @@ +package fleetupdatestrategies + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type FleetUpdateStrategyOperationPredicate struct { + ETag *string + Id *string + Name *string + Type *string +} + +func (p FleetUpdateStrategyOperationPredicate) Matches(input FleetUpdateStrategy) bool { + + if p.ETag != nil && (input.ETag == nil || *p.ETag != *input.ETag) { + return false + } + + if p.Id != nil && (input.Id == nil || *p.Id != *input.Id) { + 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-10-15/fleetupdatestrategies/version.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/containerservice/2023-10-15/fleetupdatestrategies/version.go new file mode 100644 index 000000000000..ec414cf17bf6 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/containerservice/2023-10-15/fleetupdatestrategies/version.go @@ -0,0 +1,12 @@ +package fleetupdatestrategies + +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-10-15" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/fleetupdatestrategies/%s", defaultApiVersion) +} diff --git a/vendor/modules.txt b/vendor/modules.txt index d3f8d7d27c08..ae32682c261b 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -364,6 +364,7 @@ github.com/hashicorp/go-azure-sdk/resource-manager/containerservice/2023-04-02-p github.com/hashicorp/go-azure-sdk/resource-manager/containerservice/2023-04-02-preview/maintenanceconfigurations github.com/hashicorp/go-azure-sdk/resource-manager/containerservice/2023-04-02-preview/managedclusters github.com/hashicorp/go-azure-sdk/resource-manager/containerservice/2023-04-02-preview/snapshots +github.com/hashicorp/go-azure-sdk/resource-manager/containerservice/2023-10-15/fleetupdatestrategies 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/sqldedicatedgateway github.com/hashicorp/go-azure-sdk/resource-manager/cosmosdb/2022-11-15/mongorbacs diff --git a/website/docs/r/kubernetes_fleet_update_strategy.html.markdown b/website/docs/r/kubernetes_fleet_update_strategy.html.markdown new file mode 100644 index 000000000000..1f5b6fed9ec4 --- /dev/null +++ b/website/docs/r/kubernetes_fleet_update_strategy.html.markdown @@ -0,0 +1,98 @@ +--- +subcategory: "Container" +layout: "azurerm" +page_title: "Azure Resource Manager: azurerm_kubernetes_fleet_update_strategy" +description: |- + Manages a Kubernetes Fleet Update Strategy. +--- + +# azurerm_kubernetes_fleet_update_strategy + +Manages a Kubernetes Fleet Update Strategy. + +## Example Usage + +```hcl +resource "azurerm_resource_group" "example" { + name = "example-rg" + location = "westeurope" +} + +resource "azurerm_kubernetes_fleet_manager" "example" { + location = azurerm_resource_group.example.location + name = "example" + resource_group_name = azurerm_resource_group.example.name + hub_profile { + dns_prefix = "example-dns-prefix" + } +} + +resource "azurerm_kubernetes_fleet_update_strategy" "example" { + name = "example" + fleet_manager_id = azurerm_kubernetes_fleet_manager.example.id + strategy { + stage { + name = "example-stage-1" + group { + name = "example-group-1" + } + after_stage_wait_in_seconds = 21 + } + } +} +``` + +## Arguments Reference + +The following arguments are supported: + +* `name` - (Required) The name which should be used for this Kubernetes Fleet Update Strategy. Changing this forces a new Kubernetes Fleet Update Strategy to be created. + +* `fleet_manager_id` - (Required) The ID of the Fleet Manager. Changing this forces a new Kubernetes Fleet Update Strategy to be created. + +* `strategy` - (Required) A `strategy` block as defined below. + +--- + +A `strategy` block supports the following: + +* `stage` - (Required) One or more `stage` blocks as defined below. + +--- + +A `stage` block supports the following: + +* `group` - (Required) One or more `group` blocks as defined below. + +* `name` - (Required) The name which should be used for this stage. + +* `after_stage_wait_in_seconds` - (Optional) Specifies the time in seconds to wait at the end of this stage before starting the next one. + +--- + +A `group` block supports the following: + +* `name` - (Required) The name which should be used for this group. + +## Attributes Reference + +In addition to the Arguments listed above - the following Attributes are exported: + +* `id` - The ID of the Kubernetes Fleet Update Strategy. + +## 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 Kubernetes Fleet Update Strategy. +* `read` - (Defaults to 5 minutes) Used when retrieving the Kubernetes Fleet Update Strategy. +* `update` - (Defaults to 30 minutes) Used when updating the Kubernetes Fleet Update Strategy. +* `delete` - (Defaults to 30 minutes) Used when deleting the Kubernetes Fleet Update Strategy. + +## Import + +Kubernetes Fleet Update Strategies can be imported using the `resource id`, e.g. + +```shell +terraform import azurerm_kubernetes_fleet_update_strategy.example /subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/ContainerService/fleets/fleet1/updateStrategies/updateStrategy1 +``` \ No newline at end of file From 6450c725500d217eed564d7bb7fc11df0320f368 Mon Sep 17 00:00:00 2001 From: Heng Lu Date: Thu, 28 Dec 2023 10:25:59 +0800 Subject: [PATCH 2/6] update tests --- .../kubernetes_fleet_update_strategy_resource_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/internal/services/containers/kubernetes_fleet_update_strategy_resource_test.go b/internal/services/containers/kubernetes_fleet_update_strategy_resource_test.go index 3cddd694e649..e0a162875c68 100644 --- a/internal/services/containers/kubernetes_fleet_update_strategy_resource_test.go +++ b/internal/services/containers/kubernetes_fleet_update_strategy_resource_test.go @@ -148,9 +148,9 @@ resource "azurerm_kubernetes_fleet_update_strategy" "test" { fleet_manager_id = azurerm_kubernetes_fleet_manager.test.id strategy { stage { - name = "acctestfus-%[2]d" + name = "acctestfus-%[2]d-complte" group { - name = "acctestfus-%[2]d" + name = "acctestfus-%[2]d-complete" } after_stage_wait_in_seconds = 21 } From 6728f27ac5f237fa47b4639277ae107ce7d3b57b Mon Sep 17 00:00:00 2001 From: Heng Lu Date: Mon, 29 Jan 2024 16:14:10 +0800 Subject: [PATCH 3/6] update --- ...bernetes_fleet_update_strategy_resource.go | 79 ++++++------------- ...tes_fleet_update_strategy_resource_test.go | 44 +++++------ ...rnetes_fleet_update_strategy.html.markdown | 27 +++---- 3 files changed, 57 insertions(+), 93 deletions(-) diff --git a/internal/services/containers/kubernetes_fleet_update_strategy_resource.go b/internal/services/containers/kubernetes_fleet_update_strategy_resource.go index db7f8449ed5e..af7894e098e7 100644 --- a/internal/services/containers/kubernetes_fleet_update_strategy_resource.go +++ b/internal/services/containers/kubernetes_fleet_update_strategy_resource.go @@ -25,19 +25,15 @@ func (r KubernetesFleetUpdateStrategyResource) ModelObject() interface{} { } type KubernetesFleetUpdateStrategyResourceSchema struct { - FleetId string `tfschema:"fleet_manager_id"` - Name string `tfschema:"name"` - Strategy []KubernetesFleetUpdateStrategyResourceUpdateRunStrategySchema `tfschema:"strategy"` + KubernetesFleetManagerId string `tfschema:"kubernetes_fleet_manager_id"` + Name string `tfschema:"name"` + Stage []KubernetesFleetUpdateStrategyResourceUpdateStageSchema `tfschema:"stage"` } type KubernetesFleetUpdateStrategyResourceUpdateGroupSchema struct { Name string `tfschema:"name"` } -type KubernetesFleetUpdateStrategyResourceUpdateRunStrategySchema struct { - Stage []KubernetesFleetUpdateStrategyResourceUpdateStageSchema `tfschema:"stage"` -} - type KubernetesFleetUpdateStrategyResourceUpdateStageSchema struct { AfterStageWaitInSeconds int64 `tfschema:"after_stage_wait_in_seconds"` Group []KubernetesFleetUpdateStrategyResourceUpdateGroupSchema `tfschema:"group"` @@ -60,17 +56,23 @@ func (r KubernetesFleetUpdateStrategyResource) Arguments() map[string]*pluginsdk Type: pluginsdk.TypeString, }, - "fleet_manager_id": commonschema.ResourceIDReferenceRequiredForceNew(fleetupdatestrategies.FleetId{}), + "kubernetes_fleet_manager_id": commonschema.ResourceIDReferenceRequiredForceNew(fleetupdatestrategies.FleetId{}), - "strategy": { + "stage": { Required: true, - MaxItems: 1, Type: pluginsdk.TypeList, Elem: &pluginsdk.Resource{ Schema: map[string]*pluginsdk.Schema{ - "stage": { + "name": { + Required: true, + Type: pluginsdk.TypeString, + ValidateFunc: validation.StringIsNotEmpty, + }, + + "group": { Required: true, Type: pluginsdk.TypeList, + MinItems: 1, Elem: &pluginsdk.Resource{ Schema: map[string]*pluginsdk.Schema{ "name": { @@ -78,29 +80,14 @@ func (r KubernetesFleetUpdateStrategyResource) Arguments() map[string]*pluginsdk Type: pluginsdk.TypeString, ValidateFunc: validation.StringIsNotEmpty, }, - - "group": { - Required: true, - Type: pluginsdk.TypeList, - MinItems: 1, - Elem: &pluginsdk.Resource{ - Schema: map[string]*pluginsdk.Schema{ - "name": { - Required: true, - Type: pluginsdk.TypeString, - ValidateFunc: validation.StringIsNotEmpty, - }, - }, - }, - }, - - "after_stage_wait_in_seconds": { - Optional: true, - Type: pluginsdk.TypeInt, - }, }, }, }, + + "after_stage_wait_in_seconds": { + Optional: true, + Type: pluginsdk.TypeInt, + }, }, }, }, @@ -122,7 +109,7 @@ func (r KubernetesFleetUpdateStrategyResource) Create() sdk.ResourceFunc { return fmt.Errorf("decoding: %+v", err) } - fleetId, err := commonids.ParseFleetID(config.FleetId) + fleetId, err := commonids.ParseFleetID(config.KubernetesFleetManagerId) if err != nil { return err } @@ -141,7 +128,9 @@ func (r KubernetesFleetUpdateStrategyResource) Create() sdk.ResourceFunc { payload := fleetupdatestrategies.FleetUpdateStrategy{ Properties: &fleetupdatestrategies.FleetUpdateStrategyProperties{ - Strategy: expandKubernetesFleetUpdateStrategy(config.Strategy), + Strategy: fleetupdatestrategies.UpdateRunStrategy{ + Stages: expandKubernetesFleetUpdateStrategyStage(config.Stage), + }, }, } @@ -180,8 +169,8 @@ func (r KubernetesFleetUpdateStrategyResource) Update() sdk.ResourceFunc { } payload := *existing.Model - if metadata.ResourceData.HasChange("strategy") { - payload.Properties.Strategy.Stages = expandKubernetesFleetUpdateStrategyStage(config.Strategy[0].Stage) + if metadata.ResourceData.HasChange("stage") { + payload.Properties.Strategy.Stages = expandKubernetesFleetUpdateStrategyStage(config.Stage) } if err := client.CreateOrUpdateThenPoll(ctx, *id, payload, fleetupdatestrategies.DefaultCreateOrUpdateOperationOptions()); err != nil { @@ -215,9 +204,9 @@ func (r KubernetesFleetUpdateStrategyResource) Read() sdk.ResourceFunc { if model := resp.Model; model != nil { schema.Name = id.UpdateStrategyName - schema.FleetId = fleetupdatestrategies.NewFleetID(id.SubscriptionId, id.ResourceGroupName, id.FleetName).ID() + schema.KubernetesFleetManagerId = fleetupdatestrategies.NewFleetID(id.SubscriptionId, id.ResourceGroupName, id.FleetName).ID() if model.Properties != nil { - schema.Strategy = flattenKubernetesFleetUpdateStrategy(model.Properties.Strategy) + schema.Stage = flattenKubernetesFleetUpdateStrategyStage(model.Properties.Strategy.Stages) } } @@ -245,14 +234,6 @@ func (r KubernetesFleetUpdateStrategyResource) Delete() sdk.ResourceFunc { } } -func expandKubernetesFleetUpdateStrategy(input []KubernetesFleetUpdateStrategyResourceUpdateRunStrategySchema) fleetupdatestrategies.UpdateRunStrategy { - output := fleetupdatestrategies.UpdateRunStrategy{} - if len(input) > 0 { - output.Stages = expandKubernetesFleetUpdateStrategyStage(input[0].Stage) - } - return output -} - func expandKubernetesFleetUpdateStrategyStage(input []KubernetesFleetUpdateStrategyResourceUpdateStageSchema) []fleetupdatestrategies.UpdateStage { output := make([]fleetupdatestrategies.UpdateStage, 0) for _, stage := range input { @@ -275,14 +256,6 @@ func expandKubernetesFleetUpdateStrategyGroup(input []KubernetesFleetUpdateStrat return &output } -func flattenKubernetesFleetUpdateStrategy(input fleetupdatestrategies.UpdateRunStrategy) []KubernetesFleetUpdateStrategyResourceUpdateRunStrategySchema { - output := make([]KubernetesFleetUpdateStrategyResourceUpdateRunStrategySchema, 0) - output = append(output, KubernetesFleetUpdateStrategyResourceUpdateRunStrategySchema{ - Stage: flattenKubernetesFleetUpdateStrategyStage(input.Stages), - }) - return output -} - func flattenKubernetesFleetUpdateStrategyStage(input []fleetupdatestrategies.UpdateStage) []KubernetesFleetUpdateStrategyResourceUpdateStageSchema { output := make([]KubernetesFleetUpdateStrategyResourceUpdateStageSchema, 0) for _, stage := range input { diff --git a/internal/services/containers/kubernetes_fleet_update_strategy_resource_test.go b/internal/services/containers/kubernetes_fleet_update_strategy_resource_test.go index e0a162875c68..60c7ec6ddfca 100644 --- a/internal/services/containers/kubernetes_fleet_update_strategy_resource_test.go +++ b/internal/services/containers/kubernetes_fleet_update_strategy_resource_test.go @@ -106,16 +106,16 @@ func (r KubernetesFleetUpdateStrategyTestResource) basic(data acceptance.TestDat %s resource "azurerm_kubernetes_fleet_update_strategy" "test" { - name = "acctestfus-%[2]d" - fleet_manager_id = azurerm_kubernetes_fleet_manager.test.id - strategy { - stage { + name = "acctestfus-%[2]d" + kubernetes_fleet_manager_id = azurerm_kubernetes_fleet_manager.test.id + + stage { + name = "acctestfus-%[2]d" + group { name = "acctestfus-%[2]d" - group { - name = "acctestfus-%[2]d" - } } } + } `, r.template(data), data.RandomInteger) } @@ -125,16 +125,15 @@ func (r KubernetesFleetUpdateStrategyTestResource) requiresImport(data acceptanc %s resource "azurerm_kubernetes_fleet_update_strategy" "import" { - name = azurerm_kubernetes_fleet_update_strategy.test.name - fleet_manager_id = azurerm_kubernetes_fleet_update_strategy.test.fleet_manager_id - strategy { - stage { + name = azurerm_kubernetes_fleet_update_strategy.test.name + kubernetes_fleet_manager_id = azurerm_kubernetes_fleet_update_strategy.test.kubernetes_fleet_manager_id + stage { + name = "acctestfus-%[2]d" + group { name = "acctestfus-%[2]d" - group { - name = "acctestfus-%[2]d" - } } } + } `, r.basic(data), data.RandomInteger) } @@ -144,16 +143,15 @@ func (r KubernetesFleetUpdateStrategyTestResource) complete(data acceptance.Test %s resource "azurerm_kubernetes_fleet_update_strategy" "test" { - name = "acctestfus-%[2]d" - fleet_manager_id = azurerm_kubernetes_fleet_manager.test.id - strategy { - stage { - name = "acctestfus-%[2]d-complte" - group { - name = "acctestfus-%[2]d-complete" - } - after_stage_wait_in_seconds = 21 + name = "acctestfus-%[2]d" + kubernetes_fleet_manager_id = azurerm_kubernetes_fleet_manager.test.id + + stage { + name = "acctestfus-%[2]d-complte" + group { + name = "acctestfus-%[2]d-complete" } + after_stage_wait_in_seconds = 21 } } `, r.template(data), data.RandomInteger) diff --git a/website/docs/r/kubernetes_fleet_update_strategy.html.markdown b/website/docs/r/kubernetes_fleet_update_strategy.html.markdown index 1f5b6fed9ec4..3121da4c5eba 100644 --- a/website/docs/r/kubernetes_fleet_update_strategy.html.markdown +++ b/website/docs/r/kubernetes_fleet_update_strategy.html.markdown @@ -28,16 +28,15 @@ resource "azurerm_kubernetes_fleet_manager" "example" { } resource "azurerm_kubernetes_fleet_update_strategy" "example" { - name = "example" - fleet_manager_id = azurerm_kubernetes_fleet_manager.example.id - strategy { - stage { - name = "example-stage-1" - group { - name = "example-group-1" - } - after_stage_wait_in_seconds = 21 + name = "example" + kubernetes_fleet_manager_id = azurerm_kubernetes_fleet_manager.example.id + + stage { + name = "example-stage-1" + group { + name = "example-group-1" } + after_stage_wait_in_seconds = 21 } } ``` @@ -48,13 +47,7 @@ The following arguments are supported: * `name` - (Required) The name which should be used for this Kubernetes Fleet Update Strategy. Changing this forces a new Kubernetes Fleet Update Strategy to be created. -* `fleet_manager_id` - (Required) The ID of the Fleet Manager. Changing this forces a new Kubernetes Fleet Update Strategy to be created. - -* `strategy` - (Required) A `strategy` block as defined below. - ---- - -A `strategy` block supports the following: +* `kubernetes_fleet_manager_id` - (Required) The ID of the Fleet Manager. Changing this forces a new Kubernetes Fleet Update Strategy to be created. * `stage` - (Required) One or more `stage` blocks as defined below. @@ -95,4 +88,4 @@ Kubernetes Fleet Update Strategies can be imported using the `resource id`, e.g. ```shell terraform import azurerm_kubernetes_fleet_update_strategy.example /subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/ContainerService/fleets/fleet1/updateStrategies/updateStrategy1 -``` \ No newline at end of file +``` From ca1caa7400e5e4274c69ab47870babfcb14eb11c Mon Sep 17 00:00:00 2001 From: Heng Lu Date: Mon, 29 Jan 2024 16:15:36 +0800 Subject: [PATCH 4/6] update --- .../kubernetes_fleet_update_strategy_resource_test.go | 3 --- website/docs/r/kubernetes_fleet_update_strategy.html.markdown | 1 - 2 files changed, 4 deletions(-) diff --git a/internal/services/containers/kubernetes_fleet_update_strategy_resource_test.go b/internal/services/containers/kubernetes_fleet_update_strategy_resource_test.go index 60c7ec6ddfca..873cf1f8075f 100644 --- a/internal/services/containers/kubernetes_fleet_update_strategy_resource_test.go +++ b/internal/services/containers/kubernetes_fleet_update_strategy_resource_test.go @@ -108,7 +108,6 @@ func (r KubernetesFleetUpdateStrategyTestResource) basic(data acceptance.TestDat resource "azurerm_kubernetes_fleet_update_strategy" "test" { name = "acctestfus-%[2]d" kubernetes_fleet_manager_id = azurerm_kubernetes_fleet_manager.test.id - stage { name = "acctestfus-%[2]d" group { @@ -133,7 +132,6 @@ resource "azurerm_kubernetes_fleet_update_strategy" "import" { name = "acctestfus-%[2]d" } } - } `, r.basic(data), data.RandomInteger) } @@ -145,7 +143,6 @@ func (r KubernetesFleetUpdateStrategyTestResource) complete(data acceptance.Test resource "azurerm_kubernetes_fleet_update_strategy" "test" { name = "acctestfus-%[2]d" kubernetes_fleet_manager_id = azurerm_kubernetes_fleet_manager.test.id - stage { name = "acctestfus-%[2]d-complte" group { diff --git a/website/docs/r/kubernetes_fleet_update_strategy.html.markdown b/website/docs/r/kubernetes_fleet_update_strategy.html.markdown index 3121da4c5eba..030f418c0ac4 100644 --- a/website/docs/r/kubernetes_fleet_update_strategy.html.markdown +++ b/website/docs/r/kubernetes_fleet_update_strategy.html.markdown @@ -30,7 +30,6 @@ resource "azurerm_kubernetes_fleet_manager" "example" { resource "azurerm_kubernetes_fleet_update_strategy" "example" { name = "example" kubernetes_fleet_manager_id = azurerm_kubernetes_fleet_manager.example.id - stage { name = "example-stage-1" group { From b767642feef7df847301c2e0f7fa4b7e052eab3b Mon Sep 17 00:00:00 2001 From: Heng Lu Date: Mon, 29 Jan 2024 16:24:21 +0800 Subject: [PATCH 5/6] go mod --- .../2023-10-15/fleetupdatestrategies/id_fleet.go | 6 +++--- .../2023-10-15/fleetupdatestrategies/id_updatestrategy.go | 6 +++--- .../fleetupdatestrategies/method_createorupdate_autorest.go | 1 + 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/containerservice/2023-10-15/fleetupdatestrategies/id_fleet.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/containerservice/2023-10-15/fleetupdatestrategies/id_fleet.go index fec85c2c85f5..a8cc299bd464 100644 --- a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/containerservice/2023-10-15/fleetupdatestrategies/id_fleet.go +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/containerservice/2023-10-15/fleetupdatestrategies/id_fleet.go @@ -10,7 +10,7 @@ import ( // 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 = FleetId{} +var _ resourceids.ResourceId = &FleetId{} // FleetId is a struct representing the Resource ID for a Fleet type FleetId struct { @@ -30,7 +30,7 @@ func NewFleetID(subscriptionId string, resourceGroupName string, fleetName strin // ParseFleetID parses 'input' into a FleetId func ParseFleetID(input string) (*FleetId, error) { - parser := resourceids.NewParserFromResourceIdType(FleetId{}) + parser := resourceids.NewParserFromResourceIdType(&FleetId{}) parsed, err := parser.Parse(input, false) if err != nil { return nil, fmt.Errorf("parsing %q: %+v", input, err) @@ -47,7 +47,7 @@ func ParseFleetID(input string) (*FleetId, error) { // ParseFleetIDInsensitively parses 'input' case-insensitively into a FleetId // note: this method should only be used for API response data and not user input func ParseFleetIDInsensitively(input string) (*FleetId, error) { - parser := resourceids.NewParserFromResourceIdType(FleetId{}) + parser := resourceids.NewParserFromResourceIdType(&FleetId{}) parsed, err := parser.Parse(input, true) if err != nil { return nil, fmt.Errorf("parsing %q: %+v", input, err) diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/containerservice/2023-10-15/fleetupdatestrategies/id_updatestrategy.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/containerservice/2023-10-15/fleetupdatestrategies/id_updatestrategy.go index 6b236372bd9b..23e80bd2c66b 100644 --- a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/containerservice/2023-10-15/fleetupdatestrategies/id_updatestrategy.go +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/containerservice/2023-10-15/fleetupdatestrategies/id_updatestrategy.go @@ -10,7 +10,7 @@ import ( // 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 = UpdateStrategyId{} +var _ resourceids.ResourceId = &UpdateStrategyId{} // UpdateStrategyId is a struct representing the Resource ID for a Update Strategy type UpdateStrategyId struct { @@ -32,7 +32,7 @@ func NewUpdateStrategyID(subscriptionId string, resourceGroupName string, fleetN // ParseUpdateStrategyID parses 'input' into a UpdateStrategyId func ParseUpdateStrategyID(input string) (*UpdateStrategyId, error) { - parser := resourceids.NewParserFromResourceIdType(UpdateStrategyId{}) + parser := resourceids.NewParserFromResourceIdType(&UpdateStrategyId{}) parsed, err := parser.Parse(input, false) if err != nil { return nil, fmt.Errorf("parsing %q: %+v", input, err) @@ -49,7 +49,7 @@ func ParseUpdateStrategyID(input string) (*UpdateStrategyId, error) { // ParseUpdateStrategyIDInsensitively parses 'input' case-insensitively into a UpdateStrategyId // note: this method should only be used for API response data and not user input func ParseUpdateStrategyIDInsensitively(input string) (*UpdateStrategyId, error) { - parser := resourceids.NewParserFromResourceIdType(UpdateStrategyId{}) + parser := resourceids.NewParserFromResourceIdType(&UpdateStrategyId{}) parsed, err := parser.Parse(input, true) if err != nil { return nil, fmt.Errorf("parsing %q: %+v", input, err) diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/containerservice/2023-10-15/fleetupdatestrategies/method_createorupdate_autorest.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/containerservice/2023-10-15/fleetupdatestrategies/method_createorupdate_autorest.go index 8f38f5b68b6f..d617ded082c0 100644 --- a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/containerservice/2023-10-15/fleetupdatestrategies/method_createorupdate_autorest.go +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/containerservice/2023-10-15/fleetupdatestrategies/method_createorupdate_autorest.go @@ -16,6 +16,7 @@ import ( type CreateOrUpdateOperationResponse struct { Poller polling.LongRunningPoller HttpResponse *http.Response + Model *FleetUpdateStrategy } type CreateOrUpdateOperationOptions struct { From fb8778d7815faf3e6fe38c90cc0f646337259ecf Mon Sep 17 00:00:00 2001 From: Heng Lu Date: Mon, 29 Jan 2024 16:31:22 +0800 Subject: [PATCH 6/6] fix --- .../containers/kubernetes_fleet_update_strategy_resource.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/services/containers/kubernetes_fleet_update_strategy_resource.go b/internal/services/containers/kubernetes_fleet_update_strategy_resource.go index af7894e098e7..37ddc2d4db64 100644 --- a/internal/services/containers/kubernetes_fleet_update_strategy_resource.go +++ b/internal/services/containers/kubernetes_fleet_update_strategy_resource.go @@ -56,7 +56,7 @@ func (r KubernetesFleetUpdateStrategyResource) Arguments() map[string]*pluginsdk Type: pluginsdk.TypeString, }, - "kubernetes_fleet_manager_id": commonschema.ResourceIDReferenceRequiredForceNew(fleetupdatestrategies.FleetId{}), + "kubernetes_fleet_manager_id": commonschema.ResourceIDReferenceRequiredForceNew(&fleetupdatestrategies.FleetId{}), "stage": { Required: true,