diff --git a/.github/labeler-issue-triage.yml b/.github/labeler-issue-triage.yml index 278889f16de1..5fc6bf40a288 100644 --- a/.github/labeler-issue-triage.yml +++ b/.github/labeler-issue-triage.yml @@ -72,7 +72,7 @@ service/cognitive-services: - '### (|New or )Affected Resource\(s\)\/Data Source\(s\)((.|\n)*)azurerm_(ai_services|cognitive_)((.|\n)*)###' service/communication: - - '### (|New or )Affected Resource\(s\)\/Data Source\(s\)((.|\n)*)azurerm_(communication_service|email_communication_service|gallery_application|orchestrated_virtual_machine_scale_set\W+|restore_point_collection|virtual_machine_gallery_application_assignment\W+|virtual_machine_implicit_data_disk_from_source\W+|virtual_machine_restore_point\W+|virtual_machine_restore_point_collection\W+|virtual_machine_run_command\W+)((.|\n)*)###' + - '### (|New or )Affected Resource\(s\)\/Data Source\(s\)((.|\n)*)azurerm_(communication_service|email_communication_service|gallery_application|orchestrated_virtual_machine_scale_set\W+|restore_point_collection|virtual_machine_gallery_application_assignment\W+|virtual_machine_implicit_data_disk_from_source\W+|virtual_machine_restore_point\W+|virtual_machine_restore_point_collection\W+|virtual_machine_run_command\W+|virtual_machine_scale_set_standby_pool\W+)((.|\n)*)###' service/connections: - '### (|New or )Affected Resource\(s\)\/Data Source\(s\)((.|\n)*)azurerm_(api_connection|managed_api)((.|\n)*)###' diff --git a/internal/services/compute/client/client.go b/internal/services/compute/client/client.go index 173d61f9f080..753abcc4366a 100644 --- a/internal/services/compute/client/client.go +++ b/internal/services/compute/client/client.go @@ -40,6 +40,7 @@ import ( "github.com/hashicorp/go-azure-sdk/resource-manager/compute/2024-03-01/virtualmachinescalesetvms" "github.com/hashicorp/go-azure-sdk/resource-manager/compute/2024-07-01/virtualmachinescalesets" "github.com/hashicorp/go-azure-sdk/resource-manager/marketplaceordering/2015-06-01/agreements" + "github.com/hashicorp/go-azure-sdk/resource-manager/standbypool/2024-03-01/standbyvirtualmachinepools" "github.com/hashicorp/terraform-provider-azurerm/internal/common" ) @@ -68,6 +69,7 @@ type Client struct { SkusClient *skus.SkusClient SSHPublicKeysClient *sshpublickeys.SshPublicKeysClient SnapshotsClient *snapshots.SnapshotsClient + StandbyVirtualMachinePoolsClient *standbyvirtualmachinepools.StandbyVirtualMachinePoolsClient VirtualMachinesClient *virtualmachines.VirtualMachinesClient VirtualMachineExtensionsClient *virtualmachineextensions.VirtualMachineExtensionsClient VirtualMachineRunCommandsClient *virtualmachineruncommands.VirtualMachineRunCommandsClient @@ -211,6 +213,12 @@ func NewClient(o *common.ClientOptions) (*Client, error) { } o.Configure(sshPublicKeysClient.Client, o.Authorizers.ResourceManager) + standbyVirtualMachinePoolsClient, err := standbyvirtualmachinepools.NewStandbyVirtualMachinePoolsClientWithBaseURI(o.Environment.ResourceManager) + if err != nil { + return nil, fmt.Errorf("building Standby Virtual Machine Pools client: %+v", err) + } + o.Configure(standbyVirtualMachinePoolsClient.Client, o.Authorizers.ResourceManager) + virtualMachinesClient, err := virtualmachines.NewVirtualMachinesClientWithBaseURI(o.Environment.ResourceManager) if err != nil { return nil, fmt.Errorf("building VirtualMachines client: %+v", err) @@ -282,6 +290,7 @@ func NewClient(o *common.ClientOptions) (*Client, error) { SkusClient: skusClient, SSHPublicKeysClient: sshPublicKeysClient, SnapshotsClient: snapshotsClient, + StandbyVirtualMachinePoolsClient: standbyVirtualMachinePoolsClient, VirtualMachinesClient: virtualMachinesClient, VirtualMachineExtensionsClient: virtualMachineExtensionsClient, VirtualMachineRunCommandsClient: virtualMachineRunCommandsClient, diff --git a/internal/services/compute/registration.go b/internal/services/compute/registration.go index 638a52652d07..3679f7806e5d 100644 --- a/internal/services/compute/registration.go +++ b/internal/services/compute/registration.go @@ -96,5 +96,6 @@ func (r Registration) Resources() []sdk.Resource { VirtualMachineRestorePointCollectionResource{}, VirtualMachineRestorePointResource{}, VirtualMachineGalleryApplicationAssignmentResource{}, + VirtualMachineScaleSetStandbyPoolResource{}, } } diff --git a/internal/services/compute/virtual_machine_scale_set_standby_pool_resource.go b/internal/services/compute/virtual_machine_scale_set_standby_pool_resource.go new file mode 100644 index 000000000000..b6d4c83724f0 --- /dev/null +++ b/internal/services/compute/virtual_machine_scale_set_standby_pool_resource.go @@ -0,0 +1,314 @@ +package compute + +import ( + "context" + "fmt" + "regexp" + "time" + + "github.com/hashicorp/go-azure-helpers/lang/pointer" + "github.com/hashicorp/go-azure-helpers/lang/response" + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonschema" + "github.com/hashicorp/go-azure-helpers/resourcemanager/location" + "github.com/hashicorp/go-azure-sdk/resource-manager/compute/2024-07-01/virtualmachinescalesets" + "github.com/hashicorp/go-azure-sdk/resource-manager/standbypool/2024-03-01/standbyvirtualmachinepools" + "github.com/hashicorp/terraform-provider-azurerm/internal/sdk" + "github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk" + "github.com/hashicorp/terraform-provider-azurerm/internal/tf/validation" +) + +type VirtualMachineScaleSetStandbyPoolModel struct { + Name string `tfschema:"name"` + ResourceGroupName string `tfschema:"resource_group_name"` + Location string `tfschema:"location"` + AttachedVirtualMachineScaleSetId string `tfschema:"attached_virtual_machine_scale_set_id"` + ElasticityProfile []VirtualMachineScaleSetStandbyPoolElasticityProfileModel `tfschema:"elasticity_profile"` + VirtualMachineState standbyvirtualmachinepools.VirtualMachineState `tfschema:"virtual_machine_state"` + Tags map[string]string `tfschema:"tags"` +} + +type VirtualMachineScaleSetStandbyPoolElasticityProfileModel struct { + MaxReadyCapacity int64 `tfschema:"max_ready_capacity"` + MinReadyCapacity int64 `tfschema:"min_ready_capacity"` +} + +type VirtualMachineScaleSetStandbyPoolResource struct{} + +var ( + _ sdk.ResourceWithUpdate = VirtualMachineScaleSetStandbyPoolResource{} + _ sdk.ResourceWithCustomizeDiff = VirtualMachineScaleSetStandbyPoolResource{} +) + +func (r VirtualMachineScaleSetStandbyPoolResource) ResourceType() string { + return "azurerm_virtual_machine_scale_set_standby_pool" +} + +func (r VirtualMachineScaleSetStandbyPoolResource) ModelObject() interface{} { + return &VirtualMachineScaleSetStandbyPoolModel{} +} + +func (r VirtualMachineScaleSetStandbyPoolResource) IDValidationFunc() pluginsdk.SchemaValidateFunc { + return standbyvirtualmachinepools.ValidateStandbyVirtualMachinePoolID +} + +func (r VirtualMachineScaleSetStandbyPoolResource) Arguments() map[string]*pluginsdk.Schema { + return map[string]*pluginsdk.Schema{ + "name": { + Type: pluginsdk.TypeString, + Required: true, + ForceNew: true, + ValidateFunc: validation.StringMatch( + regexp.MustCompile("^[a-zA-Z0-9-]{3,24}$"), + "name must be between 3 and 24 characters in length and may contain only letters, numbers and hyphens (-).", + ), + }, + + "resource_group_name": commonschema.ResourceGroupName(), + + "location": commonschema.Location(), + + "attached_virtual_machine_scale_set_id": { + Type: pluginsdk.TypeString, + Required: true, + ValidateFunc: virtualmachinescalesets.ValidateVirtualMachineScaleSetID, + }, + + "elasticity_profile": { + Type: pluginsdk.TypeList, + Required: true, + MaxItems: 1, + Elem: &pluginsdk.Resource{ + Schema: map[string]*pluginsdk.Schema{ + "max_ready_capacity": { + Type: pluginsdk.TypeInt, + Required: true, + ValidateFunc: validation.IntBetween(0, 2000), + }, + + "min_ready_capacity": { + Type: pluginsdk.TypeInt, + Required: true, + ValidateFunc: validation.IntBetween(0, 2000), + }, + }, + }, + }, + + "virtual_machine_state": { + Type: pluginsdk.TypeString, + Required: true, + ValidateFunc: validation.StringInSlice(standbyvirtualmachinepools.PossibleValuesForVirtualMachineState(), false), + }, + + "tags": commonschema.Tags(), + } +} + +func (r VirtualMachineScaleSetStandbyPoolResource) Attributes() map[string]*pluginsdk.Schema { + return map[string]*pluginsdk.Schema{} +} + +func (r VirtualMachineScaleSetStandbyPoolResource) CustomizeDiff() sdk.ResourceFunc { + return sdk.ResourceFunc{ + Timeout: 5 * time.Minute, + Func: func(ctx context.Context, metadata sdk.ResourceMetaData) error { + var config VirtualMachineScaleSetStandbyPoolModel + if err := metadata.DecodeDiff(&config); err != nil { + return fmt.Errorf("decoding: %+v", err) + } + + if len(config.ElasticityProfile) > 0 && config.ElasticityProfile[0].MaxReadyCapacity < config.ElasticityProfile[0].MinReadyCapacity { + return fmt.Errorf("`min_ready_capacity` cannot exceed `max_ready_capacity`") + } + + return nil + }, + } +} + +func (r VirtualMachineScaleSetStandbyPoolResource) Create() sdk.ResourceFunc { + return sdk.ResourceFunc{ + Timeout: 30 * time.Minute, + Func: func(ctx context.Context, metadata sdk.ResourceMetaData) error { + client := metadata.Client.Compute.StandbyVirtualMachinePoolsClient + subscriptionId := metadata.Client.Account.SubscriptionId + + var model VirtualMachineScaleSetStandbyPoolModel + if err := metadata.Decode(&model); err != nil { + return fmt.Errorf("decoding: %+v", err) + } + + id := standbyvirtualmachinepools.NewStandbyVirtualMachinePoolID(subscriptionId, model.ResourceGroupName, model.Name) + existing, err := client.Get(ctx, id) + if err != nil && !response.WasNotFound(existing.HttpResponse) { + return fmt.Errorf("checking for existing %s: %+v", id, err) + } + + if !response.WasNotFound(existing.HttpResponse) { + return metadata.ResourceRequiresImport(r.ResourceType(), id) + } + + properties := &standbyvirtualmachinepools.StandbyVirtualMachinePoolResource{ + Location: location.Normalize(model.Location), + Properties: &standbyvirtualmachinepools.StandbyVirtualMachinePoolResourceProperties{ + AttachedVirtualMachineScaleSetId: pointer.To(model.AttachedVirtualMachineScaleSetId), + ElasticityProfile: expandStandbyVirtualMachinePoolElasticityProfileModel(model.ElasticityProfile), + VirtualMachineState: model.VirtualMachineState, + }, + Tags: &model.Tags, + } + + if err := client.CreateOrUpdateThenPoll(ctx, id, *properties); err != nil { + return fmt.Errorf("creating %s: %+v", id, err) + } + + metadata.SetID(id) + return nil + }, + } +} + +func (r VirtualMachineScaleSetStandbyPoolResource) Update() sdk.ResourceFunc { + return sdk.ResourceFunc{ + Timeout: 30 * time.Minute, + Func: func(ctx context.Context, metadata sdk.ResourceMetaData) error { + client := metadata.Client.Compute.StandbyVirtualMachinePoolsClient + + id, err := standbyvirtualmachinepools.ParseStandbyVirtualMachinePoolID(metadata.ResourceData.Id()) + if err != nil { + return err + } + + var model VirtualMachineScaleSetStandbyPoolModel + if err := metadata.Decode(&model); err != nil { + return fmt.Errorf("decoding: %+v", err) + } + + resp, err := client.Get(ctx, *id) + if err != nil { + return fmt.Errorf("retrieving %s: %+v", *id, err) + } + + properties := resp.Model + if properties == nil { + return fmt.Errorf("retrieving %s: properties was nil", id) + } + + if metadata.ResourceData.HasChange("attached_virtual_machine_scale_set_id") { + properties.Properties.AttachedVirtualMachineScaleSetId = pointer.To(model.AttachedVirtualMachineScaleSetId) + } + + if metadata.ResourceData.HasChange("elasticity_profile") { + properties.Properties.ElasticityProfile = expandStandbyVirtualMachinePoolElasticityProfileModel(model.ElasticityProfile) + } + + if metadata.ResourceData.HasChange("virtual_machine_state") { + properties.Properties.VirtualMachineState = model.VirtualMachineState + } + + if metadata.ResourceData.HasChange("tags") { + properties.Tags = &model.Tags + } + + if err := client.CreateOrUpdateThenPoll(ctx, *id, *properties); err != nil { + return fmt.Errorf("updating %s: %+v", *id, err) + } + + return nil + }, + } +} + +func (r VirtualMachineScaleSetStandbyPoolResource) Read() sdk.ResourceFunc { + return sdk.ResourceFunc{ + Timeout: 5 * time.Minute, + Func: func(ctx context.Context, metadata sdk.ResourceMetaData) error { + client := metadata.Client.Compute.StandbyVirtualMachinePoolsClient + + id, err := standbyvirtualmachinepools.ParseStandbyVirtualMachinePoolID(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) + } + + state := VirtualMachineScaleSetStandbyPoolModel{ + Name: id.StandbyVirtualMachinePoolName, + ResourceGroupName: id.ResourceGroupName, + } + + if model := resp.Model; model != nil { + state.Location = location.Normalize(model.Location) + if properties := model.Properties; properties != nil { + parsedAttachedVirtualMachineScaleSetId, err := virtualmachinescalesets.ParseVirtualMachineScaleSetIDInsensitively(pointer.From(properties.AttachedVirtualMachineScaleSetId)) + if err != nil { + return fmt.Errorf("parsing `attached_virtual_machine_scale_set_id` for %s: %+v", *id, err) + } + + state.AttachedVirtualMachineScaleSetId = parsedAttachedVirtualMachineScaleSetId.ID() + state.ElasticityProfile = flattenStandbyVirtualMachinePoolElasticityProfileModel(properties.ElasticityProfile) + state.VirtualMachineState = properties.VirtualMachineState + } + + state.Tags = pointer.From(model.Tags) + } + + return metadata.Encode(&state) + }, + } +} + +func (r VirtualMachineScaleSetStandbyPoolResource) Delete() sdk.ResourceFunc { + return sdk.ResourceFunc{ + Timeout: 30 * time.Minute, + Func: func(ctx context.Context, metadata sdk.ResourceMetaData) error { + client := metadata.Client.Compute.StandbyVirtualMachinePoolsClient + + id, err := standbyvirtualmachinepools.ParseStandbyVirtualMachinePoolID(metadata.ResourceData.Id()) + if err != nil { + return err + } + + if err := client.DeleteThenPoll(ctx, *id); err != nil { + return fmt.Errorf("deleting %s: %+v", id, err) + } + + return nil + }, + } +} + +func expandStandbyVirtualMachinePoolElasticityProfileModel(inputList []VirtualMachineScaleSetStandbyPoolElasticityProfileModel) *standbyvirtualmachinepools.StandbyVirtualMachinePoolElasticityProfile { + if len(inputList) == 0 { + return nil + } + + input := &inputList[0] + output := standbyvirtualmachinepools.StandbyVirtualMachinePoolElasticityProfile{ + MaxReadyCapacity: input.MaxReadyCapacity, + MinReadyCapacity: pointer.To(input.MinReadyCapacity), + } + + return &output +} + +func flattenStandbyVirtualMachinePoolElasticityProfileModel(input *standbyvirtualmachinepools.StandbyVirtualMachinePoolElasticityProfile) []VirtualMachineScaleSetStandbyPoolElasticityProfileModel { + outputList := make([]VirtualMachineScaleSetStandbyPoolElasticityProfileModel, 0) + if input == nil { + return outputList + } + + output := VirtualMachineScaleSetStandbyPoolElasticityProfileModel{ + MaxReadyCapacity: input.MaxReadyCapacity, + MinReadyCapacity: pointer.From(input.MinReadyCapacity), + } + + return append(outputList, output) +} diff --git a/internal/services/compute/virtual_machine_scale_set_standby_pool_resource_test.go b/internal/services/compute/virtual_machine_scale_set_standby_pool_resource_test.go new file mode 100644 index 000000000000..469d5cb2a263 --- /dev/null +++ b/internal/services/compute/virtual_machine_scale_set_standby_pool_resource_test.go @@ -0,0 +1,260 @@ +package compute_test + +import ( + "context" + "fmt" + "regexp" + "testing" + + "github.com/hashicorp/go-azure-helpers/lang/pointer" + "github.com/hashicorp/go-azure-sdk/resource-manager/standbypool/2024-03-01/standbyvirtualmachinepools" + "github.com/hashicorp/terraform-provider-azurerm/internal/acceptance" + "github.com/hashicorp/terraform-provider-azurerm/internal/acceptance/check" + "github.com/hashicorp/terraform-provider-azurerm/internal/clients" + "github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk" +) + +type StandbyPoolStandbyVirtualMachinePoolResource struct{} + +func TestAccStandbyPoolStandbyVirtualMachinePool_basic(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_virtual_machine_scale_set_standby_pool", "test") + r := StandbyPoolStandbyVirtualMachinePoolResource{} + data.ResourceTest(t, r, []acceptance.TestStep{ + { + Config: r.basic(data), + Check: acceptance.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + ), + }, + data.ImportStep(), + }) +} + +func TestAccStandbyPoolStandbyVirtualMachinePool_requiresImport(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_virtual_machine_scale_set_standby_pool", "test") + r := StandbyPoolStandbyVirtualMachinePoolResource{} + data.ResourceTest(t, r, []acceptance.TestStep{ + { + Config: r.basic(data), + Check: acceptance.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + ), + }, + data.RequiresImportErrorStep(r.requiresImport), + }) +} + +func TestAccStandbyPoolStandbyVirtualMachinePool_complete(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_virtual_machine_scale_set_standby_pool", "test") + r := StandbyPoolStandbyVirtualMachinePoolResource{} + data.ResourceTest(t, r, []acceptance.TestStep{ + { + Config: r.complete(data), + Check: acceptance.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + ), + }, + data.ImportStep(), + }) +} + +func TestAccStandbyPoolStandbyVirtualMachinePool_update(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_virtual_machine_scale_set_standby_pool", "test") + r := StandbyPoolStandbyVirtualMachinePoolResource{} + data.ResourceTest(t, r, []acceptance.TestStep{ + { + Config: r.complete(data), + Check: acceptance.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + ), + }, + data.ImportStep(), + { + Config: r.update(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(), + { + Config: r.complete(data), + Check: acceptance.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + ), + }, + data.ImportStep(), + }) +} + +func TestAccStandbyPoolStandbyVirtualMachinePool_minCapacityExceedMaxCapacity(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_virtual_machine_scale_set_standby_pool", "test") + r := StandbyPoolStandbyVirtualMachinePoolResource{} + data.ResourceTest(t, r, []acceptance.TestStep{ + { + Config: r.minCapacityExceedMaxCapacity(data), + ExpectError: regexp.MustCompile("`min_ready_capacity` cannot exceed `max_ready_capacity`"), + }, + }) +} + +func (r StandbyPoolStandbyVirtualMachinePoolResource) Exists(ctx context.Context, clients *clients.Client, state *pluginsdk.InstanceState) (*bool, error) { + id, err := standbyvirtualmachinepools.ParseStandbyVirtualMachinePoolID(state.ID) + if err != nil { + return nil, err + } + + resp, err := clients.Compute.StandbyVirtualMachinePoolsClient.Get(ctx, *id) + if err != nil { + return nil, fmt.Errorf("retrieving %s: %+v", *id, err) + } + + return pointer.To(resp.Model != nil), nil +} + +func (r StandbyPoolStandbyVirtualMachinePoolResource) template(data acceptance.TestData) string { + return fmt.Sprintf(` +provider "azurerm" { + features {} +} + +resource "azurerm_resource_group" "test" { + name = "acctest-rg-%[1]d" + location = "%[2]s" +} + +resource "azurerm_orchestrated_virtual_machine_scale_set" "test" { + name = "acctestOVMSS-%[1]d" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name + + platform_fault_domain_count = 1 + + zones = ["1"] +} +`, data.RandomInteger, data.Locations.Primary) +} + +func (r StandbyPoolStandbyVirtualMachinePoolResource) basic(data acceptance.TestData) string { + template := r.template(data) + return fmt.Sprintf(` + %s + +resource "azurerm_virtual_machine_scale_set_standby_pool" "test" { + name = "acctest-%d" + resource_group_name = azurerm_resource_group.test.name + location = "%s" + attached_virtual_machine_scale_set_id = azurerm_orchestrated_virtual_machine_scale_set.test.id + virtual_machine_state = "Running" + + elasticity_profile { + max_ready_capacity = 10 + min_ready_capacity = 5 + } +} +`, template, data.RandomIntOfLength(16), data.Locations.Primary) +} + +func (r StandbyPoolStandbyVirtualMachinePoolResource) requiresImport(data acceptance.TestData) string { + config := r.basic(data) + return fmt.Sprintf(` + %s + +resource "azurerm_virtual_machine_scale_set_standby_pool" "import" { + name = azurerm_virtual_machine_scale_set_standby_pool.test.name + resource_group_name = azurerm_resource_group.test.name + location = "%s" + attached_virtual_machine_scale_set_id = azurerm_virtual_machine_scale_set_standby_pool.test.attached_virtual_machine_scale_set_id + virtual_machine_state = azurerm_virtual_machine_scale_set_standby_pool.test.virtual_machine_state + + elasticity_profile { + max_ready_capacity = 10 + min_ready_capacity = 5 + } +} +`, config, data.Locations.Primary) +} + +func (r StandbyPoolStandbyVirtualMachinePoolResource) complete(data acceptance.TestData) string { + template := r.template(data) + return fmt.Sprintf(` + %s + +resource "azurerm_virtual_machine_scale_set_standby_pool" "test" { + name = "acctest-%d" + resource_group_name = azurerm_resource_group.test.name + location = "%s" + attached_virtual_machine_scale_set_id = azurerm_orchestrated_virtual_machine_scale_set.test.id + virtual_machine_state = "Running" + + elasticity_profile { + max_ready_capacity = 10 + min_ready_capacity = 5 + } + + tags = { + key = "value" + } +} +`, template, data.RandomIntOfLength(16), data.Locations.Primary) +} + +func (r StandbyPoolStandbyVirtualMachinePoolResource) update(data acceptance.TestData) string { + template := r.template(data) + return fmt.Sprintf(` + %s + +resource "azurerm_orchestrated_virtual_machine_scale_set" "update" { + name = "acctestOVMSS-update-%d" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name + + platform_fault_domain_count = 1 + + zones = ["1"] +} + +resource "azurerm_virtual_machine_scale_set_standby_pool" "test" { + name = "acctest-%d" + resource_group_name = azurerm_resource_group.test.name + location = "%s" + attached_virtual_machine_scale_set_id = azurerm_orchestrated_virtual_machine_scale_set.update.id + virtual_machine_state = "Deallocated" + + elasticity_profile { + max_ready_capacity = 12 + min_ready_capacity = 6 + } + + tags = { + key = "updatedValue" + } +} +`, template, data.RandomInteger, data.RandomIntOfLength(16), data.Locations.Primary) +} + +func (r StandbyPoolStandbyVirtualMachinePoolResource) minCapacityExceedMaxCapacity(data acceptance.TestData) string { + template := r.template(data) + return fmt.Sprintf(` + %s + +resource "azurerm_virtual_machine_scale_set_standby_pool" "test" { + name = "acctest-%d" + resource_group_name = azurerm_resource_group.test.name + location = "%s" + attached_virtual_machine_scale_set_id = azurerm_orchestrated_virtual_machine_scale_set.test.id + virtual_machine_state = "Running" + + elasticity_profile { + max_ready_capacity = 5 + min_ready_capacity = 10 + } +} +`, template, data.RandomIntOfLength(16), data.Locations.Primary) +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/standbypool/2024-03-01/standbyvirtualmachinepools/README.md b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/standbypool/2024-03-01/standbyvirtualmachinepools/README.md new file mode 100644 index 000000000000..3a64e7d4e09e --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/standbypool/2024-03-01/standbyvirtualmachinepools/README.md @@ -0,0 +1,121 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/standbypool/2024-03-01/standbyvirtualmachinepools` Documentation + +The `standbyvirtualmachinepools` SDK allows for interaction with Azure Resource Manager `standbypool` (API Version `2024-03-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" +import "github.com/hashicorp/go-azure-sdk/resource-manager/standbypool/2024-03-01/standbyvirtualmachinepools" +``` + + +### Client Initialization + +```go +client := standbyvirtualmachinepools.NewStandbyVirtualMachinePoolsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `StandbyVirtualMachinePoolsClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := standbyvirtualmachinepools.NewStandbyVirtualMachinePoolID("12345678-1234-9876-4563-123456789012", "example-resource-group", "standbyVirtualMachinePoolName") + +payload := standbyvirtualmachinepools.StandbyVirtualMachinePoolResource{ + // ... +} + + +if err := client.CreateOrUpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `StandbyVirtualMachinePoolsClient.Delete` + +```go +ctx := context.TODO() +id := standbyvirtualmachinepools.NewStandbyVirtualMachinePoolID("12345678-1234-9876-4563-123456789012", "example-resource-group", "standbyVirtualMachinePoolName") + +if err := client.DeleteThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `StandbyVirtualMachinePoolsClient.Get` + +```go +ctx := context.TODO() +id := standbyvirtualmachinepools.NewStandbyVirtualMachinePoolID("12345678-1234-9876-4563-123456789012", "example-resource-group", "standbyVirtualMachinePoolName") + +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: `StandbyVirtualMachinePoolsClient.ListByResourceGroup` + +```go +ctx := context.TODO() +id := commonids.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: `StandbyVirtualMachinePoolsClient.ListBySubscription` + +```go +ctx := context.TODO() +id := commonids.NewSubscriptionID("12345678-1234-9876-4563-123456789012") + +// alternatively `client.ListBySubscription(ctx, id)` can be used to do batched pagination +items, err := client.ListBySubscriptionComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `StandbyVirtualMachinePoolsClient.Update` + +```go +ctx := context.TODO() +id := standbyvirtualmachinepools.NewStandbyVirtualMachinePoolID("12345678-1234-9876-4563-123456789012", "example-resource-group", "standbyVirtualMachinePoolName") + +payload := standbyvirtualmachinepools.StandbyVirtualMachinePoolResourceUpdate{ + // ... +} + + +read, err := client.Update(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/standbypool/2024-03-01/standbyvirtualmachinepools/client.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/standbypool/2024-03-01/standbyvirtualmachinepools/client.go new file mode 100644 index 000000000000..5cc450073f3a --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/standbypool/2024-03-01/standbyvirtualmachinepools/client.go @@ -0,0 +1,26 @@ +package standbyvirtualmachinepools + +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type StandbyVirtualMachinePoolsClient struct { + Client *resourcemanager.Client +} + +func NewStandbyVirtualMachinePoolsClientWithBaseURI(sdkApi sdkEnv.Api) (*StandbyVirtualMachinePoolsClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "standbyvirtualmachinepools", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating StandbyVirtualMachinePoolsClient: %+v", err) + } + + return &StandbyVirtualMachinePoolsClient{ + Client: client, + }, nil +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/standbypool/2024-03-01/standbyvirtualmachinepools/constants.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/standbypool/2024-03-01/standbyvirtualmachinepools/constants.go new file mode 100644 index 000000000000..e3010f1886c9 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/standbypool/2024-03-01/standbyvirtualmachinepools/constants.go @@ -0,0 +1,98 @@ +package standbyvirtualmachinepools + +import ( + "encoding/json" + "fmt" + "strings" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ProvisioningState string + +const ( + ProvisioningStateCanceled ProvisioningState = "Canceled" + ProvisioningStateDeleting ProvisioningState = "Deleting" + ProvisioningStateFailed ProvisioningState = "Failed" + ProvisioningStateSucceeded ProvisioningState = "Succeeded" +) + +func PossibleValuesForProvisioningState() []string { + return []string{ + string(ProvisioningStateCanceled), + string(ProvisioningStateDeleting), + string(ProvisioningStateFailed), + string(ProvisioningStateSucceeded), + } +} + +func (s *ProvisioningState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseProvisioningState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseProvisioningState(input string) (*ProvisioningState, error) { + vals := map[string]ProvisioningState{ + "canceled": ProvisioningStateCanceled, + "deleting": ProvisioningStateDeleting, + "failed": ProvisioningStateFailed, + "succeeded": ProvisioningStateSucceeded, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ProvisioningState(input) + return &out, nil +} + +type VirtualMachineState string + +const ( + VirtualMachineStateDeallocated VirtualMachineState = "Deallocated" + VirtualMachineStateRunning VirtualMachineState = "Running" +) + +func PossibleValuesForVirtualMachineState() []string { + return []string{ + string(VirtualMachineStateDeallocated), + string(VirtualMachineStateRunning), + } +} + +func (s *VirtualMachineState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseVirtualMachineState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseVirtualMachineState(input string) (*VirtualMachineState, error) { + vals := map[string]VirtualMachineState{ + "deallocated": VirtualMachineStateDeallocated, + "running": VirtualMachineStateRunning, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := VirtualMachineState(input) + return &out, nil +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/standbypool/2024-03-01/standbyvirtualmachinepools/id_standbyvirtualmachinepool.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/standbypool/2024-03-01/standbyvirtualmachinepools/id_standbyvirtualmachinepool.go new file mode 100644 index 000000000000..21ce39183a9a --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/standbypool/2024-03-01/standbyvirtualmachinepools/id_standbyvirtualmachinepool.go @@ -0,0 +1,130 @@ +package standbyvirtualmachinepools + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&StandbyVirtualMachinePoolId{}) +} + +var _ resourceids.ResourceId = &StandbyVirtualMachinePoolId{} + +// StandbyVirtualMachinePoolId is a struct representing the Resource ID for a Standby Virtual Machine Pool +type StandbyVirtualMachinePoolId struct { + SubscriptionId string + ResourceGroupName string + StandbyVirtualMachinePoolName string +} + +// NewStandbyVirtualMachinePoolID returns a new StandbyVirtualMachinePoolId struct +func NewStandbyVirtualMachinePoolID(subscriptionId string, resourceGroupName string, standbyVirtualMachinePoolName string) StandbyVirtualMachinePoolId { + return StandbyVirtualMachinePoolId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + StandbyVirtualMachinePoolName: standbyVirtualMachinePoolName, + } +} + +// ParseStandbyVirtualMachinePoolID parses 'input' into a StandbyVirtualMachinePoolId +func ParseStandbyVirtualMachinePoolID(input string) (*StandbyVirtualMachinePoolId, error) { + parser := resourceids.NewParserFromResourceIdType(&StandbyVirtualMachinePoolId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := StandbyVirtualMachinePoolId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseStandbyVirtualMachinePoolIDInsensitively parses 'input' case-insensitively into a StandbyVirtualMachinePoolId +// note: this method should only be used for API response data and not user input +func ParseStandbyVirtualMachinePoolIDInsensitively(input string) (*StandbyVirtualMachinePoolId, error) { + parser := resourceids.NewParserFromResourceIdType(&StandbyVirtualMachinePoolId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := StandbyVirtualMachinePoolId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *StandbyVirtualMachinePoolId) 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.StandbyVirtualMachinePoolName, ok = input.Parsed["standbyVirtualMachinePoolName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "standbyVirtualMachinePoolName", input) + } + + return nil +} + +// ValidateStandbyVirtualMachinePoolID checks that 'input' can be parsed as a Standby Virtual Machine Pool ID +func ValidateStandbyVirtualMachinePoolID(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 := ParseStandbyVirtualMachinePoolID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Standby Virtual Machine Pool ID +func (id StandbyVirtualMachinePoolId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.StandbyPool/standbyVirtualMachinePools/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.StandbyVirtualMachinePoolName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Standby Virtual Machine Pool ID +func (id StandbyVirtualMachinePoolId) 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("staticMicrosoftStandbyPool", "Microsoft.StandbyPool", "Microsoft.StandbyPool"), + resourceids.StaticSegment("staticStandbyVirtualMachinePools", "standbyVirtualMachinePools", "standbyVirtualMachinePools"), + resourceids.UserSpecifiedSegment("standbyVirtualMachinePoolName", "standbyVirtualMachinePoolName"), + } +} + +// String returns a human-readable description of this Standby Virtual Machine Pool ID +func (id StandbyVirtualMachinePoolId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Standby Virtual Machine Pool Name: %q", id.StandbyVirtualMachinePoolName), + } + return fmt.Sprintf("Standby Virtual Machine Pool (%s)", strings.Join(components, "\n")) +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/standbypool/2024-03-01/standbyvirtualmachinepools/method_createorupdate.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/standbypool/2024-03-01/standbyvirtualmachinepools/method_createorupdate.go new file mode 100644 index 000000000000..95f8487d7f97 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/standbypool/2024-03-01/standbyvirtualmachinepools/method_createorupdate.go @@ -0,0 +1,75 @@ +package standbyvirtualmachinepools + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CreateOrUpdateOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *StandbyVirtualMachinePoolResource +} + +// CreateOrUpdate ... +func (c StandbyVirtualMachinePoolsClient) CreateOrUpdate(ctx context.Context, id StandbyVirtualMachinePoolId, input StandbyVirtualMachinePoolResource) (result CreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// CreateOrUpdateThenPoll performs CreateOrUpdate then polls until it's completed +func (c StandbyVirtualMachinePoolsClient) CreateOrUpdateThenPoll(ctx context.Context, id StandbyVirtualMachinePoolId, input StandbyVirtualMachinePoolResource) error { + result, err := c.CreateOrUpdate(ctx, id, input) + if err != nil { + return fmt.Errorf("performing CreateOrUpdate: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after CreateOrUpdate: %+v", err) + } + + return nil +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/standbypool/2024-03-01/standbyvirtualmachinepools/method_delete.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/standbypool/2024-03-01/standbyvirtualmachinepools/method_delete.go new file mode 100644 index 000000000000..2166eb6c1d1d --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/standbypool/2024-03-01/standbyvirtualmachinepools/method_delete.go @@ -0,0 +1,70 @@ +package standbyvirtualmachinepools + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeleteOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData +} + +// Delete ... +func (c StandbyVirtualMachinePoolsClient) Delete(ctx context.Context, id StandbyVirtualMachinePoolId) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusNoContent, + }, + HttpMethod: http.MethodDelete, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// DeleteThenPoll performs Delete then polls until it's completed +func (c StandbyVirtualMachinePoolsClient) DeleteThenPoll(ctx context.Context, id StandbyVirtualMachinePoolId) error { + result, err := c.Delete(ctx, id) + if err != nil { + return fmt.Errorf("performing Delete: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after Delete: %+v", err) + } + + return nil +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/standbypool/2024-03-01/standbyvirtualmachinepools/method_get.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/standbypool/2024-03-01/standbyvirtualmachinepools/method_get.go new file mode 100644 index 000000000000..f0c6e16ef014 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/standbypool/2024-03-01/standbyvirtualmachinepools/method_get.go @@ -0,0 +1,53 @@ +package standbyvirtualmachinepools + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *StandbyVirtualMachinePoolResource +} + +// Get ... +func (c StandbyVirtualMachinePoolsClient) Get(ctx context.Context, id StandbyVirtualMachinePoolId) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model StandbyVirtualMachinePoolResource + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/standbypool/2024-03-01/standbyvirtualmachinepools/method_listbyresourcegroup.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/standbypool/2024-03-01/standbyvirtualmachinepools/method_listbyresourcegroup.go new file mode 100644 index 000000000000..18ac9c91c83d --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/standbypool/2024-03-01/standbyvirtualmachinepools/method_listbyresourcegroup.go @@ -0,0 +1,106 @@ +package standbyvirtualmachinepools + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListByResourceGroupOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]StandbyVirtualMachinePoolResource +} + +type ListByResourceGroupCompleteResult struct { + LatestHttpResponse *http.Response + Items []StandbyVirtualMachinePoolResource +} + +type ListByResourceGroupCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListByResourceGroupCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListByResourceGroup ... +func (c StandbyVirtualMachinePoolsClient) ListByResourceGroup(ctx context.Context, id commonids.ResourceGroupId) (result ListByResourceGroupOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &ListByResourceGroupCustomPager{}, + Path: fmt.Sprintf("%s/providers/Microsoft.StandbyPool/standbyVirtualMachinePools", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]StandbyVirtualMachinePoolResource `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByResourceGroupComplete retrieves all the results into a single object +func (c StandbyVirtualMachinePoolsClient) ListByResourceGroupComplete(ctx context.Context, id commonids.ResourceGroupId) (ListByResourceGroupCompleteResult, error) { + return c.ListByResourceGroupCompleteMatchingPredicate(ctx, id, StandbyVirtualMachinePoolResourceOperationPredicate{}) +} + +// ListByResourceGroupCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c StandbyVirtualMachinePoolsClient) ListByResourceGroupCompleteMatchingPredicate(ctx context.Context, id commonids.ResourceGroupId, predicate StandbyVirtualMachinePoolResourceOperationPredicate) (result ListByResourceGroupCompleteResult, err error) { + items := make([]StandbyVirtualMachinePoolResource, 0) + + resp, err := c.ListByResourceGroup(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByResourceGroupCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/standbypool/2024-03-01/standbyvirtualmachinepools/method_listbysubscription.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/standbypool/2024-03-01/standbyvirtualmachinepools/method_listbysubscription.go new file mode 100644 index 000000000000..18859d5e0e2c --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/standbypool/2024-03-01/standbyvirtualmachinepools/method_listbysubscription.go @@ -0,0 +1,106 @@ +package standbyvirtualmachinepools + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListBySubscriptionOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]StandbyVirtualMachinePoolResource +} + +type ListBySubscriptionCompleteResult struct { + LatestHttpResponse *http.Response + Items []StandbyVirtualMachinePoolResource +} + +type ListBySubscriptionCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListBySubscriptionCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListBySubscription ... +func (c StandbyVirtualMachinePoolsClient) ListBySubscription(ctx context.Context, id commonids.SubscriptionId) (result ListBySubscriptionOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &ListBySubscriptionCustomPager{}, + Path: fmt.Sprintf("%s/providers/Microsoft.StandbyPool/standbyVirtualMachinePools", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]StandbyVirtualMachinePoolResource `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListBySubscriptionComplete retrieves all the results into a single object +func (c StandbyVirtualMachinePoolsClient) ListBySubscriptionComplete(ctx context.Context, id commonids.SubscriptionId) (ListBySubscriptionCompleteResult, error) { + return c.ListBySubscriptionCompleteMatchingPredicate(ctx, id, StandbyVirtualMachinePoolResourceOperationPredicate{}) +} + +// ListBySubscriptionCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c StandbyVirtualMachinePoolsClient) ListBySubscriptionCompleteMatchingPredicate(ctx context.Context, id commonids.SubscriptionId, predicate StandbyVirtualMachinePoolResourceOperationPredicate) (result ListBySubscriptionCompleteResult, err error) { + items := make([]StandbyVirtualMachinePoolResource, 0) + + resp, err := c.ListBySubscription(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListBySubscriptionCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/standbypool/2024-03-01/standbyvirtualmachinepools/method_update.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/standbypool/2024-03-01/standbyvirtualmachinepools/method_update.go new file mode 100644 index 000000000000..b4d470798dee --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/standbypool/2024-03-01/standbyvirtualmachinepools/method_update.go @@ -0,0 +1,57 @@ +package standbyvirtualmachinepools + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type UpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *StandbyVirtualMachinePoolResource +} + +// Update ... +func (c StandbyVirtualMachinePoolsClient) Update(ctx context.Context, id StandbyVirtualMachinePoolId, input StandbyVirtualMachinePoolResourceUpdate) (result UpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPatch, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model StandbyVirtualMachinePoolResource + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/standbypool/2024-03-01/standbyvirtualmachinepools/model_standbyvirtualmachinepoolelasticityprofile.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/standbypool/2024-03-01/standbyvirtualmachinepools/model_standbyvirtualmachinepoolelasticityprofile.go new file mode 100644 index 000000000000..9214ec79b5f7 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/standbypool/2024-03-01/standbyvirtualmachinepools/model_standbyvirtualmachinepoolelasticityprofile.go @@ -0,0 +1,9 @@ +package standbyvirtualmachinepools + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type StandbyVirtualMachinePoolElasticityProfile struct { + MaxReadyCapacity int64 `json:"maxReadyCapacity"` + MinReadyCapacity *int64 `json:"minReadyCapacity,omitempty"` +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/standbypool/2024-03-01/standbyvirtualmachinepools/model_standbyvirtualmachinepoolresource.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/standbypool/2024-03-01/standbyvirtualmachinepools/model_standbyvirtualmachinepoolresource.go new file mode 100644 index 000000000000..f7126f48397f --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/standbypool/2024-03-01/standbyvirtualmachinepools/model_standbyvirtualmachinepoolresource.go @@ -0,0 +1,18 @@ +package standbyvirtualmachinepools + +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 StandbyVirtualMachinePoolResource struct { + Id *string `json:"id,omitempty"` + Location string `json:"location"` + Name *string `json:"name,omitempty"` + Properties *StandbyVirtualMachinePoolResourceProperties `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/standbypool/2024-03-01/standbyvirtualmachinepools/model_standbyvirtualmachinepoolresourceproperties.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/standbypool/2024-03-01/standbyvirtualmachinepools/model_standbyvirtualmachinepoolresourceproperties.go new file mode 100644 index 000000000000..4ae4ea48f7e7 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/standbypool/2024-03-01/standbyvirtualmachinepools/model_standbyvirtualmachinepoolresourceproperties.go @@ -0,0 +1,11 @@ +package standbyvirtualmachinepools + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type StandbyVirtualMachinePoolResourceProperties struct { + AttachedVirtualMachineScaleSetId *string `json:"attachedVirtualMachineScaleSetId,omitempty"` + ElasticityProfile *StandbyVirtualMachinePoolElasticityProfile `json:"elasticityProfile,omitempty"` + ProvisioningState *ProvisioningState `json:"provisioningState,omitempty"` + VirtualMachineState VirtualMachineState `json:"virtualMachineState"` +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/standbypool/2024-03-01/standbyvirtualmachinepools/model_standbyvirtualmachinepoolresourceupdate.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/standbypool/2024-03-01/standbyvirtualmachinepools/model_standbyvirtualmachinepoolresourceupdate.go new file mode 100644 index 000000000000..dc5d7c116c9d --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/standbypool/2024-03-01/standbyvirtualmachinepools/model_standbyvirtualmachinepoolresourceupdate.go @@ -0,0 +1,9 @@ +package standbyvirtualmachinepools + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type StandbyVirtualMachinePoolResourceUpdate struct { + Properties *StandbyVirtualMachinePoolResourceUpdateProperties `json:"properties,omitempty"` + Tags *map[string]string `json:"tags,omitempty"` +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/standbypool/2024-03-01/standbyvirtualmachinepools/model_standbyvirtualmachinepoolresourceupdateproperties.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/standbypool/2024-03-01/standbyvirtualmachinepools/model_standbyvirtualmachinepoolresourceupdateproperties.go new file mode 100644 index 000000000000..1f5354918381 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/standbypool/2024-03-01/standbyvirtualmachinepools/model_standbyvirtualmachinepoolresourceupdateproperties.go @@ -0,0 +1,10 @@ +package standbyvirtualmachinepools + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type StandbyVirtualMachinePoolResourceUpdateProperties struct { + AttachedVirtualMachineScaleSetId *string `json:"attachedVirtualMachineScaleSetId,omitempty"` + ElasticityProfile *StandbyVirtualMachinePoolElasticityProfile `json:"elasticityProfile,omitempty"` + VirtualMachineState *VirtualMachineState `json:"virtualMachineState,omitempty"` +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/standbypool/2024-03-01/standbyvirtualmachinepools/predicates.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/standbypool/2024-03-01/standbyvirtualmachinepools/predicates.go new file mode 100644 index 000000000000..3ada540e5735 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/standbypool/2024-03-01/standbyvirtualmachinepools/predicates.go @@ -0,0 +1,32 @@ +package standbyvirtualmachinepools + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type StandbyVirtualMachinePoolResourceOperationPredicate struct { + Id *string + Location *string + Name *string + Type *string +} + +func (p StandbyVirtualMachinePoolResourceOperationPredicate) Matches(input StandbyVirtualMachinePoolResource) 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/standbypool/2024-03-01/standbyvirtualmachinepools/version.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/standbypool/2024-03-01/standbyvirtualmachinepools/version.go new file mode 100644 index 000000000000..9079509eac07 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/standbypool/2024-03-01/standbyvirtualmachinepools/version.go @@ -0,0 +1,10 @@ +package standbyvirtualmachinepools + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2024-03-01" + +func userAgent() string { + return "hashicorp/go-azure-sdk/standbyvirtualmachinepools/2024-03-01" +} diff --git a/vendor/modules.txt b/vendor/modules.txt index e1229bc47de4..ba47191e5f47 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -1087,6 +1087,7 @@ github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01-preview/virtua github.com/hashicorp/go-azure-sdk/resource-manager/sqlvirtualmachine/2023-10-01/availabilitygrouplisteners github.com/hashicorp/go-azure-sdk/resource-manager/sqlvirtualmachine/2023-10-01/sqlvirtualmachinegroups github.com/hashicorp/go-azure-sdk/resource-manager/sqlvirtualmachine/2023-10-01/sqlvirtualmachines +github.com/hashicorp/go-azure-sdk/resource-manager/standbypool/2024-03-01/standbyvirtualmachinepools github.com/hashicorp/go-azure-sdk/resource-manager/storage/2023-05-01 github.com/hashicorp/go-azure-sdk/resource-manager/storage/2023-05-01/accountmigrations github.com/hashicorp/go-azure-sdk/resource-manager/storage/2023-05-01/blobcontainers diff --git a/website/docs/r/virtual_machine_scale_set_standby_pool.html.markdown b/website/docs/r/virtual_machine_scale_set_standby_pool.html.markdown new file mode 100644 index 000000000000..7b354a8379c8 --- /dev/null +++ b/website/docs/r/virtual_machine_scale_set_standby_pool.html.markdown @@ -0,0 +1,97 @@ +--- +subcategory: "Compute" +layout: "azurerm" +page_title: "Azure Resource Manager: azurerm_virtual_machine_scale_set_standby_pool" +description: |- + Manages a Standby Pool for Virtual Machine Scale Sets. +--- + +# azurerm_virtual_machine_scale_set_standby_pool + +Manages a Standby Pool for Virtual Machine Scale Sets. +~> **NOTE :** please follow the prerequisites mentioned in this [article](https://learn.microsoft.com/azure/virtual-machine-scale-sets/standby-pools-create?tabs=portal#prerequisites) before using this resource. + +## Example Usage + +```hcl +resource "azurerm_resource_group" "example" { + name = "example-resources" + location = "West Europe" +} + +resource "azurerm_orchestrated_virtual_machine_scale_set" "example" { + name = "example-ovmss" + location = azurerm_resource_group.example.location + resource_group_name = azurerm_resource_group.example.name + platform_fault_domain_count = 1 + zones = ["1"] +} + +resource "azurerm_virtual_machine_scale_set_standby_pool" "example" { + name = "example-spsvmp" + resource_group_name = azurerm_resource_group.example.name + location = "West Europe" + attached_virtual_machine_scale_set_id = azurerm_orchestrated_virtual_machine_scale_set.example.id + virtual_machine_state = "Running" + + elasticity_profile { + max_ready_capacity = 10 + min_ready_capacity = 5 + } + + tags = { + key = "value" + } +} +``` + +## Arguments Reference + +The following arguments are supported: + +* `name` - (Required) Specifies the name which should be used for this Standby Pool. Changing this forces a new Standby Pool to be created. + +* `resource_group_name` - (Required) Specifies the name of the Resource Group where the Standby Pool should exist. Changing this forces a new Standby Pool to be created. + +* `location` - (Required) Specifies the Azure Region where the Standby Pool should exist. Changing this forces a new Standby Pool to be created. + +* `attached_virtual_machine_scale_set_id` - (Required) Specifies the fully qualified resource ID of a virtual machine scale set the pool is attached to. + +* `elasticity_profile` - (Required) An `elasticity_profile` block as defined below. + +* `virtual_machine_state` - (Required) Specifies the desired state of virtual machines in the pool. Possible values are `Running` and `Deallocated`. + +* `tags` - (Optional) A mapping of tags which should be assigned to the Standby Pool. + +--- + +An `elasticity_profile` block supports the following: + +* `max_ready_capacity` - (Required) Specifies the maximum number of virtual machines in the standby pool. + +* `min_ready_capacity` - (Required) Specifies the desired minimum number of virtual machines in the standby pool. + +~> **NOTE** `min_ready_capacity` cannot exceed `max_ready_capacity`. + +## Attributes Reference + +In addition to the Arguments listed above - the following Attributes are exported: + +* `id` - The ID of the Standby Pool. + +## Timeouts + +The `timeouts` block allows you to specify [timeouts](https://www.terraform.io/docs/configuration/resources.html#timeouts) for certain actions: + +* `create` - (Defaults to 30 minutes) Used when creating the Standby Pool. +* `read` - (Defaults to 5 minutes) Used when retrieving the Standby Pool. +* `update` - (Defaults to 30 minutes) Used when updating the Standby Pool. +* `delete` - (Defaults to 30 minutes) Used when deleting the Standby Pool. + +## Import + +Standby Pool can be imported using the `resource id`, e.g. + +```shell +terraform import azurerm_virtual_machine_scale_set_standby_pool.example /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resourceGroup1/providers/Microsoft.StandbyPool/standbyVirtualMachinePools/standbyVirtualMachinePool1 +```