From 5bedc850928848b4646520f24ba9479178ce3100 Mon Sep 17 00:00:00 2001 From: neil-yechenwei Date: Mon, 28 Nov 2022 11:10:58 +0800 Subject: [PATCH 01/10] New Resource: azurerm_lab_service_schedule --- internal/clients/client.go | 3 + internal/provider/services.go | 2 + internal/services/labservice/client/client.go | 19 + .../lab_service_schedule_resource.go | 356 ++++++++++++++++++ internal/services/labservice/registration.go | 49 +++ .../labservices/2022-08-01/lab/README.md | 140 +++++++ .../labservices/2022-08-01/lab/client.go | 18 + .../labservices/2022-08-01/lab/constants.go | 263 +++++++++++++ .../labservices/2022-08-01/lab/id_lab.go | 124 ++++++ .../lab/method_createorupdate_autorest.go | 79 ++++ .../2022-08-01/lab/method_delete_autorest.go | 78 ++++ .../2022-08-01/lab/method_get_autorest.go | 68 ++++ .../method_listbyresourcegroup_autorest.go | 187 +++++++++ .../lab/method_listbysubscription_autorest.go | 187 +++++++++ .../2022-08-01/lab/method_publish_autorest.go | 78 ++++ .../lab/method_syncgroup_autorest.go | 78 ++++ .../2022-08-01/lab/method_update_autorest.go | 79 ++++ .../lab/model_autoshutdownprofile.go | 13 + .../2022-08-01/lab/model_connectionprofile.go | 11 + .../2022-08-01/lab/model_credentials.go | 9 + .../2022-08-01/lab/model_imagereference.go | 13 + .../labservices/2022-08-01/lab/model_lab.go | 18 + .../2022-08-01/lab/model_labnetworkprofile.go | 10 + .../2022-08-01/lab/model_labproperties.go | 18 + .../2022-08-01/lab/model_labupdate.go | 9 + .../lab/model_labupdateproperties.go | 15 + .../2022-08-01/lab/model_rosterprofile.go | 12 + .../2022-08-01/lab/model_securityprofile.go | 9 + .../labservices/2022-08-01/lab/model_sku.go | 12 + ...el_virtualmachineadditionalcapabilities.go | 8 + .../lab/model_virtualmachineprofile.go | 16 + .../labservices/2022-08-01/lab/predicates.go | 29 ++ .../labservices/2022-08-01/lab/version.go | 12 + .../labservices/2022-08-01/schedule/README.md | 107 ++++++ .../labservices/2022-08-01/schedule/client.go | 18 + .../2022-08-01/schedule/constants.go | 117 ++++++ .../labservices/2022-08-01/schedule/id_lab.go | 124 ++++++ .../2022-08-01/schedule/id_schedule.go | 137 +++++++ .../method_createorupdate_autorest.go | 69 ++++ .../schedule/method_delete_autorest.go | 78 ++++ .../schedule/method_get_autorest.go | 68 ++++ .../schedule/method_listbylab_autorest.go | 186 +++++++++ .../schedule/method_update_autorest.go | 69 ++++ .../schedule/model_recurrencepattern.go | 26 ++ .../2022-08-01/schedule/model_schedule.go | 16 + .../schedule/model_scheduleproperties.go | 40 ++ .../schedule/model_scheduleupdate.go | 8 + .../model_scheduleupdateproperties.go | 42 +++ .../2022-08-01/schedule/predicates.go | 24 ++ .../2022-08-01/schedule/version.go | 12 + vendor/modules.txt | 2 + 51 files changed, 3165 insertions(+) create mode 100644 internal/services/labservice/client/client.go create mode 100644 internal/services/labservice/lab_service_schedule_resource.go create mode 100644 internal/services/labservice/registration.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/labservices/2022-08-01/lab/README.md create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/labservices/2022-08-01/lab/client.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/labservices/2022-08-01/lab/constants.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/labservices/2022-08-01/lab/id_lab.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/labservices/2022-08-01/lab/method_createorupdate_autorest.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/labservices/2022-08-01/lab/method_delete_autorest.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/labservices/2022-08-01/lab/method_get_autorest.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/labservices/2022-08-01/lab/method_listbyresourcegroup_autorest.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/labservices/2022-08-01/lab/method_listbysubscription_autorest.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/labservices/2022-08-01/lab/method_publish_autorest.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/labservices/2022-08-01/lab/method_syncgroup_autorest.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/labservices/2022-08-01/lab/method_update_autorest.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/labservices/2022-08-01/lab/model_autoshutdownprofile.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/labservices/2022-08-01/lab/model_connectionprofile.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/labservices/2022-08-01/lab/model_credentials.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/labservices/2022-08-01/lab/model_imagereference.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/labservices/2022-08-01/lab/model_lab.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/labservices/2022-08-01/lab/model_labnetworkprofile.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/labservices/2022-08-01/lab/model_labproperties.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/labservices/2022-08-01/lab/model_labupdate.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/labservices/2022-08-01/lab/model_labupdateproperties.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/labservices/2022-08-01/lab/model_rosterprofile.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/labservices/2022-08-01/lab/model_securityprofile.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/labservices/2022-08-01/lab/model_sku.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/labservices/2022-08-01/lab/model_virtualmachineadditionalcapabilities.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/labservices/2022-08-01/lab/model_virtualmachineprofile.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/labservices/2022-08-01/lab/predicates.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/labservices/2022-08-01/lab/version.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/labservices/2022-08-01/schedule/README.md create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/labservices/2022-08-01/schedule/client.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/labservices/2022-08-01/schedule/constants.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/labservices/2022-08-01/schedule/id_lab.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/labservices/2022-08-01/schedule/id_schedule.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/labservices/2022-08-01/schedule/method_createorupdate_autorest.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/labservices/2022-08-01/schedule/method_delete_autorest.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/labservices/2022-08-01/schedule/method_get_autorest.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/labservices/2022-08-01/schedule/method_listbylab_autorest.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/labservices/2022-08-01/schedule/method_update_autorest.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/labservices/2022-08-01/schedule/model_recurrencepattern.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/labservices/2022-08-01/schedule/model_schedule.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/labservices/2022-08-01/schedule/model_scheduleproperties.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/labservices/2022-08-01/schedule/model_scheduleupdate.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/labservices/2022-08-01/schedule/model_scheduleupdateproperties.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/labservices/2022-08-01/schedule/predicates.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/labservices/2022-08-01/schedule/version.go diff --git a/internal/clients/client.go b/internal/clients/client.go index ed4c81251ebf..0be83c8b4304 100644 --- a/internal/clients/client.go +++ b/internal/clients/client.go @@ -67,6 +67,7 @@ import ( timeseriesinsights "github.com/hashicorp/terraform-provider-azurerm/internal/services/iottimeseriesinsights/client" keyvault "github.com/hashicorp/terraform-provider-azurerm/internal/services/keyvault/client" kusto "github.com/hashicorp/terraform-provider-azurerm/internal/services/kusto/client" + labservice "github.com/hashicorp/terraform-provider-azurerm/internal/services/labservice/client" legacy "github.com/hashicorp/terraform-provider-azurerm/internal/services/legacy/client" lighthouse "github.com/hashicorp/terraform-provider-azurerm/internal/services/lighthouse/client" loadbalancers "github.com/hashicorp/terraform-provider-azurerm/internal/services/loadbalancer/client" @@ -185,6 +186,7 @@ type Client struct { IoTTimeSeriesInsights *timeseriesinsights.Client KeyVault *keyvault.Client Kusto *kusto.Client + LabService *labservice.Client Legacy *legacy.Client Lighthouse *lighthouse.Client LoadBalancers *loadbalancers.Client @@ -307,6 +309,7 @@ func (client *Client) Build(ctx context.Context, o *common.ClientOptions) error client.IoTTimeSeriesInsights = timeseriesinsights.NewClient(o) client.KeyVault = keyvault.NewClient(o) client.Kusto = kusto.NewClient(o) + client.LabService = labservice.NewClient(o) client.Legacy = legacy.NewClient(o) client.Lighthouse = lighthouse.NewClient(o) client.LogAnalytics = loganalytics.NewClient(o) diff --git a/internal/provider/services.go b/internal/provider/services.go index 3f04cdd0e438..45113dc39121 100644 --- a/internal/provider/services.go +++ b/internal/provider/services.go @@ -57,6 +57,7 @@ import ( "github.com/hashicorp/terraform-provider-azurerm/internal/services/iottimeseriesinsights" "github.com/hashicorp/terraform-provider-azurerm/internal/services/keyvault" "github.com/hashicorp/terraform-provider-azurerm/internal/services/kusto" + "github.com/hashicorp/terraform-provider-azurerm/internal/services/labservice" "github.com/hashicorp/terraform-provider-azurerm/internal/services/legacy" "github.com/hashicorp/terraform-provider-azurerm/internal/services/lighthouse" "github.com/hashicorp/terraform-provider-azurerm/internal/services/loadbalancer" @@ -137,6 +138,7 @@ func SupportedTypedServices() []sdk.TypedServiceRegistration { iothub.Registration{}, iotcentral.Registration{}, keyvault.Registration{}, + labservice.Registration{}, loadbalancer.Registration{}, loganalytics.Registration{}, monitor.Registration{}, diff --git a/internal/services/labservice/client/client.go b/internal/services/labservice/client/client.go new file mode 100644 index 000000000000..d312272818f8 --- /dev/null +++ b/internal/services/labservice/client/client.go @@ -0,0 +1,19 @@ +package client + +import ( + "github.com/hashicorp/go-azure-sdk/resource-manager/labservices/2022-08-01/schedule" + "github.com/hashicorp/terraform-provider-azurerm/internal/common" +) + +type Client struct { + ScheduleClient *schedule.ScheduleClient +} + +func NewClient(o *common.ClientOptions) *Client { + ScheduleClient := schedule.NewScheduleClientWithBaseURI(o.ResourceManagerEndpoint) + o.ConfigureClient(&ScheduleClient.Client, o.ResourceManagerAuthorizer) + + return &Client{ + ScheduleClient: &ScheduleClient, + } +} diff --git a/internal/services/labservice/lab_service_schedule_resource.go b/internal/services/labservice/lab_service_schedule_resource.go new file mode 100644 index 000000000000..4963698d4157 --- /dev/null +++ b/internal/services/labservice/lab_service_schedule_resource.go @@ -0,0 +1,356 @@ +package labservice + +import ( + "context" + "fmt" + "time" + + "github.com/hashicorp/go-azure-helpers/lang/response" + "github.com/hashicorp/go-azure-sdk/resource-manager/labservices/2022-08-01/lab" + "github.com/hashicorp/go-azure-sdk/resource-manager/labservices/2022-08-01/schedule" + "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 LabServiceScheduleModel struct { + Name string `tfschema:"name"` + LabId string `tfschema:"lab_id"` + Notes string `tfschema:"notes"` + RecurrencePattern []RecurrencePattern `tfschema:"recurrence_pattern"` + StartAt string `tfschema:"start_at"` + StopAt string `tfschema:"stop_at"` + TimeZoneId string `tfschema:"time_zone_id"` +} + +type RecurrencePattern struct { + ExpirationDate string `tfschema:"expiration_date"` + Frequency schedule.RecurrenceFrequency `tfschema:"frequency"` + Interval int64 `tfschema:"interval"` + WeekDays []schedule.WeekDay `tfschema:"week_days"` +} + +type LabServiceScheduleResource struct{} + +var _ sdk.ResourceWithUpdate = LabServiceScheduleResource{} + +func (r LabServiceScheduleResource) ResourceType() string { + return "azurerm_lab_service_schedule" +} + +func (r LabServiceScheduleResource) ModelObject() interface{} { + return &LabServiceScheduleModel{} +} + +func (r LabServiceScheduleResource) IDValidationFunc() pluginsdk.SchemaValidateFunc { + return schedule.ValidateScheduleID +} + +func (r LabServiceScheduleResource) Arguments() map[string]*pluginsdk.Schema { + return map[string]*pluginsdk.Schema{ + "name": { + Type: pluginsdk.TypeString, + Required: true, + ForceNew: true, + ValidateFunc: validation.StringIsNotEmpty, + }, + + "lab_id": { + Type: pluginsdk.TypeString, + Required: true, + ForceNew: true, + ValidateFunc: lab.ValidateLabID, + }, + + "stop_at": { + Type: pluginsdk.TypeString, + Required: true, + ValidateFunc: validation.StringIsNotEmpty, + }, + + "time_zone_id": { + Type: pluginsdk.TypeString, + Required: true, + ValidateFunc: validation.StringIsNotEmpty, + }, + + "notes": { + Type: pluginsdk.TypeString, + Optional: true, + ValidateFunc: validation.StringIsNotEmpty, + }, + + "recurrence_pattern": { + Type: pluginsdk.TypeList, + Optional: true, + MaxItems: 1, + Elem: &pluginsdk.Resource{ + Schema: map[string]*pluginsdk.Schema{ + "expiration_date": { + Type: pluginsdk.TypeString, + Required: true, + ValidateFunc: validation.StringIsNotEmpty, + }, + + "frequency": { + Type: pluginsdk.TypeString, + Required: true, + ValidateFunc: validation.StringInSlice([]string{ + string(schedule.RecurrenceFrequencyWeekly), + string(schedule.RecurrenceFrequencyDaily), + }, false), + }, + + "interval": { + Type: pluginsdk.TypeInt, + Optional: true, + }, + + "week_days": { + Type: pluginsdk.TypeList, + Optional: true, + }, + }, + }, + }, + + "start_at": { + Type: pluginsdk.TypeString, + Optional: true, + ValidateFunc: validation.StringIsNotEmpty, + }, + } +} + +func (r LabServiceScheduleResource) Attributes() map[string]*pluginsdk.Schema { + return map[string]*pluginsdk.Schema{} +} + +func (r LabServiceScheduleResource) Create() sdk.ResourceFunc { + return sdk.ResourceFunc{ + Timeout: 30 * time.Minute, + Func: func(ctx context.Context, metadata sdk.ResourceMetaData) error { + var model LabServiceScheduleModel + if err := metadata.Decode(&model); err != nil { + return fmt.Errorf("decoding: %+v", err) + } + + client := metadata.Client.LabService.ScheduleClient + labId, err := lab.ParseLabID(model.LabId) + if err != nil { + return err + } + + id := schedule.NewScheduleID(labId.SubscriptionId, labId.ResourceGroupName, labId.LabName, 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 := &schedule.Schedule{ + Properties: schedule.ScheduleProperties{ + StartAt: &model.StartAt, + StopAt: model.StopAt, + TimeZoneId: model.TimeZoneId, + }, + } + + if model.Notes != "" { + properties.Properties.Notes = &model.Notes + } + + recurrencePatternValue, err := expandRecurrencePattern(model.RecurrencePattern) + if err != nil { + return err + } + properties.Properties.RecurrencePattern = recurrencePatternValue + + if _, err := client.CreateOrUpdate(ctx, id, *properties); err != nil { + return fmt.Errorf("creating %s: %+v", id, err) + } + + metadata.SetID(id) + return nil + }, + } +} + +func (r LabServiceScheduleResource) Update() sdk.ResourceFunc { + return sdk.ResourceFunc{ + Timeout: 30 * time.Minute, + Func: func(ctx context.Context, metadata sdk.ResourceMetaData) error { + client := metadata.Client.LabService.ScheduleClient + + id, err := schedule.ParseScheduleID(metadata.ResourceData.Id()) + if err != nil { + return err + } + + var model LabServiceScheduleModel + 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("notes") { + if model.Notes != "" { + properties.Properties.Notes = &model.Notes + } else { + properties.Properties.Notes = nil + } + } + + if metadata.ResourceData.HasChange("recurrence_pattern") { + recurrencePatternValue, err := expandRecurrencePattern(model.RecurrencePattern) + if err != nil { + return err + } + properties.Properties.RecurrencePattern = recurrencePatternValue + } + + if metadata.ResourceData.HasChange("start_at") { + properties.Properties.StartAt = &model.StartAt + } + + if metadata.ResourceData.HasChange("stop_at") { + properties.Properties.StopAt = model.StopAt + } + + if metadata.ResourceData.HasChange("time_zone_id") { + properties.Properties.TimeZoneId = model.TimeZoneId + } + + properties.SystemData = nil + + if _, err := client.CreateOrUpdate(ctx, *id, *properties); err != nil { + return fmt.Errorf("updating %s: %+v", *id, err) + } + + return nil + }, + } +} + +func (r LabServiceScheduleResource) Read() sdk.ResourceFunc { + return sdk.ResourceFunc{ + Timeout: 5 * time.Minute, + Func: func(ctx context.Context, metadata sdk.ResourceMetaData) error { + client := metadata.Client.LabService.ScheduleClient + + id, err := schedule.ParseScheduleID(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) + } + + model := resp.Model + if model == nil { + return fmt.Errorf("retrieving %s: model was nil", id) + } + + state := LabServiceScheduleModel{ + Name: id.ScheduleName, + LabId: lab.NewLabID(id.SubscriptionId, id.ResourceGroupName, id.LabName).ID(), + } + + properties := &model.Properties + if properties.Notes != nil { + state.Notes = *properties.Notes + } + + recurrencePatternValue, err := flattenRecurrencePattern(properties.RecurrencePattern) + if err != nil { + return err + } + state.RecurrencePattern = recurrencePatternValue + + if properties.StartAt != nil { + state.StartAt = *properties.StartAt + } + + state.StopAt = properties.StopAt + + state.TimeZoneId = properties.TimeZoneId + + return metadata.Encode(&state) + }, + } +} + +func (r LabServiceScheduleResource) Delete() sdk.ResourceFunc { + return sdk.ResourceFunc{ + Timeout: 30 * time.Minute, + Func: func(ctx context.Context, metadata sdk.ResourceMetaData) error { + client := metadata.Client.LabService.ScheduleClient + + id, err := schedule.ParseScheduleID(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 expandRecurrencePattern(input []RecurrencePattern) (*schedule.RecurrencePattern, error) { + if len(input) == 0 { + return nil, nil + } + + recurrencePattern := input[0] + result := schedule.RecurrencePattern{ + ExpirationDate: recurrencePattern.ExpirationDate, + Frequency: recurrencePattern.Frequency, + Interval: &recurrencePattern.Interval, + } + + result.WeekDays = &recurrencePattern.WeekDays + + return &result, nil +} + +func flattenRecurrencePattern(input *schedule.RecurrencePattern) ([]RecurrencePattern, error) { + var recurrencePatterns []RecurrencePattern + if input == nil { + return recurrencePatterns, nil + } + + recurrencePattern := RecurrencePattern{ + ExpirationDate: input.ExpirationDate, + Frequency: input.Frequency, + } + + if input.Interval != nil { + recurrencePattern.Interval = *input.Interval + } + + recurrencePattern.WeekDays = *input.WeekDays + + return append(recurrencePatterns, recurrencePattern), nil +} diff --git a/internal/services/labservice/registration.go b/internal/services/labservice/registration.go new file mode 100644 index 000000000000..cad42833bc5c --- /dev/null +++ b/internal/services/labservice/registration.go @@ -0,0 +1,49 @@ +package labservice + +import ( + "github.com/hashicorp/terraform-provider-azurerm/internal/sdk" + "github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk" +) + +type Registration struct{} + +var ( + _ sdk.TypedServiceRegistration = Registration{} + _ sdk.UntypedServiceRegistrationWithAGitHubLabel = Registration{} +) + +func (r Registration) AssociatedGitHubLabel() string { + return "service/labservice" +} + +func (r Registration) DataSources() []sdk.DataSource { + return []sdk.DataSource{} +} + +func (r Registration) Resources() []sdk.Resource { + return []sdk.Resource{ + LabServiceScheduleResource{}, + } +} + +// Name is the name of this Service +func (r Registration) Name() string { + return "Lab Service" +} + +// WebsiteCategories returns a list of categories which can be used for the sidebar +func (r Registration) WebsiteCategories() []string { + return []string{ + "Lab Service", + } +} + +// SupportedDataSources returns the supported Data Sources supported by this Service +func (r Registration) SupportedDataSources() map[string]*pluginsdk.Resource { + return map[string]*pluginsdk.Resource{} +} + +// SupportedResources returns the supported Resources supported by this Service +func (r Registration) SupportedResources() map[string]*pluginsdk.Resource { + return map[string]*pluginsdk.Resource{} +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/labservices/2022-08-01/lab/README.md b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/labservices/2022-08-01/lab/README.md new file mode 100644 index 000000000000..a7fa2a3b2eb3 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/labservices/2022-08-01/lab/README.md @@ -0,0 +1,140 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/labservices/2022-08-01/lab` Documentation + +The `lab` SDK allows for interaction with the Azure Resource Manager Service `labservices` (API Version `2022-08-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/labservices/2022-08-01/lab" +``` + + +### Client Initialization + +```go +client := lab.NewLabClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `LabClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := lab.NewLabID("12345678-1234-9876-4563-123456789012", "example-resource-group", "labValue") + +payload := lab.Lab{ + // ... +} + + +if err := client.CreateOrUpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `LabClient.Delete` + +```go +ctx := context.TODO() +id := lab.NewLabID("12345678-1234-9876-4563-123456789012", "example-resource-group", "labValue") + +if err := client.DeleteThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `LabClient.Get` + +```go +ctx := context.TODO() +id := lab.NewLabID("12345678-1234-9876-4563-123456789012", "example-resource-group", "labValue") + +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: `LabClient.ListByResourceGroup` + +```go +ctx := context.TODO() +id := lab.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: `LabClient.ListBySubscription` + +```go +ctx := context.TODO() +id := lab.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: `LabClient.Publish` + +```go +ctx := context.TODO() +id := lab.NewLabID("12345678-1234-9876-4563-123456789012", "example-resource-group", "labValue") + +if err := client.PublishThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `LabClient.SyncGroup` + +```go +ctx := context.TODO() +id := lab.NewLabID("12345678-1234-9876-4563-123456789012", "example-resource-group", "labValue") + +if err := client.SyncGroupThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `LabClient.Update` + +```go +ctx := context.TODO() +id := lab.NewLabID("12345678-1234-9876-4563-123456789012", "example-resource-group", "labValue") + +payload := lab.LabUpdate{ + // ... +} + + +if err := client.UpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/labservices/2022-08-01/lab/client.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/labservices/2022-08-01/lab/client.go new file mode 100644 index 000000000000..de73d64930fc --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/labservices/2022-08-01/lab/client.go @@ -0,0 +1,18 @@ +package lab + +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 LabClient struct { + Client autorest.Client + baseUri string +} + +func NewLabClientWithBaseURI(endpoint string) LabClient { + return LabClient{ + Client: autorest.NewClientWithUserAgent(userAgent()), + baseUri: endpoint, + } +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/labservices/2022-08-01/lab/constants.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/labservices/2022-08-01/lab/constants.go new file mode 100644 index 000000000000..3bdd7fcd8184 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/labservices/2022-08-01/lab/constants.go @@ -0,0 +1,263 @@ +package lab + +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 ConnectionType string + +const ( + ConnectionTypeNone ConnectionType = "None" + ConnectionTypePrivate ConnectionType = "Private" + ConnectionTypePublic ConnectionType = "Public" +) + +func PossibleValuesForConnectionType() []string { + return []string{ + string(ConnectionTypeNone), + string(ConnectionTypePrivate), + string(ConnectionTypePublic), + } +} + +func parseConnectionType(input string) (*ConnectionType, error) { + vals := map[string]ConnectionType{ + "none": ConnectionTypeNone, + "private": ConnectionTypePrivate, + "public": ConnectionTypePublic, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ConnectionType(input) + return &out, nil +} + +type CreateOption string + +const ( + CreateOptionImage CreateOption = "Image" + CreateOptionTemplateVM CreateOption = "TemplateVM" +) + +func PossibleValuesForCreateOption() []string { + return []string{ + string(CreateOptionImage), + string(CreateOptionTemplateVM), + } +} + +func parseCreateOption(input string) (*CreateOption, error) { + vals := map[string]CreateOption{ + "image": CreateOptionImage, + "templatevm": CreateOptionTemplateVM, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := CreateOption(input) + return &out, nil +} + +type EnableState string + +const ( + EnableStateDisabled EnableState = "Disabled" + EnableStateEnabled EnableState = "Enabled" +) + +func PossibleValuesForEnableState() []string { + return []string{ + string(EnableStateDisabled), + string(EnableStateEnabled), + } +} + +func parseEnableState(input string) (*EnableState, error) { + vals := map[string]EnableState{ + "disabled": EnableStateDisabled, + "enabled": EnableStateEnabled, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := EnableState(input) + return &out, nil +} + +type LabState string + +const ( + LabStateDraft LabState = "Draft" + LabStatePublished LabState = "Published" + LabStatePublishing LabState = "Publishing" + LabStateScaling LabState = "Scaling" + LabStateSyncing LabState = "Syncing" +) + +func PossibleValuesForLabState() []string { + return []string{ + string(LabStateDraft), + string(LabStatePublished), + string(LabStatePublishing), + string(LabStateScaling), + string(LabStateSyncing), + } +} + +func parseLabState(input string) (*LabState, error) { + vals := map[string]LabState{ + "draft": LabStateDraft, + "published": LabStatePublished, + "publishing": LabStatePublishing, + "scaling": LabStateScaling, + "syncing": LabStateSyncing, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := LabState(input) + return &out, nil +} + +type OsType string + +const ( + OsTypeLinux OsType = "Linux" + OsTypeWindows OsType = "Windows" +) + +func PossibleValuesForOsType() []string { + return []string{ + string(OsTypeLinux), + string(OsTypeWindows), + } +} + +func parseOsType(input string) (*OsType, error) { + vals := map[string]OsType{ + "linux": OsTypeLinux, + "windows": OsTypeWindows, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := OsType(input) + return &out, nil +} + +type ProvisioningState string + +const ( + ProvisioningStateCreating ProvisioningState = "Creating" + ProvisioningStateDeleting ProvisioningState = "Deleting" + ProvisioningStateFailed ProvisioningState = "Failed" + ProvisioningStateLocked ProvisioningState = "Locked" + ProvisioningStateSucceeded ProvisioningState = "Succeeded" + ProvisioningStateUpdating ProvisioningState = "Updating" +) + +func PossibleValuesForProvisioningState() []string { + return []string{ + string(ProvisioningStateCreating), + string(ProvisioningStateDeleting), + string(ProvisioningStateFailed), + string(ProvisioningStateLocked), + string(ProvisioningStateSucceeded), + string(ProvisioningStateUpdating), + } +} + +func parseProvisioningState(input string) (*ProvisioningState, error) { + vals := map[string]ProvisioningState{ + "creating": ProvisioningStateCreating, + "deleting": ProvisioningStateDeleting, + "failed": ProvisioningStateFailed, + "locked": ProvisioningStateLocked, + "succeeded": ProvisioningStateSucceeded, + "updating": ProvisioningStateUpdating, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ProvisioningState(input) + return &out, nil +} + +type ShutdownOnIdleMode string + +const ( + ShutdownOnIdleModeLowUsage ShutdownOnIdleMode = "LowUsage" + ShutdownOnIdleModeNone ShutdownOnIdleMode = "None" + ShutdownOnIdleModeUserAbsence ShutdownOnIdleMode = "UserAbsence" +) + +func PossibleValuesForShutdownOnIdleMode() []string { + return []string{ + string(ShutdownOnIdleModeLowUsage), + string(ShutdownOnIdleModeNone), + string(ShutdownOnIdleModeUserAbsence), + } +} + +func parseShutdownOnIdleMode(input string) (*ShutdownOnIdleMode, error) { + vals := map[string]ShutdownOnIdleMode{ + "lowusage": ShutdownOnIdleModeLowUsage, + "none": ShutdownOnIdleModeNone, + "userabsence": ShutdownOnIdleModeUserAbsence, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ShutdownOnIdleMode(input) + return &out, nil +} + +type SkuTier string + +const ( + SkuTierBasic SkuTier = "Basic" + SkuTierFree SkuTier = "Free" + SkuTierPremium SkuTier = "Premium" + SkuTierStandard SkuTier = "Standard" +) + +func PossibleValuesForSkuTier() []string { + return []string{ + string(SkuTierBasic), + string(SkuTierFree), + string(SkuTierPremium), + string(SkuTierStandard), + } +} + +func parseSkuTier(input string) (*SkuTier, error) { + vals := map[string]SkuTier{ + "basic": SkuTierBasic, + "free": SkuTierFree, + "premium": SkuTierPremium, + "standard": SkuTierStandard, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := SkuTier(input) + return &out, nil +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/labservices/2022-08-01/lab/id_lab.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/labservices/2022-08-01/lab/id_lab.go new file mode 100644 index 000000000000..bf7ac5e7a208 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/labservices/2022-08-01/lab/id_lab.go @@ -0,0 +1,124 @@ +package lab + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +var _ resourceids.ResourceId = LabId{} + +// LabId is a struct representing the Resource ID for a Lab +type LabId struct { + SubscriptionId string + ResourceGroupName string + LabName string +} + +// NewLabID returns a new LabId struct +func NewLabID(subscriptionId string, resourceGroupName string, labName string) LabId { + return LabId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + LabName: labName, + } +} + +// ParseLabID parses 'input' into a LabId +func ParseLabID(input string) (*LabId, error) { + parser := resourceids.NewParserFromResourceIdType(LabId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := LabId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.LabName, ok = parsed.Parsed["labName"]; !ok { + return nil, fmt.Errorf("the segment 'labName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ParseLabIDInsensitively parses 'input' case-insensitively into a LabId +// note: this method should only be used for API response data and not user input +func ParseLabIDInsensitively(input string) (*LabId, error) { + parser := resourceids.NewParserFromResourceIdType(LabId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := LabId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.LabName, ok = parsed.Parsed["labName"]; !ok { + return nil, fmt.Errorf("the segment 'labName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ValidateLabID checks that 'input' can be parsed as a Lab ID +func ValidateLabID(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 := ParseLabID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Lab ID +func (id LabId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.LabServices/labs/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.LabName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Lab ID +func (id LabId) 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("staticMicrosoftLabServices", "Microsoft.LabServices", "Microsoft.LabServices"), + resourceids.StaticSegment("staticLabs", "labs", "labs"), + resourceids.UserSpecifiedSegment("labName", "labValue"), + } +} + +// String returns a human-readable description of this Lab ID +func (id LabId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Lab Name: %q", id.LabName), + } + return fmt.Sprintf("Lab (%s)", strings.Join(components, "\n")) +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/labservices/2022-08-01/lab/method_createorupdate_autorest.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/labservices/2022-08-01/lab/method_createorupdate_autorest.go new file mode 100644 index 000000000000..e6759f323633 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/labservices/2022-08-01/lab/method_createorupdate_autorest.go @@ -0,0 +1,79 @@ +package lab + +import ( + "context" + "fmt" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/hashicorp/go-azure-helpers/polling" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CreateOrUpdateOperationResponse struct { + Poller polling.LongRunningPoller + HttpResponse *http.Response +} + +// CreateOrUpdate ... +func (c LabClient) CreateOrUpdate(ctx context.Context, id LabId, input Lab) (result CreateOrUpdateOperationResponse, err error) { + req, err := c.preparerForCreateOrUpdate(ctx, id, input) + if err != nil { + err = autorest.NewErrorWithError(err, "lab.LabClient", "CreateOrUpdate", nil, "Failure preparing request") + return + } + + result, err = c.senderForCreateOrUpdate(ctx, req) + if err != nil { + err = autorest.NewErrorWithError(err, "lab.LabClient", "CreateOrUpdate", result.HttpResponse, "Failure sending request") + return + } + + return +} + +// CreateOrUpdateThenPoll performs CreateOrUpdate then polls until it's completed +func (c LabClient) CreateOrUpdateThenPoll(ctx context.Context, id LabId, input Lab) error { + result, err := c.CreateOrUpdate(ctx, id, input) + if err != nil { + return fmt.Errorf("performing CreateOrUpdate: %+v", err) + } + + if err := result.Poller.PollUntilDone(); err != nil { + return fmt.Errorf("polling after CreateOrUpdate: %+v", err) + } + + return nil +} + +// preparerForCreateOrUpdate prepares the CreateOrUpdate request. +func (c LabClient) preparerForCreateOrUpdate(ctx context.Context, id LabId, input Lab) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPut(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(id.ID()), + autorest.WithJSON(input), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// senderForCreateOrUpdate sends the CreateOrUpdate request. The method will close the +// http.Response Body if it receives an error. +func (c LabClient) 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/labservices/2022-08-01/lab/method_delete_autorest.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/labservices/2022-08-01/lab/method_delete_autorest.go new file mode 100644 index 000000000000..db1a989a241b --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/labservices/2022-08-01/lab/method_delete_autorest.go @@ -0,0 +1,78 @@ +package lab + +import ( + "context" + "fmt" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/hashicorp/go-azure-helpers/polling" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeleteOperationResponse struct { + Poller polling.LongRunningPoller + HttpResponse *http.Response +} + +// Delete ... +func (c LabClient) Delete(ctx context.Context, id LabId) (result DeleteOperationResponse, err error) { + req, err := c.preparerForDelete(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "lab.LabClient", "Delete", nil, "Failure preparing request") + return + } + + result, err = c.senderForDelete(ctx, req) + if err != nil { + err = autorest.NewErrorWithError(err, "lab.LabClient", "Delete", result.HttpResponse, "Failure sending request") + return + } + + return +} + +// DeleteThenPoll performs Delete then polls until it's completed +func (c LabClient) DeleteThenPoll(ctx context.Context, id LabId) error { + result, err := c.Delete(ctx, id) + if err != nil { + return fmt.Errorf("performing Delete: %+v", err) + } + + if err := result.Poller.PollUntilDone(); err != nil { + return fmt.Errorf("polling after Delete: %+v", err) + } + + return nil +} + +// preparerForDelete prepares the Delete request. +func (c LabClient) preparerForDelete(ctx context.Context, id LabId) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsDelete(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(id.ID()), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// senderForDelete sends the Delete request. The method will close the +// http.Response Body if it receives an error. +func (c LabClient) 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/labservices/2022-08-01/lab/method_get_autorest.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/labservices/2022-08-01/lab/method_get_autorest.go new file mode 100644 index 000000000000..fb4755c0f229 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/labservices/2022-08-01/lab/method_get_autorest.go @@ -0,0 +1,68 @@ +package lab + +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 *Lab +} + +// Get ... +func (c LabClient) Get(ctx context.Context, id LabId) (result GetOperationResponse, err error) { + req, err := c.preparerForGet(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "lab.LabClient", "Get", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "lab.LabClient", "Get", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForGet(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "lab.LabClient", "Get", result.HttpResponse, "Failure responding to request") + return + } + + return +} + +// preparerForGet prepares the Get request. +func (c LabClient) preparerForGet(ctx context.Context, id LabId) (*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 LabClient) 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/labservices/2022-08-01/lab/method_listbyresourcegroup_autorest.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/labservices/2022-08-01/lab/method_listbyresourcegroup_autorest.go new file mode 100644 index 000000000000..1317e6fa21e7 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/labservices/2022-08-01/lab/method_listbyresourcegroup_autorest.go @@ -0,0 +1,187 @@ +package lab + +import ( + "context" + "fmt" + "net/http" + "net/url" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListByResourceGroupOperationResponse struct { + HttpResponse *http.Response + Model *[]Lab + + nextLink *string + nextPageFunc func(ctx context.Context, nextLink string) (ListByResourceGroupOperationResponse, error) +} + +type ListByResourceGroupCompleteResult struct { + Items []Lab +} + +func (r ListByResourceGroupOperationResponse) HasMore() bool { + return r.nextLink != nil +} + +func (r ListByResourceGroupOperationResponse) LoadMore(ctx context.Context) (resp ListByResourceGroupOperationResponse, err error) { + if !r.HasMore() { + err = fmt.Errorf("no more pages returned") + return + } + return r.nextPageFunc(ctx, *r.nextLink) +} + +// ListByResourceGroup ... +func (c LabClient) ListByResourceGroup(ctx context.Context, id commonids.ResourceGroupId) (resp ListByResourceGroupOperationResponse, err error) { + req, err := c.preparerForListByResourceGroup(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "lab.LabClient", "ListByResourceGroup", nil, "Failure preparing request") + return + } + + resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "lab.LabClient", "ListByResourceGroup", resp.HttpResponse, "Failure sending request") + return + } + + resp, err = c.responderForListByResourceGroup(resp.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "lab.LabClient", "ListByResourceGroup", resp.HttpResponse, "Failure responding to request") + return + } + return +} + +// preparerForListByResourceGroup prepares the ListByResourceGroup request. +func (c LabClient) preparerForListByResourceGroup(ctx context.Context, id commonids.ResourceGroupId) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(fmt.Sprintf("%s/providers/Microsoft.LabServices/labs", id.ID())), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// preparerForListByResourceGroupWithNextLink prepares the ListByResourceGroup request with the given nextLink token. +func (c LabClient) preparerForListByResourceGroupWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { + uri, err := url.Parse(nextLink) + if err != nil { + return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) + } + queryParameters := map[string]interface{}{} + for k, v := range uri.Query() { + if len(v) == 0 { + continue + } + val := v[0] + val = autorest.Encode("query", val) + queryParameters[k] = val + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(uri.Path), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForListByResourceGroup handles the response to the ListByResourceGroup request. The method always +// closes the http.Response Body. +func (c LabClient) responderForListByResourceGroup(resp *http.Response) (result ListByResourceGroupOperationResponse, err error) { + type page struct { + Values []Lab `json:"value"` + NextLink *string `json:"nextLink"` + } + var respObj page + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&respObj), + autorest.ByClosing()) + result.HttpResponse = resp + result.Model = &respObj.Values + result.nextLink = respObj.NextLink + if respObj.NextLink != nil { + result.nextPageFunc = func(ctx context.Context, nextLink string) (result ListByResourceGroupOperationResponse, err error) { + req, err := c.preparerForListByResourceGroupWithNextLink(ctx, nextLink) + if err != nil { + err = autorest.NewErrorWithError(err, "lab.LabClient", "ListByResourceGroup", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "lab.LabClient", "ListByResourceGroup", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForListByResourceGroup(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "lab.LabClient", "ListByResourceGroup", result.HttpResponse, "Failure responding to request") + return + } + + return + } + } + return +} + +// ListByResourceGroupComplete retrieves all of the results into a single object +func (c LabClient) ListByResourceGroupComplete(ctx context.Context, id commonids.ResourceGroupId) (ListByResourceGroupCompleteResult, error) { + return c.ListByResourceGroupCompleteMatchingPredicate(ctx, id, LabOperationPredicate{}) +} + +// ListByResourceGroupCompleteMatchingPredicate retrieves all of the results and then applied the predicate +func (c LabClient) ListByResourceGroupCompleteMatchingPredicate(ctx context.Context, id commonids.ResourceGroupId, predicate LabOperationPredicate) (resp ListByResourceGroupCompleteResult, err error) { + items := make([]Lab, 0) + + page, err := c.ListByResourceGroup(ctx, id) + if err != nil { + err = fmt.Errorf("loading the initial page: %+v", err) + return + } + if page.Model != nil { + for _, v := range *page.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + for page.HasMore() { + page, err = page.LoadMore(ctx) + if err != nil { + err = fmt.Errorf("loading the next page: %+v", err) + return + } + + if page.Model != nil { + for _, v := range *page.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + } + + out := ListByResourceGroupCompleteResult{ + Items: items, + } + return out, nil +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/labservices/2022-08-01/lab/method_listbysubscription_autorest.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/labservices/2022-08-01/lab/method_listbysubscription_autorest.go new file mode 100644 index 000000000000..038ac6f9d3d3 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/labservices/2022-08-01/lab/method_listbysubscription_autorest.go @@ -0,0 +1,187 @@ +package lab + +import ( + "context" + "fmt" + "net/http" + "net/url" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListBySubscriptionOperationResponse struct { + HttpResponse *http.Response + Model *[]Lab + + nextLink *string + nextPageFunc func(ctx context.Context, nextLink string) (ListBySubscriptionOperationResponse, error) +} + +type ListBySubscriptionCompleteResult struct { + Items []Lab +} + +func (r ListBySubscriptionOperationResponse) HasMore() bool { + return r.nextLink != nil +} + +func (r ListBySubscriptionOperationResponse) LoadMore(ctx context.Context) (resp ListBySubscriptionOperationResponse, err error) { + if !r.HasMore() { + err = fmt.Errorf("no more pages returned") + return + } + return r.nextPageFunc(ctx, *r.nextLink) +} + +// ListBySubscription ... +func (c LabClient) ListBySubscription(ctx context.Context, id commonids.SubscriptionId) (resp ListBySubscriptionOperationResponse, err error) { + req, err := c.preparerForListBySubscription(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "lab.LabClient", "ListBySubscription", nil, "Failure preparing request") + return + } + + resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "lab.LabClient", "ListBySubscription", resp.HttpResponse, "Failure sending request") + return + } + + resp, err = c.responderForListBySubscription(resp.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "lab.LabClient", "ListBySubscription", resp.HttpResponse, "Failure responding to request") + return + } + return +} + +// preparerForListBySubscription prepares the ListBySubscription request. +func (c LabClient) preparerForListBySubscription(ctx context.Context, id commonids.SubscriptionId) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(fmt.Sprintf("%s/providers/Microsoft.LabServices/labs", id.ID())), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// preparerForListBySubscriptionWithNextLink prepares the ListBySubscription request with the given nextLink token. +func (c LabClient) preparerForListBySubscriptionWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { + uri, err := url.Parse(nextLink) + if err != nil { + return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) + } + queryParameters := map[string]interface{}{} + for k, v := range uri.Query() { + if len(v) == 0 { + continue + } + val := v[0] + val = autorest.Encode("query", val) + queryParameters[k] = val + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(uri.Path), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForListBySubscription handles the response to the ListBySubscription request. The method always +// closes the http.Response Body. +func (c LabClient) responderForListBySubscription(resp *http.Response) (result ListBySubscriptionOperationResponse, err error) { + type page struct { + Values []Lab `json:"value"` + NextLink *string `json:"nextLink"` + } + var respObj page + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&respObj), + autorest.ByClosing()) + result.HttpResponse = resp + result.Model = &respObj.Values + result.nextLink = respObj.NextLink + if respObj.NextLink != nil { + result.nextPageFunc = func(ctx context.Context, nextLink string) (result ListBySubscriptionOperationResponse, err error) { + req, err := c.preparerForListBySubscriptionWithNextLink(ctx, nextLink) + if err != nil { + err = autorest.NewErrorWithError(err, "lab.LabClient", "ListBySubscription", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "lab.LabClient", "ListBySubscription", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForListBySubscription(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "lab.LabClient", "ListBySubscription", result.HttpResponse, "Failure responding to request") + return + } + + return + } + } + return +} + +// ListBySubscriptionComplete retrieves all of the results into a single object +func (c LabClient) ListBySubscriptionComplete(ctx context.Context, id commonids.SubscriptionId) (ListBySubscriptionCompleteResult, error) { + return c.ListBySubscriptionCompleteMatchingPredicate(ctx, id, LabOperationPredicate{}) +} + +// ListBySubscriptionCompleteMatchingPredicate retrieves all of the results and then applied the predicate +func (c LabClient) ListBySubscriptionCompleteMatchingPredicate(ctx context.Context, id commonids.SubscriptionId, predicate LabOperationPredicate) (resp ListBySubscriptionCompleteResult, err error) { + items := make([]Lab, 0) + + page, err := c.ListBySubscription(ctx, id) + if err != nil { + err = fmt.Errorf("loading the initial page: %+v", err) + return + } + if page.Model != nil { + for _, v := range *page.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + for page.HasMore() { + page, err = page.LoadMore(ctx) + if err != nil { + err = fmt.Errorf("loading the next page: %+v", err) + return + } + + if page.Model != nil { + for _, v := range *page.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + } + + out := ListBySubscriptionCompleteResult{ + Items: items, + } + return out, nil +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/labservices/2022-08-01/lab/method_publish_autorest.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/labservices/2022-08-01/lab/method_publish_autorest.go new file mode 100644 index 000000000000..5dabf570690d --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/labservices/2022-08-01/lab/method_publish_autorest.go @@ -0,0 +1,78 @@ +package lab + +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 PublishOperationResponse struct { + Poller polling.LongRunningPoller + HttpResponse *http.Response +} + +// Publish ... +func (c LabClient) Publish(ctx context.Context, id LabId) (result PublishOperationResponse, err error) { + req, err := c.preparerForPublish(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "lab.LabClient", "Publish", nil, "Failure preparing request") + return + } + + result, err = c.senderForPublish(ctx, req) + if err != nil { + err = autorest.NewErrorWithError(err, "lab.LabClient", "Publish", result.HttpResponse, "Failure sending request") + return + } + + return +} + +// PublishThenPoll performs Publish then polls until it's completed +func (c LabClient) PublishThenPoll(ctx context.Context, id LabId) error { + result, err := c.Publish(ctx, id) + if err != nil { + return fmt.Errorf("performing Publish: %+v", err) + } + + if err := result.Poller.PollUntilDone(); err != nil { + return fmt.Errorf("polling after Publish: %+v", err) + } + + return nil +} + +// preparerForPublish prepares the Publish request. +func (c LabClient) preparerForPublish(ctx context.Context, id LabId) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPost(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(fmt.Sprintf("%s/publish", id.ID())), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// senderForPublish sends the Publish request. The method will close the +// http.Response Body if it receives an error. +func (c LabClient) senderForPublish(ctx context.Context, req *http.Request) (future PublishOperationResponse, 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/labservices/2022-08-01/lab/method_syncgroup_autorest.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/labservices/2022-08-01/lab/method_syncgroup_autorest.go new file mode 100644 index 000000000000..86d643126ce7 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/labservices/2022-08-01/lab/method_syncgroup_autorest.go @@ -0,0 +1,78 @@ +package lab + +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 SyncGroupOperationResponse struct { + Poller polling.LongRunningPoller + HttpResponse *http.Response +} + +// SyncGroup ... +func (c LabClient) SyncGroup(ctx context.Context, id LabId) (result SyncGroupOperationResponse, err error) { + req, err := c.preparerForSyncGroup(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "lab.LabClient", "SyncGroup", nil, "Failure preparing request") + return + } + + result, err = c.senderForSyncGroup(ctx, req) + if err != nil { + err = autorest.NewErrorWithError(err, "lab.LabClient", "SyncGroup", result.HttpResponse, "Failure sending request") + return + } + + return +} + +// SyncGroupThenPoll performs SyncGroup then polls until it's completed +func (c LabClient) SyncGroupThenPoll(ctx context.Context, id LabId) error { + result, err := c.SyncGroup(ctx, id) + if err != nil { + return fmt.Errorf("performing SyncGroup: %+v", err) + } + + if err := result.Poller.PollUntilDone(); err != nil { + return fmt.Errorf("polling after SyncGroup: %+v", err) + } + + return nil +} + +// preparerForSyncGroup prepares the SyncGroup request. +func (c LabClient) preparerForSyncGroup(ctx context.Context, id LabId) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPost(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(fmt.Sprintf("%s/syncGroup", id.ID())), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// senderForSyncGroup sends the SyncGroup request. The method will close the +// http.Response Body if it receives an error. +func (c LabClient) senderForSyncGroup(ctx context.Context, req *http.Request) (future SyncGroupOperationResponse, 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/labservices/2022-08-01/lab/method_update_autorest.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/labservices/2022-08-01/lab/method_update_autorest.go new file mode 100644 index 000000000000..7b518633f145 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/labservices/2022-08-01/lab/method_update_autorest.go @@ -0,0 +1,79 @@ +package lab + +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 UpdateOperationResponse struct { + Poller polling.LongRunningPoller + HttpResponse *http.Response +} + +// Update ... +func (c LabClient) Update(ctx context.Context, id LabId, input LabUpdate) (result UpdateOperationResponse, err error) { + req, err := c.preparerForUpdate(ctx, id, input) + if err != nil { + err = autorest.NewErrorWithError(err, "lab.LabClient", "Update", nil, "Failure preparing request") + return + } + + result, err = c.senderForUpdate(ctx, req) + if err != nil { + err = autorest.NewErrorWithError(err, "lab.LabClient", "Update", result.HttpResponse, "Failure sending request") + return + } + + return +} + +// UpdateThenPoll performs Update then polls until it's completed +func (c LabClient) UpdateThenPoll(ctx context.Context, id LabId, input LabUpdate) error { + result, err := c.Update(ctx, id, input) + if err != nil { + return fmt.Errorf("performing Update: %+v", err) + } + + if err := result.Poller.PollUntilDone(); err != nil { + return fmt.Errorf("polling after Update: %+v", err) + } + + return nil +} + +// preparerForUpdate prepares the Update request. +func (c LabClient) preparerForUpdate(ctx context.Context, id LabId, input LabUpdate) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPatch(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(id.ID()), + autorest.WithJSON(input), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// senderForUpdate sends the Update request. The method will close the +// http.Response Body if it receives an error. +func (c LabClient) senderForUpdate(ctx context.Context, req *http.Request) (future UpdateOperationResponse, 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/labservices/2022-08-01/lab/model_autoshutdownprofile.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/labservices/2022-08-01/lab/model_autoshutdownprofile.go new file mode 100644 index 000000000000..06638510756e --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/labservices/2022-08-01/lab/model_autoshutdownprofile.go @@ -0,0 +1,13 @@ +package lab + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AutoShutdownProfile struct { + DisconnectDelay *string `json:"disconnectDelay,omitempty"` + IdleDelay *string `json:"idleDelay,omitempty"` + NoConnectDelay *string `json:"noConnectDelay,omitempty"` + ShutdownOnDisconnect *EnableState `json:"shutdownOnDisconnect,omitempty"` + ShutdownOnIdle *ShutdownOnIdleMode `json:"shutdownOnIdle,omitempty"` + ShutdownWhenNotConnected *EnableState `json:"shutdownWhenNotConnected,omitempty"` +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/labservices/2022-08-01/lab/model_connectionprofile.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/labservices/2022-08-01/lab/model_connectionprofile.go new file mode 100644 index 000000000000..68a127f8e34a --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/labservices/2022-08-01/lab/model_connectionprofile.go @@ -0,0 +1,11 @@ +package lab + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ConnectionProfile struct { + ClientRdpAccess *ConnectionType `json:"clientRdpAccess,omitempty"` + ClientSshAccess *ConnectionType `json:"clientSshAccess,omitempty"` + WebRdpAccess *ConnectionType `json:"webRdpAccess,omitempty"` + WebSshAccess *ConnectionType `json:"webSshAccess,omitempty"` +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/labservices/2022-08-01/lab/model_credentials.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/labservices/2022-08-01/lab/model_credentials.go new file mode 100644 index 000000000000..6d23f8a3fba9 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/labservices/2022-08-01/lab/model_credentials.go @@ -0,0 +1,9 @@ +package lab + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type Credentials struct { + Password *string `json:"password,omitempty"` + Username string `json:"username"` +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/labservices/2022-08-01/lab/model_imagereference.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/labservices/2022-08-01/lab/model_imagereference.go new file mode 100644 index 000000000000..b58e73a3347e --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/labservices/2022-08-01/lab/model_imagereference.go @@ -0,0 +1,13 @@ +package lab + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ImageReference struct { + ExactVersion *string `json:"exactVersion,omitempty"` + Id *string `json:"id,omitempty"` + Offer *string `json:"offer,omitempty"` + Publisher *string `json:"publisher,omitempty"` + Sku *string `json:"sku,omitempty"` + Version *string `json:"version,omitempty"` +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/labservices/2022-08-01/lab/model_lab.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/labservices/2022-08-01/lab/model_lab.go new file mode 100644 index 000000000000..47453834f0e7 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/labservices/2022-08-01/lab/model_lab.go @@ -0,0 +1,18 @@ +package lab + +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 Lab struct { + Id *string `json:"id,omitempty"` + Location string `json:"location"` + Name *string `json:"name,omitempty"` + Properties LabProperties `json:"properties"` + 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/labservices/2022-08-01/lab/model_labnetworkprofile.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/labservices/2022-08-01/lab/model_labnetworkprofile.go new file mode 100644 index 000000000000..48ff54d74bfb --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/labservices/2022-08-01/lab/model_labnetworkprofile.go @@ -0,0 +1,10 @@ +package lab + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type LabNetworkProfile struct { + LoadBalancerId *string `json:"loadBalancerId,omitempty"` + PublicIPId *string `json:"publicIpId,omitempty"` + SubnetId *string `json:"subnetId,omitempty"` +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/labservices/2022-08-01/lab/model_labproperties.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/labservices/2022-08-01/lab/model_labproperties.go new file mode 100644 index 000000000000..6d31f47b152b --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/labservices/2022-08-01/lab/model_labproperties.go @@ -0,0 +1,18 @@ +package lab + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type LabProperties struct { + AutoShutdownProfile AutoShutdownProfile `json:"autoShutdownProfile"` + ConnectionProfile ConnectionProfile `json:"connectionProfile"` + Description *string `json:"description,omitempty"` + LabPlanId *string `json:"labPlanId,omitempty"` + NetworkProfile *LabNetworkProfile `json:"networkProfile,omitempty"` + ProvisioningState *ProvisioningState `json:"provisioningState,omitempty"` + RosterProfile *RosterProfile `json:"rosterProfile,omitempty"` + SecurityProfile SecurityProfile `json:"securityProfile"` + State *LabState `json:"state,omitempty"` + Title *string `json:"title,omitempty"` + VirtualMachineProfile VirtualMachineProfile `json:"virtualMachineProfile"` +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/labservices/2022-08-01/lab/model_labupdate.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/labservices/2022-08-01/lab/model_labupdate.go new file mode 100644 index 000000000000..dfa99f31c3c2 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/labservices/2022-08-01/lab/model_labupdate.go @@ -0,0 +1,9 @@ +package lab + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type LabUpdate struct { + Properties *LabUpdateProperties `json:"properties,omitempty"` + Tags *[]string `json:"tags,omitempty"` +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/labservices/2022-08-01/lab/model_labupdateproperties.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/labservices/2022-08-01/lab/model_labupdateproperties.go new file mode 100644 index 000000000000..eb79b4be84b3 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/labservices/2022-08-01/lab/model_labupdateproperties.go @@ -0,0 +1,15 @@ +package lab + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type LabUpdateProperties struct { + AutoShutdownProfile *AutoShutdownProfile `json:"autoShutdownProfile,omitempty"` + ConnectionProfile *ConnectionProfile `json:"connectionProfile,omitempty"` + Description *string `json:"description,omitempty"` + LabPlanId *string `json:"labPlanId,omitempty"` + RosterProfile *RosterProfile `json:"rosterProfile,omitempty"` + SecurityProfile *SecurityProfile `json:"securityProfile,omitempty"` + Title *string `json:"title,omitempty"` + VirtualMachineProfile *VirtualMachineProfile `json:"virtualMachineProfile,omitempty"` +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/labservices/2022-08-01/lab/model_rosterprofile.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/labservices/2022-08-01/lab/model_rosterprofile.go new file mode 100644 index 000000000000..b95ceca34af1 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/labservices/2022-08-01/lab/model_rosterprofile.go @@ -0,0 +1,12 @@ +package lab + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RosterProfile struct { + ActiveDirectoryGroupId *string `json:"activeDirectoryGroupId,omitempty"` + LmsInstance *string `json:"lmsInstance,omitempty"` + LtiClientId *string `json:"ltiClientId,omitempty"` + LtiContextId *string `json:"ltiContextId,omitempty"` + LtiRosterEndpoint *string `json:"ltiRosterEndpoint,omitempty"` +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/labservices/2022-08-01/lab/model_securityprofile.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/labservices/2022-08-01/lab/model_securityprofile.go new file mode 100644 index 000000000000..9e0184755744 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/labservices/2022-08-01/lab/model_securityprofile.go @@ -0,0 +1,9 @@ +package lab + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SecurityProfile struct { + OpenAccess *EnableState `json:"openAccess,omitempty"` + RegistrationCode *string `json:"registrationCode,omitempty"` +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/labservices/2022-08-01/lab/model_sku.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/labservices/2022-08-01/lab/model_sku.go new file mode 100644 index 000000000000..abacbe098b4f --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/labservices/2022-08-01/lab/model_sku.go @@ -0,0 +1,12 @@ +package lab + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type Sku struct { + Capacity *int64 `json:"capacity,omitempty"` + Family *string `json:"family,omitempty"` + Name string `json:"name"` + Size *string `json:"size,omitempty"` + Tier *SkuTier `json:"tier,omitempty"` +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/labservices/2022-08-01/lab/model_virtualmachineadditionalcapabilities.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/labservices/2022-08-01/lab/model_virtualmachineadditionalcapabilities.go new file mode 100644 index 000000000000..f0aff54d4319 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/labservices/2022-08-01/lab/model_virtualmachineadditionalcapabilities.go @@ -0,0 +1,8 @@ +package lab + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type VirtualMachineAdditionalCapabilities struct { + InstallGpuDrivers *EnableState `json:"installGpuDrivers,omitempty"` +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/labservices/2022-08-01/lab/model_virtualmachineprofile.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/labservices/2022-08-01/lab/model_virtualmachineprofile.go new file mode 100644 index 000000000000..840aece64657 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/labservices/2022-08-01/lab/model_virtualmachineprofile.go @@ -0,0 +1,16 @@ +package lab + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type VirtualMachineProfile struct { + AdditionalCapabilities *VirtualMachineAdditionalCapabilities `json:"additionalCapabilities,omitempty"` + AdminUser Credentials `json:"adminUser"` + CreateOption CreateOption `json:"createOption"` + ImageReference ImageReference `json:"imageReference"` + NonAdminUser *Credentials `json:"nonAdminUser,omitempty"` + OsType *OsType `json:"osType,omitempty"` + Sku Sku `json:"sku"` + UsageQuota string `json:"usageQuota"` + UseSharedPassword *EnableState `json:"useSharedPassword,omitempty"` +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/labservices/2022-08-01/lab/predicates.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/labservices/2022-08-01/lab/predicates.go new file mode 100644 index 000000000000..784f9cc6cfbc --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/labservices/2022-08-01/lab/predicates.go @@ -0,0 +1,29 @@ +package lab + +type LabOperationPredicate struct { + Id *string + Location *string + Name *string + Type *string +} + +func (p LabOperationPredicate) Matches(input Lab) 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/labservices/2022-08-01/lab/version.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/labservices/2022-08-01/lab/version.go new file mode 100644 index 000000000000..7b9e0fb1e82d --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/labservices/2022-08-01/lab/version.go @@ -0,0 +1,12 @@ +package lab + +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 = "2022-08-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/lab/%s", defaultApiVersion) +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/labservices/2022-08-01/schedule/README.md b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/labservices/2022-08-01/schedule/README.md new file mode 100644 index 000000000000..743d95e64113 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/labservices/2022-08-01/schedule/README.md @@ -0,0 +1,107 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/labservices/2022-08-01/schedule` Documentation + +The `schedule` SDK allows for interaction with the Azure Resource Manager Service `labservices` (API Version `2022-08-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/labservices/2022-08-01/schedule" +``` + + +### Client Initialization + +```go +client := schedule.NewScheduleClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `ScheduleClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := schedule.NewScheduleID("12345678-1234-9876-4563-123456789012", "example-resource-group", "labValue", "scheduleValue") + +payload := schedule.Schedule{ + // ... +} + + +read, err := client.CreateOrUpdate(ctx, id, payload) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ScheduleClient.Delete` + +```go +ctx := context.TODO() +id := schedule.NewScheduleID("12345678-1234-9876-4563-123456789012", "example-resource-group", "labValue", "scheduleValue") + +if err := client.DeleteThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `ScheduleClient.Get` + +```go +ctx := context.TODO() +id := schedule.NewScheduleID("12345678-1234-9876-4563-123456789012", "example-resource-group", "labValue", "scheduleValue") + +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: `ScheduleClient.ListByLab` + +```go +ctx := context.TODO() +id := schedule.NewLabID("12345678-1234-9876-4563-123456789012", "example-resource-group", "labValue") + +// alternatively `client.ListByLab(ctx, id)` can be used to do batched pagination +items, err := client.ListByLabComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `ScheduleClient.Update` + +```go +ctx := context.TODO() +id := schedule.NewScheduleID("12345678-1234-9876-4563-123456789012", "example-resource-group", "labValue", "scheduleValue") + +payload := schedule.ScheduleUpdate{ + // ... +} + + +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/labservices/2022-08-01/schedule/client.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/labservices/2022-08-01/schedule/client.go new file mode 100644 index 000000000000..11f1d41c8c54 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/labservices/2022-08-01/schedule/client.go @@ -0,0 +1,18 @@ +package schedule + +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 ScheduleClient struct { + Client autorest.Client + baseUri string +} + +func NewScheduleClientWithBaseURI(endpoint string) ScheduleClient { + return ScheduleClient{ + Client: autorest.NewClientWithUserAgent(userAgent()), + baseUri: endpoint, + } +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/labservices/2022-08-01/schedule/constants.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/labservices/2022-08-01/schedule/constants.go new file mode 100644 index 000000000000..1c6b42124e43 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/labservices/2022-08-01/schedule/constants.go @@ -0,0 +1,117 @@ +package schedule + +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 ProvisioningState string + +const ( + ProvisioningStateCreating ProvisioningState = "Creating" + ProvisioningStateDeleting ProvisioningState = "Deleting" + ProvisioningStateFailed ProvisioningState = "Failed" + ProvisioningStateLocked ProvisioningState = "Locked" + ProvisioningStateSucceeded ProvisioningState = "Succeeded" + ProvisioningStateUpdating ProvisioningState = "Updating" +) + +func PossibleValuesForProvisioningState() []string { + return []string{ + string(ProvisioningStateCreating), + string(ProvisioningStateDeleting), + string(ProvisioningStateFailed), + string(ProvisioningStateLocked), + string(ProvisioningStateSucceeded), + string(ProvisioningStateUpdating), + } +} + +func parseProvisioningState(input string) (*ProvisioningState, error) { + vals := map[string]ProvisioningState{ + "creating": ProvisioningStateCreating, + "deleting": ProvisioningStateDeleting, + "failed": ProvisioningStateFailed, + "locked": ProvisioningStateLocked, + "succeeded": ProvisioningStateSucceeded, + "updating": ProvisioningStateUpdating, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ProvisioningState(input) + return &out, nil +} + +type RecurrenceFrequency string + +const ( + RecurrenceFrequencyDaily RecurrenceFrequency = "Daily" + RecurrenceFrequencyWeekly RecurrenceFrequency = "Weekly" +) + +func PossibleValuesForRecurrenceFrequency() []string { + return []string{ + string(RecurrenceFrequencyDaily), + string(RecurrenceFrequencyWeekly), + } +} + +func parseRecurrenceFrequency(input string) (*RecurrenceFrequency, error) { + vals := map[string]RecurrenceFrequency{ + "daily": RecurrenceFrequencyDaily, + "weekly": RecurrenceFrequencyWeekly, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := RecurrenceFrequency(input) + return &out, nil +} + +type WeekDay string + +const ( + WeekDayFriday WeekDay = "Friday" + WeekDayMonday WeekDay = "Monday" + WeekDaySaturday WeekDay = "Saturday" + WeekDaySunday WeekDay = "Sunday" + WeekDayThursday WeekDay = "Thursday" + WeekDayTuesday WeekDay = "Tuesday" + WeekDayWednesday WeekDay = "Wednesday" +) + +func PossibleValuesForWeekDay() []string { + return []string{ + string(WeekDayFriday), + string(WeekDayMonday), + string(WeekDaySaturday), + string(WeekDaySunday), + string(WeekDayThursday), + string(WeekDayTuesday), + string(WeekDayWednesday), + } +} + +func parseWeekDay(input string) (*WeekDay, error) { + vals := map[string]WeekDay{ + "friday": WeekDayFriday, + "monday": WeekDayMonday, + "saturday": WeekDaySaturday, + "sunday": WeekDaySunday, + "thursday": WeekDayThursday, + "tuesday": WeekDayTuesday, + "wednesday": WeekDayWednesday, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := WeekDay(input) + return &out, nil +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/labservices/2022-08-01/schedule/id_lab.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/labservices/2022-08-01/schedule/id_lab.go new file mode 100644 index 000000000000..14c9394200a5 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/labservices/2022-08-01/schedule/id_lab.go @@ -0,0 +1,124 @@ +package schedule + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +var _ resourceids.ResourceId = LabId{} + +// LabId is a struct representing the Resource ID for a Lab +type LabId struct { + SubscriptionId string + ResourceGroupName string + LabName string +} + +// NewLabID returns a new LabId struct +func NewLabID(subscriptionId string, resourceGroupName string, labName string) LabId { + return LabId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + LabName: labName, + } +} + +// ParseLabID parses 'input' into a LabId +func ParseLabID(input string) (*LabId, error) { + parser := resourceids.NewParserFromResourceIdType(LabId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := LabId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.LabName, ok = parsed.Parsed["labName"]; !ok { + return nil, fmt.Errorf("the segment 'labName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ParseLabIDInsensitively parses 'input' case-insensitively into a LabId +// note: this method should only be used for API response data and not user input +func ParseLabIDInsensitively(input string) (*LabId, error) { + parser := resourceids.NewParserFromResourceIdType(LabId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := LabId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.LabName, ok = parsed.Parsed["labName"]; !ok { + return nil, fmt.Errorf("the segment 'labName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ValidateLabID checks that 'input' can be parsed as a Lab ID +func ValidateLabID(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 := ParseLabID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Lab ID +func (id LabId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.LabServices/labs/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.LabName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Lab ID +func (id LabId) 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("staticMicrosoftLabServices", "Microsoft.LabServices", "Microsoft.LabServices"), + resourceids.StaticSegment("staticLabs", "labs", "labs"), + resourceids.UserSpecifiedSegment("labName", "labValue"), + } +} + +// String returns a human-readable description of this Lab ID +func (id LabId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Lab Name: %q", id.LabName), + } + return fmt.Sprintf("Lab (%s)", strings.Join(components, "\n")) +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/labservices/2022-08-01/schedule/id_schedule.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/labservices/2022-08-01/schedule/id_schedule.go new file mode 100644 index 000000000000..4a1a64f73afa --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/labservices/2022-08-01/schedule/id_schedule.go @@ -0,0 +1,137 @@ +package schedule + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +var _ resourceids.ResourceId = ScheduleId{} + +// ScheduleId is a struct representing the Resource ID for a Schedule +type ScheduleId struct { + SubscriptionId string + ResourceGroupName string + LabName string + ScheduleName string +} + +// NewScheduleID returns a new ScheduleId struct +func NewScheduleID(subscriptionId string, resourceGroupName string, labName string, scheduleName string) ScheduleId { + return ScheduleId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + LabName: labName, + ScheduleName: scheduleName, + } +} + +// ParseScheduleID parses 'input' into a ScheduleId +func ParseScheduleID(input string) (*ScheduleId, error) { + parser := resourceids.NewParserFromResourceIdType(ScheduleId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := ScheduleId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.LabName, ok = parsed.Parsed["labName"]; !ok { + return nil, fmt.Errorf("the segment 'labName' was not found in the resource id %q", input) + } + + if id.ScheduleName, ok = parsed.Parsed["scheduleName"]; !ok { + return nil, fmt.Errorf("the segment 'scheduleName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ParseScheduleIDInsensitively parses 'input' case-insensitively into a ScheduleId +// note: this method should only be used for API response data and not user input +func ParseScheduleIDInsensitively(input string) (*ScheduleId, error) { + parser := resourceids.NewParserFromResourceIdType(ScheduleId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := ScheduleId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.LabName, ok = parsed.Parsed["labName"]; !ok { + return nil, fmt.Errorf("the segment 'labName' was not found in the resource id %q", input) + } + + if id.ScheduleName, ok = parsed.Parsed["scheduleName"]; !ok { + return nil, fmt.Errorf("the segment 'scheduleName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ValidateScheduleID checks that 'input' can be parsed as a Schedule ID +func ValidateScheduleID(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 := ParseScheduleID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Schedule ID +func (id ScheduleId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.LabServices/labs/%s/schedules/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.LabName, id.ScheduleName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Schedule ID +func (id ScheduleId) 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("staticMicrosoftLabServices", "Microsoft.LabServices", "Microsoft.LabServices"), + resourceids.StaticSegment("staticLabs", "labs", "labs"), + resourceids.UserSpecifiedSegment("labName", "labValue"), + resourceids.StaticSegment("staticSchedules", "schedules", "schedules"), + resourceids.UserSpecifiedSegment("scheduleName", "scheduleValue"), + } +} + +// String returns a human-readable description of this Schedule ID +func (id ScheduleId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Lab Name: %q", id.LabName), + fmt.Sprintf("Schedule Name: %q", id.ScheduleName), + } + return fmt.Sprintf("Schedule (%s)", strings.Join(components, "\n")) +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/labservices/2022-08-01/schedule/method_createorupdate_autorest.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/labservices/2022-08-01/schedule/method_createorupdate_autorest.go new file mode 100644 index 000000000000..0c0f70ae5a96 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/labservices/2022-08-01/schedule/method_createorupdate_autorest.go @@ -0,0 +1,69 @@ +package schedule + +import ( + "context" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CreateOrUpdateOperationResponse struct { + HttpResponse *http.Response + Model *Schedule +} + +// CreateOrUpdate ... +func (c ScheduleClient) CreateOrUpdate(ctx context.Context, id ScheduleId, input Schedule) (result CreateOrUpdateOperationResponse, err error) { + req, err := c.preparerForCreateOrUpdate(ctx, id, input) + if err != nil { + err = autorest.NewErrorWithError(err, "schedule.ScheduleClient", "CreateOrUpdate", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "schedule.ScheduleClient", "CreateOrUpdate", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForCreateOrUpdate(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "schedule.ScheduleClient", "CreateOrUpdate", result.HttpResponse, "Failure responding to request") + return + } + + return +} + +// preparerForCreateOrUpdate prepares the CreateOrUpdate request. +func (c ScheduleClient) preparerForCreateOrUpdate(ctx context.Context, id ScheduleId, input Schedule) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPut(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(id.ID()), + autorest.WithJSON(input), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForCreateOrUpdate handles the response to the CreateOrUpdate request. The method always +// closes the http.Response Body. +func (c ScheduleClient) responderForCreateOrUpdate(resp *http.Response) (result CreateOrUpdateOperationResponse, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusCreated, http.StatusOK), + autorest.ByUnmarshallingJSON(&result.Model), + autorest.ByClosing()) + result.HttpResponse = resp + + return +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/labservices/2022-08-01/schedule/method_delete_autorest.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/labservices/2022-08-01/schedule/method_delete_autorest.go new file mode 100644 index 000000000000..3c3904466881 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/labservices/2022-08-01/schedule/method_delete_autorest.go @@ -0,0 +1,78 @@ +package schedule + +import ( + "context" + "fmt" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/hashicorp/go-azure-helpers/polling" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeleteOperationResponse struct { + Poller polling.LongRunningPoller + HttpResponse *http.Response +} + +// Delete ... +func (c ScheduleClient) Delete(ctx context.Context, id ScheduleId) (result DeleteOperationResponse, err error) { + req, err := c.preparerForDelete(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "schedule.ScheduleClient", "Delete", nil, "Failure preparing request") + return + } + + result, err = c.senderForDelete(ctx, req) + if err != nil { + err = autorest.NewErrorWithError(err, "schedule.ScheduleClient", "Delete", result.HttpResponse, "Failure sending request") + return + } + + return +} + +// DeleteThenPoll performs Delete then polls until it's completed +func (c ScheduleClient) DeleteThenPoll(ctx context.Context, id ScheduleId) error { + result, err := c.Delete(ctx, id) + if err != nil { + return fmt.Errorf("performing Delete: %+v", err) + } + + if err := result.Poller.PollUntilDone(); err != nil { + return fmt.Errorf("polling after Delete: %+v", err) + } + + return nil +} + +// preparerForDelete prepares the Delete request. +func (c ScheduleClient) preparerForDelete(ctx context.Context, id ScheduleId) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsDelete(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(id.ID()), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// senderForDelete sends the Delete request. The method will close the +// http.Response Body if it receives an error. +func (c ScheduleClient) 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/labservices/2022-08-01/schedule/method_get_autorest.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/labservices/2022-08-01/schedule/method_get_autorest.go new file mode 100644 index 000000000000..46cd9742cf37 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/labservices/2022-08-01/schedule/method_get_autorest.go @@ -0,0 +1,68 @@ +package schedule + +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 *Schedule +} + +// Get ... +func (c ScheduleClient) Get(ctx context.Context, id ScheduleId) (result GetOperationResponse, err error) { + req, err := c.preparerForGet(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "schedule.ScheduleClient", "Get", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "schedule.ScheduleClient", "Get", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForGet(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "schedule.ScheduleClient", "Get", result.HttpResponse, "Failure responding to request") + return + } + + return +} + +// preparerForGet prepares the Get request. +func (c ScheduleClient) preparerForGet(ctx context.Context, id ScheduleId) (*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 ScheduleClient) 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/labservices/2022-08-01/schedule/method_listbylab_autorest.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/labservices/2022-08-01/schedule/method_listbylab_autorest.go new file mode 100644 index 000000000000..fa3dfe3094bd --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/labservices/2022-08-01/schedule/method_listbylab_autorest.go @@ -0,0 +1,186 @@ +package schedule + +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 ListByLabOperationResponse struct { + HttpResponse *http.Response + Model *[]Schedule + + nextLink *string + nextPageFunc func(ctx context.Context, nextLink string) (ListByLabOperationResponse, error) +} + +type ListByLabCompleteResult struct { + Items []Schedule +} + +func (r ListByLabOperationResponse) HasMore() bool { + return r.nextLink != nil +} + +func (r ListByLabOperationResponse) LoadMore(ctx context.Context) (resp ListByLabOperationResponse, err error) { + if !r.HasMore() { + err = fmt.Errorf("no more pages returned") + return + } + return r.nextPageFunc(ctx, *r.nextLink) +} + +// ListByLab ... +func (c ScheduleClient) ListByLab(ctx context.Context, id LabId) (resp ListByLabOperationResponse, err error) { + req, err := c.preparerForListByLab(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "schedule.ScheduleClient", "ListByLab", nil, "Failure preparing request") + return + } + + resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "schedule.ScheduleClient", "ListByLab", resp.HttpResponse, "Failure sending request") + return + } + + resp, err = c.responderForListByLab(resp.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "schedule.ScheduleClient", "ListByLab", resp.HttpResponse, "Failure responding to request") + return + } + return +} + +// preparerForListByLab prepares the ListByLab request. +func (c ScheduleClient) preparerForListByLab(ctx context.Context, id LabId) (*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/schedules", id.ID())), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// preparerForListByLabWithNextLink prepares the ListByLab request with the given nextLink token. +func (c ScheduleClient) preparerForListByLabWithNextLink(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)) +} + +// responderForListByLab handles the response to the ListByLab request. The method always +// closes the http.Response Body. +func (c ScheduleClient) responderForListByLab(resp *http.Response) (result ListByLabOperationResponse, err error) { + type page struct { + Values []Schedule `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 ListByLabOperationResponse, err error) { + req, err := c.preparerForListByLabWithNextLink(ctx, nextLink) + if err != nil { + err = autorest.NewErrorWithError(err, "schedule.ScheduleClient", "ListByLab", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "schedule.ScheduleClient", "ListByLab", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForListByLab(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "schedule.ScheduleClient", "ListByLab", result.HttpResponse, "Failure responding to request") + return + } + + return + } + } + return +} + +// ListByLabComplete retrieves all of the results into a single object +func (c ScheduleClient) ListByLabComplete(ctx context.Context, id LabId) (ListByLabCompleteResult, error) { + return c.ListByLabCompleteMatchingPredicate(ctx, id, ScheduleOperationPredicate{}) +} + +// ListByLabCompleteMatchingPredicate retrieves all of the results and then applied the predicate +func (c ScheduleClient) ListByLabCompleteMatchingPredicate(ctx context.Context, id LabId, predicate ScheduleOperationPredicate) (resp ListByLabCompleteResult, err error) { + items := make([]Schedule, 0) + + page, err := c.ListByLab(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 := ListByLabCompleteResult{ + Items: items, + } + return out, nil +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/labservices/2022-08-01/schedule/method_update_autorest.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/labservices/2022-08-01/schedule/method_update_autorest.go new file mode 100644 index 000000000000..cb3710f71391 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/labservices/2022-08-01/schedule/method_update_autorest.go @@ -0,0 +1,69 @@ +package schedule + +import ( + "context" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type UpdateOperationResponse struct { + HttpResponse *http.Response + Model *Schedule +} + +// Update ... +func (c ScheduleClient) Update(ctx context.Context, id ScheduleId, input ScheduleUpdate) (result UpdateOperationResponse, err error) { + req, err := c.preparerForUpdate(ctx, id, input) + if err != nil { + err = autorest.NewErrorWithError(err, "schedule.ScheduleClient", "Update", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "schedule.ScheduleClient", "Update", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForUpdate(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "schedule.ScheduleClient", "Update", result.HttpResponse, "Failure responding to request") + return + } + + return +} + +// preparerForUpdate prepares the Update request. +func (c ScheduleClient) preparerForUpdate(ctx context.Context, id ScheduleId, input ScheduleUpdate) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPatch(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(id.ID()), + autorest.WithJSON(input), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForUpdate handles the response to the Update request. The method always +// closes the http.Response Body. +func (c ScheduleClient) responderForUpdate(resp *http.Response) (result UpdateOperationResponse, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result.Model), + autorest.ByClosing()) + result.HttpResponse = resp + + return +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/labservices/2022-08-01/schedule/model_recurrencepattern.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/labservices/2022-08-01/schedule/model_recurrencepattern.go new file mode 100644 index 000000000000..b5f375906fe4 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/labservices/2022-08-01/schedule/model_recurrencepattern.go @@ -0,0 +1,26 @@ +package schedule + +import ( + "time" + + "github.com/hashicorp/go-azure-helpers/lang/dates" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RecurrencePattern struct { + ExpirationDate string `json:"expirationDate"` + Frequency RecurrenceFrequency `json:"frequency"` + Interval *int64 `json:"interval,omitempty"` + WeekDays *[]WeekDay `json:"weekDays,omitempty"` +} + +func (o *RecurrencePattern) GetExpirationDateAsTime() (*time.Time, error) { + return dates.ParseAsFormat(&o.ExpirationDate, "2006-01-02T15:04:05Z07:00") +} + +func (o *RecurrencePattern) SetExpirationDateAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.ExpirationDate = formatted +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/labservices/2022-08-01/schedule/model_schedule.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/labservices/2022-08-01/schedule/model_schedule.go new file mode 100644 index 000000000000..810453634f1d --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/labservices/2022-08-01/schedule/model_schedule.go @@ -0,0 +1,16 @@ +package schedule + +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 Schedule struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties ScheduleProperties `json:"properties"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/labservices/2022-08-01/schedule/model_scheduleproperties.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/labservices/2022-08-01/schedule/model_scheduleproperties.go new file mode 100644 index 000000000000..de698b227bd0 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/labservices/2022-08-01/schedule/model_scheduleproperties.go @@ -0,0 +1,40 @@ +package schedule + +import ( + "time" + + "github.com/hashicorp/go-azure-helpers/lang/dates" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ScheduleProperties struct { + Notes *string `json:"notes,omitempty"` + ProvisioningState *ProvisioningState `json:"provisioningState,omitempty"` + RecurrencePattern *RecurrencePattern `json:"recurrencePattern,omitempty"` + StartAt *string `json:"startAt,omitempty"` + StopAt string `json:"stopAt"` + TimeZoneId string `json:"timeZoneId"` +} + +func (o *ScheduleProperties) GetStartAtAsTime() (*time.Time, error) { + if o.StartAt == nil { + return nil, nil + } + return dates.ParseAsFormat(o.StartAt, "2006-01-02T15:04:05Z07:00") +} + +func (o *ScheduleProperties) SetStartAtAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.StartAt = &formatted +} + +func (o *ScheduleProperties) GetStopAtAsTime() (*time.Time, error) { + return dates.ParseAsFormat(&o.StopAt, "2006-01-02T15:04:05Z07:00") +} + +func (o *ScheduleProperties) SetStopAtAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.StopAt = formatted +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/labservices/2022-08-01/schedule/model_scheduleupdate.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/labservices/2022-08-01/schedule/model_scheduleupdate.go new file mode 100644 index 000000000000..57030b33d881 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/labservices/2022-08-01/schedule/model_scheduleupdate.go @@ -0,0 +1,8 @@ +package schedule + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ScheduleUpdate struct { + Properties *ScheduleUpdateProperties `json:"properties,omitempty"` +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/labservices/2022-08-01/schedule/model_scheduleupdateproperties.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/labservices/2022-08-01/schedule/model_scheduleupdateproperties.go new file mode 100644 index 000000000000..3878a8e4f38b --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/labservices/2022-08-01/schedule/model_scheduleupdateproperties.go @@ -0,0 +1,42 @@ +package schedule + +import ( + "time" + + "github.com/hashicorp/go-azure-helpers/lang/dates" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ScheduleUpdateProperties struct { + Notes *string `json:"notes,omitempty"` + RecurrencePattern *RecurrencePattern `json:"recurrencePattern,omitempty"` + StartAt *string `json:"startAt,omitempty"` + StopAt *string `json:"stopAt,omitempty"` + TimeZoneId *string `json:"timeZoneId,omitempty"` +} + +func (o *ScheduleUpdateProperties) GetStartAtAsTime() (*time.Time, error) { + if o.StartAt == nil { + return nil, nil + } + return dates.ParseAsFormat(o.StartAt, "2006-01-02T15:04:05Z07:00") +} + +func (o *ScheduleUpdateProperties) SetStartAtAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.StartAt = &formatted +} + +func (o *ScheduleUpdateProperties) GetStopAtAsTime() (*time.Time, error) { + if o.StopAt == nil { + return nil, nil + } + return dates.ParseAsFormat(o.StopAt, "2006-01-02T15:04:05Z07:00") +} + +func (o *ScheduleUpdateProperties) SetStopAtAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.StopAt = &formatted +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/labservices/2022-08-01/schedule/predicates.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/labservices/2022-08-01/schedule/predicates.go new file mode 100644 index 000000000000..41f6d3ed25ba --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/labservices/2022-08-01/schedule/predicates.go @@ -0,0 +1,24 @@ +package schedule + +type ScheduleOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p ScheduleOperationPredicate) Matches(input Schedule) bool { + + 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/labservices/2022-08-01/schedule/version.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/labservices/2022-08-01/schedule/version.go new file mode 100644 index 000000000000..2c94464c64c1 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/labservices/2022-08-01/schedule/version.go @@ -0,0 +1,12 @@ +package schedule + +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 = "2022-08-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/schedule/%s", defaultApiVersion) +} diff --git a/vendor/modules.txt b/vendor/modules.txt index eb7c379e2339..b722f07d99a0 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -285,6 +285,8 @@ github.com/hashicorp/go-azure-sdk/resource-manager/insights/2021-05-01-preview/d github.com/hashicorp/go-azure-sdk/resource-manager/insights/2021-08-01/scheduledqueryrules github.com/hashicorp/go-azure-sdk/resource-manager/iotcentral/2021-11-01-preview/apps github.com/hashicorp/go-azure-sdk/resource-manager/kusto/2022-07-07/clusters +github.com/hashicorp/go-azure-sdk/resource-manager/labservices/2022-08-01/lab +github.com/hashicorp/go-azure-sdk/resource-manager/labservices/2022-08-01/schedule github.com/hashicorp/go-azure-sdk/resource-manager/loadtestservice/2021-12-01-preview github.com/hashicorp/go-azure-sdk/resource-manager/loadtestservice/2021-12-01-preview/loadtests github.com/hashicorp/go-azure-sdk/resource-manager/machinelearningservices/2022-05-01/machinelearningcomputes From 660c3db2734f645e8337b2ae02ffe90a5b98578c Mon Sep 17 00:00:00 2001 From: neil-yechenwei Date: Mon, 28 Nov 2022 14:46:32 +0800 Subject: [PATCH 02/10] update code --- .../lab_service_schedule_resource.go | 47 ++-- .../lab_service_schedule_resource_test.go | 201 ++++++++++++++++++ .../labservice/validate/schedule_notes.go | 15 ++ .../validate/schedule_notes_test.go | 43 ++++ .../docs/r/lab_service_schedule.html.markdown | 85 ++++++++ 5 files changed, 376 insertions(+), 15 deletions(-) create mode 100644 internal/services/labservice/lab_service_schedule_resource_test.go create mode 100644 internal/services/labservice/validate/schedule_notes.go create mode 100644 internal/services/labservice/validate/schedule_notes_test.go create mode 100644 website/docs/r/lab_service_schedule.html.markdown diff --git a/internal/services/labservice/lab_service_schedule_resource.go b/internal/services/labservice/lab_service_schedule_resource.go index 4963698d4157..ac77176c584f 100644 --- a/internal/services/labservice/lab_service_schedule_resource.go +++ b/internal/services/labservice/lab_service_schedule_resource.go @@ -8,8 +8,11 @@ import ( "github.com/hashicorp/go-azure-helpers/lang/response" "github.com/hashicorp/go-azure-sdk/resource-manager/labservices/2022-08-01/lab" "github.com/hashicorp/go-azure-sdk/resource-manager/labservices/2022-08-01/schedule" + azValidate "github.com/hashicorp/terraform-provider-azurerm/helpers/validate" "github.com/hashicorp/terraform-provider-azurerm/internal/sdk" + "github.com/hashicorp/terraform-provider-azurerm/internal/services/labservice/validate" "github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk" + "github.com/hashicorp/terraform-provider-azurerm/internal/tf/suppress" "github.com/hashicorp/terraform-provider-azurerm/internal/tf/validation" ) @@ -63,21 +66,22 @@ func (r LabServiceScheduleResource) Arguments() map[string]*pluginsdk.Schema { }, "stop_at": { - Type: pluginsdk.TypeString, - Required: true, - ValidateFunc: validation.StringIsNotEmpty, + Type: pluginsdk.TypeString, + Required: true, + DiffSuppressFunc: suppress.RFC3339MinuteTime, + ValidateFunc: validation.IsRFC3339Time, }, "time_zone_id": { Type: pluginsdk.TypeString, Required: true, - ValidateFunc: validation.StringIsNotEmpty, + ValidateFunc: azValidate.AzureTimeZoneString(), }, "notes": { Type: pluginsdk.TypeString, Optional: true, - ValidateFunc: validation.StringIsNotEmpty, + ValidateFunc: validate.ScheduleNotes, }, "recurrence_pattern": { @@ -87,37 +91,50 @@ func (r LabServiceScheduleResource) Arguments() map[string]*pluginsdk.Schema { Elem: &pluginsdk.Resource{ Schema: map[string]*pluginsdk.Schema{ "expiration_date": { - Type: pluginsdk.TypeString, - Required: true, - ValidateFunc: validation.StringIsNotEmpty, + Type: pluginsdk.TypeString, + Required: true, + DiffSuppressFunc: suppress.RFC3339MinuteTime, + ValidateFunc: validation.IsRFC3339Time, }, "frequency": { Type: pluginsdk.TypeString, - Required: true, + Optional: true, + Default: string(schedule.RecurrenceFrequencyDaily), ValidateFunc: validation.StringInSlice([]string{ - string(schedule.RecurrenceFrequencyWeekly), string(schedule.RecurrenceFrequencyDaily), + string(schedule.RecurrenceFrequencyWeekly), }, false), }, "interval": { - Type: pluginsdk.TypeInt, - Optional: true, + Type: pluginsdk.TypeInt, + Optional: true, + ValidateFunc: validation.IntBetween(1, 365), }, "week_days": { Type: pluginsdk.TypeList, Optional: true, + ValidateFunc: validation.StringInSlice([]string{ + string(schedule.WeekDaySunday), + string(schedule.WeekDayMonday), + string(schedule.WeekDayTuesday), + string(schedule.WeekDayWednesday), + string(schedule.WeekDayThursday), + string(schedule.WeekDayFriday), + string(schedule.WeekDaySaturday), + }, false), }, }, }, }, "start_at": { - Type: pluginsdk.TypeString, - Optional: true, - ValidateFunc: validation.StringIsNotEmpty, + Type: pluginsdk.TypeString, + Optional: true, + DiffSuppressFunc: suppress.RFC3339MinuteTime, + ValidateFunc: validation.IsRFC3339Time, }, } } diff --git a/internal/services/labservice/lab_service_schedule_resource_test.go b/internal/services/labservice/lab_service_schedule_resource_test.go new file mode 100644 index 000000000000..8b8a8d830e11 --- /dev/null +++ b/internal/services/labservice/lab_service_schedule_resource_test.go @@ -0,0 +1,201 @@ +package labservice_test + +import ( + "context" + "fmt" + "testing" + "time" + + "github.com/hashicorp/go-azure-helpers/lang/response" + "github.com/hashicorp/go-azure-sdk/resource-manager/labservices/2022-08-01/schedule" + "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 LabServiceScheduleResource struct{} + +func TestAccLabServiceSchedule_basic(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_lab_service_schedule", "test") + r := LabServiceScheduleResource{} + + data.ResourceTest(t, r, []acceptance.TestStep{ + { + Config: r.basic(data), + Check: acceptance.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + ), + }, + data.ImportStep(), + }) +} + +func TestAccLabServiceSchedule_requiresImport(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_lab_service_schedule", "test") + r := LabServiceScheduleResource{} + + data.ResourceTest(t, r, []acceptance.TestStep{ + { + Config: r.basic(data), + Check: acceptance.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + ), + }, + data.RequiresImportErrorStep(r.requiresImport), + }) +} + +func TestAccLabServiceSchedule_complete(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_lab_service_schedule", "test") + r := LabServiceScheduleResource{} + + startTime := time.Now().Format(time.RFC3339) + stopTime := time.Now().Add(time.Hour * 1).Format(time.RFC3339) + expirationDate := time.Now().Add(time.Hour * 2).Format(time.RFC3339) + + data.ResourceTest(t, r, []acceptance.TestStep{ + { + Config: r.complete(data, startTime, stopTime, expirationDate), + Check: acceptance.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + ), + }, + data.ImportStep(), + }) +} + +func TestAccLabServiceSchedule_update(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_lab_service_schedule", "test") + r := LabServiceScheduleResource{} + + startTime := time.Now().Format(time.RFC3339) + stopTime := time.Now().Add(time.Hour * 1).Format(time.RFC3339) + expirationDate := time.Now().Add(time.Hour * 2).Format(time.RFC3339) + + updatedStartTime := time.Now().Format(time.RFC3339) + updatedStopTime := time.Now().Add(time.Hour * 1).Format(time.RFC3339) + updatedExpirationDate := time.Now().Add(time.Hour * 2).Format(time.RFC3339) + + data.ResourceTest(t, r, []acceptance.TestStep{ + { + Config: r.complete(data, startTime, stopTime, expirationDate), + Check: acceptance.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + ), + }, + data.ImportStep(), + { + Config: r.update(data, updatedStartTime, updatedStopTime, updatedExpirationDate), + Check: acceptance.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + ), + }, + data.ImportStep(), + }) +} + +func (r LabServiceScheduleResource) Exists(ctx context.Context, clients *clients.Client, state *pluginsdk.InstanceState) (*bool, error) { + id, err := schedule.ParseScheduleID(state.ID) + if err != nil { + return nil, err + } + + client := clients.LabService.ScheduleClient + resp, err := client.Get(ctx, *id) + if err != nil { + if response.WasNotFound(resp.HttpResponse) { + return utils.Bool(false), nil + } + return nil, fmt.Errorf("retrieving %s: %+v", id, err) + } + return utils.Bool(resp.Model != nil), nil +} + +func (r LabServiceScheduleResource) template(data acceptance.TestData) string { + return fmt.Sprintf(` +provider "azurerm" { + features {} +} + +resource "azurerm_resource_group" "test" { + name = "acctestRG-lss-%d" + location = "%s" +} + +resource "azurerm_lab_service_lab" "test" { + name = "acctest-lsl-%d" + resource_group_name = azurerm_resource_group.test.name +} +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) +} + +func (r LabServiceScheduleResource) basic(data acceptance.TestData) string { + return fmt.Sprintf(` +%s + +resource "azurerm_lab_service_schedule" "test" { + name = "acctest-lss-%d" + lab_id = azurerm_lab_service_lab.test.id + stop_at = "" + time_zone_id = "America/Los_Angeles" +} +`, r.template(data), data.RandomInteger) +} + +func (r LabServiceScheduleResource) requiresImport(data acceptance.TestData) string { + return fmt.Sprintf(` +%s + +resource "azurerm_lab_service_schedule" "import" { + name = azurerm_lab_service_schedule.test.name + lab_id = azurerm_lab_service_schedule.test.lab_id + stop_at = azurerm_lab_service_schedule.test.stop_at + time_zone_id = azurerm_lab_service_schedule.test.time_zone_id +} +`, r.basic(data)) +} + +func (r LabServiceScheduleResource) complete(data acceptance.TestData, startTime, stopTime, expirationDate string) string { + return fmt.Sprintf(` +%s + +resource "azurerm_lab_service_schedule" "test" { + name = "acctest-lss-%d" + lab_id = azurerm_lab_service_lab.test.id + notes = "Testing" + start_at = "%s" + stop_at = "%s" + time_zone_id = "America/Los_Angeles" + + recurrence_pattern { + expiration_date = "%s" + frequency = "Weekly" + interval = 1 + week_days = ["Friday", "Thursday"] + } +} +`, r.template(data), data.RandomInteger, startTime, stopTime, expirationDate) +} + +func (r LabServiceScheduleResource) update(data acceptance.TestData, startTime, stopTime, expirationDate string) string { + return fmt.Sprintf(` +%s + +resource "azurerm_lab_service_schedule" "test" { + name = "acctest-lss-%d" + lab_id = azurerm_lab_service_lab.test.id + notes = "Testing2" + start_at = "%s" + stop_at = "%s" + time_zone_id = "America/Grenada" + + recurrence_pattern { + expiration_date = "%s" + frequency = "Daily" + interval = 2 + } +} +`, r.template(data), data.RandomInteger, startTime, stopTime, expirationDate) +} diff --git a/internal/services/labservice/validate/schedule_notes.go b/internal/services/labservice/validate/schedule_notes.go new file mode 100644 index 000000000000..22e5407b2d68 --- /dev/null +++ b/internal/services/labservice/validate/schedule_notes.go @@ -0,0 +1,15 @@ +package validate + +import ( + "fmt" + "regexp" +) + +func ScheduleNotes(v interface{}, k string) (warnings []string, errors []error) { + value := v.(string) + if matched := regexp.MustCompile(`^.{1,1000}$`).Match([]byte(value)); !matched { + errors = append(errors, fmt.Errorf("%q may only be up to 1000 characters in length", k)) + } + + return warnings, errors +} diff --git a/internal/services/labservice/validate/schedule_notes_test.go b/internal/services/labservice/validate/schedule_notes_test.go new file mode 100644 index 000000000000..f0a1e8418b35 --- /dev/null +++ b/internal/services/labservice/validate/schedule_notes_test.go @@ -0,0 +1,43 @@ +package validate + +import ( + "strings" + "testing" +) + +func TestValidateLabPlanName(t *testing.T) { + cases := []struct { + Input string + ExpectError bool + }{ + { + Input: "", + ExpectError: true, + }, + { + Input: "hello", + ExpectError: false, + }, + { + Input: strings.Repeat("s", 999), + ExpectError: false, + }, + { + Input: strings.Repeat("s", 1000), + ExpectError: false, + }, + { + Input: strings.Repeat("s", 1001), + ExpectError: true, + }, + } + + for _, tc := range cases { + _, errors := ScheduleNotes(tc.Input, "notes") + + hasError := len(errors) > 0 + if tc.ExpectError && !hasError { + t.Fatalf("Expected the Lab Plan Name to trigger a validation error for '%s'", tc.Input) + } + } +} diff --git a/website/docs/r/lab_service_schedule.html.markdown b/website/docs/r/lab_service_schedule.html.markdown new file mode 100644 index 000000000000..53a39f1ad19c --- /dev/null +++ b/website/docs/r/lab_service_schedule.html.markdown @@ -0,0 +1,85 @@ +--- +subcategory: "Lab Service" +layout: "azurerm" +page_title: "Azure Resource Manager: azurerm_lab_service_schedule" +description: |- + Manages a Lab Service Schedule. +--- + +# azurerm_lab_service_schedule + +Manages a Lab Service Schedule. + +## Example Usage + +```hcl +resource "azurerm_resource_group" "example" { + name = "example-resources" + location = "West Europe" +} + +resource "azurerm_lab_service_lab" "example" { + name = "example-lsl" + resource_group_name = azurerm_resource_group.example.name +} + +resource "azurerm_lab_service_schedule" "example" { + name = "example-lss" + lab_id = azurerm_lab_service_lab.example.id + stop_at = "2022-11-28T00:00:00Z" + time_zone_id = "America/Los_Angeles" +} +``` + +## Arguments Reference + +The following arguments are supported: + +* `name` - (Required) The name which should be used for this Lab Service Schedule. Changing this forces a new resource to be created. + +* `lab_id` - (Required) The resource ID of the Lab Service Schedule. Changing this forces a new resource to be created. + +* `stop_at` - (Required) When Lab User Virtual Machines will be stopped in RFC-3339 format. + +* `time_zone_id` - (Required) The IANA Time Zone ID for the Schedule. + +* `notes` - (Optional) The notes for the Schedule. + +* `recurrence_pattern` - (Optional) A `recurrence_pattern` block as defined below. + +* `start_at` - (Optional) When Lab User Virtual Machines will be started in RFC-3339 format. + +--- + +A `recurrence_pattern` block supports the following: + +* `expiration_date` - (Required) When the recurrence will expire in RFC-3339 format. + +* `frequency` - (Optional) The frequency of the recurrence. Possible values are `Daily` and `Weekly`. Defaults to `Daily`. + +* `interval` - (Optional) The interval to invoke the schedule on. Possible values are between `1` and `365`. + +* `week_days` - (Optional) The interval to invoke the schedule on. Possible values are `Sunday`, `Monday`, `Tuesday`, `Wednesday`, `Thrusday`, `Friday` and `Saturday`. + +## Attributes Reference + +In addition to the Arguments listed above - the following Attributes are exported: + +* `id` - The ID of the Lab Service Schedule. + +## 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 Lab Service Schedule. +* `read` - (Defaults to 5 minutes) Used when retrieving the Lab Service Schedule. +* `update` - (Defaults to 30 minutes) Used when updating the Lab Service Schedule. +* `delete` - (Defaults to 30 minutes) Used when deleting the Lab Service Schedule. + +## Import + +Lab Service Schedules can be imported using the `resource id`, e.g. + +```shell +terraform import azurerm_lab_service_schedule.example /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resourceGroup1/providers/Microsoft.LabServices/labs/lab1/schedules/schedule1 +``` From 6b6fcb03d253a1f4f1810b52a57e0cb10f9d55c1 Mon Sep 17 00:00:00 2001 From: neil-yechenwei Date: Wed, 11 Jan 2023 16:07:27 +0800 Subject: [PATCH 03/10] update code --- .../lab_service_schedule_resource.go | 47 ++++++---------- .../lab_service_schedule_resource_test.go | 56 ++++++++++++++----- .../docs/r/lab_service_schedule.html.markdown | 29 +++++++++- 3 files changed, 87 insertions(+), 45 deletions(-) diff --git a/internal/services/labservice/lab_service_schedule_resource.go b/internal/services/labservice/lab_service_schedule_resource.go index ac77176c584f..20e0a6412410 100644 --- a/internal/services/labservice/lab_service_schedule_resource.go +++ b/internal/services/labservice/lab_service_schedule_resource.go @@ -170,9 +170,9 @@ func (r LabServiceScheduleResource) Create() sdk.ResourceFunc { properties := &schedule.Schedule{ Properties: schedule.ScheduleProperties{ - StartAt: &model.StartAt, - StopAt: model.StopAt, - TimeZoneId: model.TimeZoneId, + StopAt: model.StopAt, + TimeZoneId: model.TimeZoneId, + RecurrencePattern: expandRecurrencePattern(model.RecurrencePattern), }, } @@ -180,11 +180,9 @@ func (r LabServiceScheduleResource) Create() sdk.ResourceFunc { properties.Properties.Notes = &model.Notes } - recurrencePatternValue, err := expandRecurrencePattern(model.RecurrencePattern) - if err != nil { - return err + if model.StartAt != "" { + properties.Properties.StartAt = &model.StartAt } - properties.Properties.RecurrencePattern = recurrencePatternValue if _, err := client.CreateOrUpdate(ctx, id, *properties); err != nil { return fmt.Errorf("creating %s: %+v", id, err) @@ -231,11 +229,7 @@ func (r LabServiceScheduleResource) Update() sdk.ResourceFunc { } if metadata.ResourceData.HasChange("recurrence_pattern") { - recurrencePatternValue, err := expandRecurrencePattern(model.RecurrencePattern) - if err != nil { - return err - } - properties.Properties.RecurrencePattern = recurrencePatternValue + properties.Properties.RecurrencePattern = expandRecurrencePattern(model.RecurrencePattern) } if metadata.ResourceData.HasChange("start_at") { @@ -250,8 +244,6 @@ func (r LabServiceScheduleResource) Update() sdk.ResourceFunc { properties.Properties.TimeZoneId = model.TimeZoneId } - properties.SystemData = nil - if _, err := client.CreateOrUpdate(ctx, *id, *properties); err != nil { return fmt.Errorf("updating %s: %+v", *id, err) } @@ -292,24 +284,19 @@ func (r LabServiceScheduleResource) Read() sdk.ResourceFunc { } properties := &model.Properties + + state.StopAt = properties.StopAt + state.TimeZoneId = properties.TimeZoneId + state.RecurrencePattern = flattenRecurrencePattern(properties.RecurrencePattern) + if properties.Notes != nil { state.Notes = *properties.Notes } - recurrencePatternValue, err := flattenRecurrencePattern(properties.RecurrencePattern) - if err != nil { - return err - } - state.RecurrencePattern = recurrencePatternValue - if properties.StartAt != nil { state.StartAt = *properties.StartAt } - state.StopAt = properties.StopAt - - state.TimeZoneId = properties.TimeZoneId - return metadata.Encode(&state) }, } @@ -335,9 +322,9 @@ func (r LabServiceScheduleResource) Delete() sdk.ResourceFunc { } } -func expandRecurrencePattern(input []RecurrencePattern) (*schedule.RecurrencePattern, error) { +func expandRecurrencePattern(input []RecurrencePattern) *schedule.RecurrencePattern { if len(input) == 0 { - return nil, nil + return nil } recurrencePattern := input[0] @@ -349,13 +336,13 @@ func expandRecurrencePattern(input []RecurrencePattern) (*schedule.RecurrencePat result.WeekDays = &recurrencePattern.WeekDays - return &result, nil + return &result } -func flattenRecurrencePattern(input *schedule.RecurrencePattern) ([]RecurrencePattern, error) { +func flattenRecurrencePattern(input *schedule.RecurrencePattern) []RecurrencePattern { var recurrencePatterns []RecurrencePattern if input == nil { - return recurrencePatterns, nil + return recurrencePatterns } recurrencePattern := RecurrencePattern{ @@ -369,5 +356,5 @@ func flattenRecurrencePattern(input *schedule.RecurrencePattern) ([]RecurrencePa recurrencePattern.WeekDays = *input.WeekDays - return append(recurrencePatterns, recurrencePattern), nil + return append(recurrencePatterns, recurrencePattern) } diff --git a/internal/services/labservice/lab_service_schedule_resource_test.go b/internal/services/labservice/lab_service_schedule_resource_test.go index 8b8a8d830e11..c9de046d56b5 100644 --- a/internal/services/labservice/lab_service_schedule_resource_test.go +++ b/internal/services/labservice/lab_service_schedule_resource_test.go @@ -20,10 +20,11 @@ type LabServiceScheduleResource struct{} func TestAccLabServiceSchedule_basic(t *testing.T) { data := acceptance.BuildTestData(t, "azurerm_lab_service_schedule", "test") r := LabServiceScheduleResource{} + stopTime := time.Now().Add(time.Hour * 1).Format(time.RFC3339) data.ResourceTest(t, r, []acceptance.TestStep{ { - Config: r.basic(data), + Config: r.basic(data, stopTime), Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), ), @@ -35,15 +36,19 @@ func TestAccLabServiceSchedule_basic(t *testing.T) { func TestAccLabServiceSchedule_requiresImport(t *testing.T) { data := acceptance.BuildTestData(t, "azurerm_lab_service_schedule", "test") r := LabServiceScheduleResource{} + stopTime := time.Now().Add(time.Hour * 1).Format(time.RFC3339) data.ResourceTest(t, r, []acceptance.TestStep{ { - Config: r.basic(data), + Config: r.basic(data, stopTime), Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), ), }, - data.RequiresImportErrorStep(r.requiresImport), + { + Config: r.requiresImport(data, stopTime), + ExpectError: acceptance.RequiresImportError(data.ResourceType), + }, }) } @@ -120,31 +125,56 @@ provider "azurerm" { } resource "azurerm_resource_group" "test" { - name = "acctestRG-lss-%d" + name = "acctestRG-labschedule-%d" location = "%s" } resource "azurerm_lab_service_lab" "test" { - name = "acctest-lsl-%d" + name = "acctest-lab-%d" resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location + title = "Test Title" + + security { + open_access_enabled = false + } + + virtual_machine { + admin_user { + username = "testadmin" + password = "Password1234!" + } + + image_reference { + offer = "0001-com-ubuntu-server-focal" + publisher = "canonical" + sku = "20_04-lts" + version = "latest" + } + + sku { + name = "Classic_Fsv2_2_4GB_128_S_SSD" + capacity = 1 + } + } } `, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func (r LabServiceScheduleResource) basic(data acceptance.TestData) string { +func (r LabServiceScheduleResource) basic(data acceptance.TestData, stopTime string) string { return fmt.Sprintf(` %s resource "azurerm_lab_service_schedule" "test" { - name = "acctest-lss-%d" + name = "acctest-labschedule-%d" lab_id = azurerm_lab_service_lab.test.id - stop_at = "" + stop_at = "%s" time_zone_id = "America/Los_Angeles" } -`, r.template(data), data.RandomInteger) +`, r.template(data), data.RandomInteger, stopTime) } -func (r LabServiceScheduleResource) requiresImport(data acceptance.TestData) string { +func (r LabServiceScheduleResource) requiresImport(data acceptance.TestData, stopTime string) string { return fmt.Sprintf(` %s @@ -154,7 +184,7 @@ resource "azurerm_lab_service_schedule" "import" { stop_at = azurerm_lab_service_schedule.test.stop_at time_zone_id = azurerm_lab_service_schedule.test.time_zone_id } -`, r.basic(data)) +`, r.basic(data, stopTime)) } func (r LabServiceScheduleResource) complete(data acceptance.TestData, startTime, stopTime, expirationDate string) string { @@ -162,7 +192,7 @@ func (r LabServiceScheduleResource) complete(data acceptance.TestData, startTime %s resource "azurerm_lab_service_schedule" "test" { - name = "acctest-lss-%d" + name = "acctest-labschedule-%d" lab_id = azurerm_lab_service_lab.test.id notes = "Testing" start_at = "%s" @@ -184,7 +214,7 @@ func (r LabServiceScheduleResource) update(data acceptance.TestData, startTime, %s resource "azurerm_lab_service_schedule" "test" { - name = "acctest-lss-%d" + name = "acctest-labschedule-%d" lab_id = azurerm_lab_service_lab.test.id notes = "Testing2" start_at = "%s" diff --git a/website/docs/r/lab_service_schedule.html.markdown b/website/docs/r/lab_service_schedule.html.markdown index 53a39f1ad19c..8f6dea2a580a 100644 --- a/website/docs/r/lab_service_schedule.html.markdown +++ b/website/docs/r/lab_service_schedule.html.markdown @@ -19,12 +19,37 @@ resource "azurerm_resource_group" "example" { } resource "azurerm_lab_service_lab" "example" { - name = "example-lsl" + name = "example-lab" resource_group_name = azurerm_resource_group.example.name + location = azurerm_resource_group.example.location + title = "Test Title" + + security { + open_access_enabled = false + } + + virtual_machine { + admin_user { + username = "testadmin" + password = "Password1234!" + } + + image_reference { + offer = "0001-com-ubuntu-server-focal" + publisher = "canonical" + sku = "20_04-lts" + version = "latest" + } + + sku { + name = "Classic_Fsv2_2_4GB_128_S_SSD" + capacity = 1 + } + } } resource "azurerm_lab_service_schedule" "example" { - name = "example-lss" + name = "example-labschedule" lab_id = azurerm_lab_service_lab.example.id stop_at = "2022-11-28T00:00:00Z" time_zone_id = "America/Los_Angeles" From e39ba9ef4c38e5518016430cb6d454784dc8ca8e Mon Sep 17 00:00:00 2001 From: neil-yechenwei Date: Thu, 12 Jan 2023 12:52:26 +0800 Subject: [PATCH 04/10] update code --- .../lab_service_schedule_resource.go | 38 ++++++++++++------- .../docs/r/lab_service_schedule.html.markdown | 2 +- 2 files changed, 25 insertions(+), 15 deletions(-) diff --git a/internal/services/labservice/lab_service_schedule_resource.go b/internal/services/labservice/lab_service_schedule_resource.go index 20e0a6412410..77dc1505dcf1 100644 --- a/internal/services/labservice/lab_service_schedule_resource.go +++ b/internal/services/labservice/lab_service_schedule_resource.go @@ -3,6 +3,7 @@ package labservice import ( "context" "fmt" + "github.com/hashicorp/terraform-provider-azurerm/utils" "time" "github.com/hashicorp/go-azure-helpers/lang/response" @@ -99,8 +100,7 @@ func (r LabServiceScheduleResource) Arguments() map[string]*pluginsdk.Schema { "frequency": { Type: pluginsdk.TypeString, - Optional: true, - Default: string(schedule.RecurrenceFrequencyDaily), + Required: true, ValidateFunc: validation.StringInSlice([]string{ string(schedule.RecurrenceFrequencyDaily), string(schedule.RecurrenceFrequencyWeekly), @@ -116,15 +116,18 @@ func (r LabServiceScheduleResource) Arguments() map[string]*pluginsdk.Schema { "week_days": { Type: pluginsdk.TypeList, Optional: true, - ValidateFunc: validation.StringInSlice([]string{ - string(schedule.WeekDaySunday), - string(schedule.WeekDayMonday), - string(schedule.WeekDayTuesday), - string(schedule.WeekDayWednesday), - string(schedule.WeekDayThursday), - string(schedule.WeekDayFriday), - string(schedule.WeekDaySaturday), - }, false), + Elem: &pluginsdk.Schema{ + Type: pluginsdk.TypeString, + ValidateFunc: validation.StringInSlice([]string{ + string(schedule.WeekDaySunday), + string(schedule.WeekDayMonday), + string(schedule.WeekDayTuesday), + string(schedule.WeekDayWednesday), + string(schedule.WeekDayThursday), + string(schedule.WeekDayFriday), + string(schedule.WeekDaySaturday), + }, false), + }, }, }, }, @@ -331,10 +334,15 @@ func expandRecurrencePattern(input []RecurrencePattern) *schedule.RecurrencePatt result := schedule.RecurrencePattern{ ExpirationDate: recurrencePattern.ExpirationDate, Frequency: recurrencePattern.Frequency, - Interval: &recurrencePattern.Interval, } - result.WeekDays = &recurrencePattern.WeekDays + if recurrencePattern.Interval != 0 { + result.Interval = utils.Int64(recurrencePattern.Interval) + } + + if recurrencePattern.WeekDays != nil { + result.WeekDays = &recurrencePattern.WeekDays + } return &result } @@ -354,7 +362,9 @@ func flattenRecurrencePattern(input *schedule.RecurrencePattern) []RecurrencePat recurrencePattern.Interval = *input.Interval } - recurrencePattern.WeekDays = *input.WeekDays + if input.WeekDays != nil { + recurrencePattern.WeekDays = *input.WeekDays + } return append(recurrencePatterns, recurrencePattern) } diff --git a/website/docs/r/lab_service_schedule.html.markdown b/website/docs/r/lab_service_schedule.html.markdown index 8f6dea2a580a..c21d25e7a8b8 100644 --- a/website/docs/r/lab_service_schedule.html.markdown +++ b/website/docs/r/lab_service_schedule.html.markdown @@ -80,7 +80,7 @@ A `recurrence_pattern` block supports the following: * `expiration_date` - (Required) When the recurrence will expire in RFC-3339 format. -* `frequency` - (Optional) The frequency of the recurrence. Possible values are `Daily` and `Weekly`. Defaults to `Daily`. +* `frequency` - (Required) The frequency of the recurrence. Possible values are `Daily` and `Weekly`. * `interval` - (Optional) The interval to invoke the schedule on. Possible values are between `1` and `365`. From 5a1c0b98fffc0459b6b310f1b3374ea9a2f338f2 Mon Sep 17 00:00:00 2001 From: neil-yechenwei Date: Thu, 12 Jan 2023 12:57:05 +0800 Subject: [PATCH 05/10] update code --- website/docs/r/lab_service_schedule.html.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/website/docs/r/lab_service_schedule.html.markdown b/website/docs/r/lab_service_schedule.html.markdown index c21d25e7a8b8..2db923a49fbd 100644 --- a/website/docs/r/lab_service_schedule.html.markdown +++ b/website/docs/r/lab_service_schedule.html.markdown @@ -84,7 +84,7 @@ A `recurrence_pattern` block supports the following: * `interval` - (Optional) The interval to invoke the schedule on. Possible values are between `1` and `365`. -* `week_days` - (Optional) The interval to invoke the schedule on. Possible values are `Sunday`, `Monday`, `Tuesday`, `Wednesday`, `Thrusday`, `Friday` and `Saturday`. +* `week_days` - (Optional) The interval to invoke the schedule on. Possible values are `Sunday`, `Monday`, `Tuesday`, `Wednesday`, `Thursday`, `Friday` and `Saturday`. ## Attributes Reference From 3acfc6e886fdeb2f6eafca057346a4c91bc6c66d Mon Sep 17 00:00:00 2001 From: neil-yechenwei Date: Thu, 12 Jan 2023 13:36:37 +0800 Subject: [PATCH 06/10] update code --- .../lab_service_schedule_resource.go | 38 +++++++++++++++---- .../validate/schedule_notes_test.go | 2 +- 2 files changed, 31 insertions(+), 9 deletions(-) diff --git a/internal/services/labservice/lab_service_schedule_resource.go b/internal/services/labservice/lab_service_schedule_resource.go index 77dc1505dcf1..4b91d95e991d 100644 --- a/internal/services/labservice/lab_service_schedule_resource.go +++ b/internal/services/labservice/lab_service_schedule_resource.go @@ -31,7 +31,7 @@ type RecurrencePattern struct { ExpirationDate string `tfschema:"expiration_date"` Frequency schedule.RecurrenceFrequency `tfschema:"frequency"` Interval int64 `tfschema:"interval"` - WeekDays []schedule.WeekDay `tfschema:"week_days"` + WeekDays []string `tfschema:"week_days"` } type LabServiceScheduleResource struct{} @@ -334,16 +334,13 @@ func expandRecurrencePattern(input []RecurrencePattern) *schedule.RecurrencePatt result := schedule.RecurrencePattern{ ExpirationDate: recurrencePattern.ExpirationDate, Frequency: recurrencePattern.Frequency, + WeekDays: expandWeekDays(recurrencePattern.WeekDays), } if recurrencePattern.Interval != 0 { result.Interval = utils.Int64(recurrencePattern.Interval) } - if recurrencePattern.WeekDays != nil { - result.WeekDays = &recurrencePattern.WeekDays - } - return &result } @@ -356,15 +353,40 @@ func flattenRecurrencePattern(input *schedule.RecurrencePattern) []RecurrencePat recurrencePattern := RecurrencePattern{ ExpirationDate: input.ExpirationDate, Frequency: input.Frequency, + WeekDays: flattenWeekDays(input.WeekDays), } if input.Interval != nil { recurrencePattern.Interval = *input.Interval } - if input.WeekDays != nil { - recurrencePattern.WeekDays = *input.WeekDays + return append(recurrencePatterns, recurrencePattern) +} + +func expandWeekDays(input []string) *[]schedule.WeekDay { + if len(input) == 0 { + return nil } - return append(recurrencePatterns, recurrencePattern) + result := make([]schedule.WeekDay, 0) + + for _, item := range input { + result = append(result, schedule.WeekDay(item)) + } + + return &result +} + +func flattenWeekDays(input *[]schedule.WeekDay) []string { + if input == nil { + return nil + } + + result := make([]string, 0) + + for _, item := range *input { + result = append(result, string(item)) + } + + return result } diff --git a/internal/services/labservice/validate/schedule_notes_test.go b/internal/services/labservice/validate/schedule_notes_test.go index f0a1e8418b35..2ef0926e64b8 100644 --- a/internal/services/labservice/validate/schedule_notes_test.go +++ b/internal/services/labservice/validate/schedule_notes_test.go @@ -5,7 +5,7 @@ import ( "testing" ) -func TestValidateLabPlanName(t *testing.T) { +func TestValidateScheduleNotes(t *testing.T) { cases := []struct { Input string ExpectError bool From 102c1addff4218982e8b093c1e01cca95b349a77 Mon Sep 17 00:00:00 2001 From: neil-yechenwei Date: Thu, 12 Jan 2023 13:45:09 +0800 Subject: [PATCH 07/10] update code --- internal/services/labservice/lab_service_schedule_resource.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/services/labservice/lab_service_schedule_resource.go b/internal/services/labservice/lab_service_schedule_resource.go index 4b91d95e991d..a75d01116db2 100644 --- a/internal/services/labservice/lab_service_schedule_resource.go +++ b/internal/services/labservice/lab_service_schedule_resource.go @@ -3,7 +3,6 @@ package labservice import ( "context" "fmt" - "github.com/hashicorp/terraform-provider-azurerm/utils" "time" "github.com/hashicorp/go-azure-helpers/lang/response" @@ -15,6 +14,7 @@ import ( "github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk" "github.com/hashicorp/terraform-provider-azurerm/internal/tf/suppress" "github.com/hashicorp/terraform-provider-azurerm/internal/tf/validation" + "github.com/hashicorp/terraform-provider-azurerm/utils" ) type LabServiceScheduleModel struct { From 92cbe918304c737299fdd3c497ca23b0c4a01a0f Mon Sep 17 00:00:00 2001 From: neil-yechenwei Date: Thu, 12 Jan 2023 17:07:33 +0800 Subject: [PATCH 08/10] update code --- .../labservice/lab_service_schedule_resource_test.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/internal/services/labservice/lab_service_schedule_resource_test.go b/internal/services/labservice/lab_service_schedule_resource_test.go index c9de046d56b5..5c5c7cc1a610 100644 --- a/internal/services/labservice/lab_service_schedule_resource_test.go +++ b/internal/services/labservice/lab_service_schedule_resource_test.go @@ -58,7 +58,7 @@ func TestAccLabServiceSchedule_complete(t *testing.T) { startTime := time.Now().Format(time.RFC3339) stopTime := time.Now().Add(time.Hour * 1).Format(time.RFC3339) - expirationDate := time.Now().Add(time.Hour * 2).Format(time.RFC3339) + expirationDate := time.Now().Add(time.Hour * 1).Format(time.RFC3339) data.ResourceTest(t, r, []acceptance.TestStep{ { @@ -77,10 +77,10 @@ func TestAccLabServiceSchedule_update(t *testing.T) { startTime := time.Now().Format(time.RFC3339) stopTime := time.Now().Add(time.Hour * 1).Format(time.RFC3339) - expirationDate := time.Now().Add(time.Hour * 2).Format(time.RFC3339) + expirationDate := time.Now().Add(time.Hour * 1).Format(time.RFC3339) - updatedStartTime := time.Now().Format(time.RFC3339) - updatedStopTime := time.Now().Add(time.Hour * 1).Format(time.RFC3339) + updatedStartTime := time.Now().Add(time.Hour * 1).Format(time.RFC3339) + updatedStopTime := time.Now().Add(time.Hour * 2).Format(time.RFC3339) updatedExpirationDate := time.Now().Add(time.Hour * 2).Format(time.RFC3339) data.ResourceTest(t, r, []acceptance.TestStep{ @@ -158,7 +158,7 @@ resource "azurerm_lab_service_lab" "test" { } } } -`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) +`, data.RandomInteger, data.Locations.Primary, data.RandomIntOfLength(17)) } func (r LabServiceScheduleResource) basic(data acceptance.TestData, stopTime string) string { From aab0927a028800a56438f0be57323efe80475061 Mon Sep 17 00:00:00 2001 From: neil-yechenwei Date: Fri, 13 Jan 2023 09:37:55 +0800 Subject: [PATCH 09/10] update code --- .../lab_service_schedule_resource.go | 66 +++++++++---------- .../lab_service_schedule_resource_test.go | 48 +++++++------- .../docs/r/lab_service_schedule.html.markdown | 18 ++--- 3 files changed, 66 insertions(+), 66 deletions(-) diff --git a/internal/services/labservice/lab_service_schedule_resource.go b/internal/services/labservice/lab_service_schedule_resource.go index a75d01116db2..e7184cf9ac8b 100644 --- a/internal/services/labservice/lab_service_schedule_resource.go +++ b/internal/services/labservice/lab_service_schedule_resource.go @@ -18,16 +18,16 @@ import ( ) type LabServiceScheduleModel struct { - Name string `tfschema:"name"` - LabId string `tfschema:"lab_id"` - Notes string `tfschema:"notes"` - RecurrencePattern []RecurrencePattern `tfschema:"recurrence_pattern"` - StartAt string `tfschema:"start_at"` - StopAt string `tfschema:"stop_at"` - TimeZoneId string `tfschema:"time_zone_id"` + Name string `tfschema:"name"` + LabId string `tfschema:"lab_id"` + Notes string `tfschema:"notes"` + Recurrence []Recurrence `tfschema:"recurrence"` + StartTime string `tfschema:"start_time"` + StopTime string `tfschema:"stop_time"` + TimeZone string `tfschema:"time_zone"` } -type RecurrencePattern struct { +type Recurrence struct { ExpirationDate string `tfschema:"expiration_date"` Frequency schedule.RecurrenceFrequency `tfschema:"frequency"` Interval int64 `tfschema:"interval"` @@ -66,14 +66,14 @@ func (r LabServiceScheduleResource) Arguments() map[string]*pluginsdk.Schema { ValidateFunc: lab.ValidateLabID, }, - "stop_at": { + "stop_time": { Type: pluginsdk.TypeString, Required: true, DiffSuppressFunc: suppress.RFC3339MinuteTime, ValidateFunc: validation.IsRFC3339Time, }, - "time_zone_id": { + "time_zone": { Type: pluginsdk.TypeString, Required: true, ValidateFunc: azValidate.AzureTimeZoneString(), @@ -85,7 +85,7 @@ func (r LabServiceScheduleResource) Arguments() map[string]*pluginsdk.Schema { ValidateFunc: validate.ScheduleNotes, }, - "recurrence_pattern": { + "recurrence": { Type: pluginsdk.TypeList, Optional: true, MaxItems: 1, @@ -133,7 +133,7 @@ func (r LabServiceScheduleResource) Arguments() map[string]*pluginsdk.Schema { }, }, - "start_at": { + "start_time": { Type: pluginsdk.TypeString, Optional: true, DiffSuppressFunc: suppress.RFC3339MinuteTime, @@ -173,9 +173,9 @@ func (r LabServiceScheduleResource) Create() sdk.ResourceFunc { properties := &schedule.Schedule{ Properties: schedule.ScheduleProperties{ - StopAt: model.StopAt, - TimeZoneId: model.TimeZoneId, - RecurrencePattern: expandRecurrencePattern(model.RecurrencePattern), + StopAt: model.StopTime, + TimeZoneId: model.TimeZone, + RecurrencePattern: expandRecurrencePattern(model.Recurrence), }, } @@ -183,8 +183,8 @@ func (r LabServiceScheduleResource) Create() sdk.ResourceFunc { properties.Properties.Notes = &model.Notes } - if model.StartAt != "" { - properties.Properties.StartAt = &model.StartAt + if model.StartTime != "" { + properties.Properties.StartAt = &model.StartTime } if _, err := client.CreateOrUpdate(ctx, id, *properties); err != nil { @@ -231,20 +231,20 @@ func (r LabServiceScheduleResource) Update() sdk.ResourceFunc { } } - if metadata.ResourceData.HasChange("recurrence_pattern") { - properties.Properties.RecurrencePattern = expandRecurrencePattern(model.RecurrencePattern) + if metadata.ResourceData.HasChange("recurrence") { + properties.Properties.RecurrencePattern = expandRecurrencePattern(model.Recurrence) } - if metadata.ResourceData.HasChange("start_at") { - properties.Properties.StartAt = &model.StartAt + if metadata.ResourceData.HasChange("start_time") { + properties.Properties.StartAt = &model.StartTime } - if metadata.ResourceData.HasChange("stop_at") { - properties.Properties.StopAt = model.StopAt + if metadata.ResourceData.HasChange("stop_time") { + properties.Properties.StopAt = model.StopTime } - if metadata.ResourceData.HasChange("time_zone_id") { - properties.Properties.TimeZoneId = model.TimeZoneId + if metadata.ResourceData.HasChange("time_zone") { + properties.Properties.TimeZoneId = model.TimeZone } if _, err := client.CreateOrUpdate(ctx, *id, *properties); err != nil { @@ -288,16 +288,16 @@ func (r LabServiceScheduleResource) Read() sdk.ResourceFunc { properties := &model.Properties - state.StopAt = properties.StopAt - state.TimeZoneId = properties.TimeZoneId - state.RecurrencePattern = flattenRecurrencePattern(properties.RecurrencePattern) + state.StopTime = properties.StopAt + state.TimeZone = properties.TimeZoneId + state.Recurrence = flattenRecurrencePattern(properties.RecurrencePattern) if properties.Notes != nil { state.Notes = *properties.Notes } if properties.StartAt != nil { - state.StartAt = *properties.StartAt + state.StartTime = *properties.StartAt } return metadata.Encode(&state) @@ -325,7 +325,7 @@ func (r LabServiceScheduleResource) Delete() sdk.ResourceFunc { } } -func expandRecurrencePattern(input []RecurrencePattern) *schedule.RecurrencePattern { +func expandRecurrencePattern(input []Recurrence) *schedule.RecurrencePattern { if len(input) == 0 { return nil } @@ -344,13 +344,13 @@ func expandRecurrencePattern(input []RecurrencePattern) *schedule.RecurrencePatt return &result } -func flattenRecurrencePattern(input *schedule.RecurrencePattern) []RecurrencePattern { - var recurrencePatterns []RecurrencePattern +func flattenRecurrencePattern(input *schedule.RecurrencePattern) []Recurrence { + var recurrencePatterns []Recurrence if input == nil { return recurrencePatterns } - recurrencePattern := RecurrencePattern{ + recurrencePattern := Recurrence{ ExpirationDate: input.ExpirationDate, Frequency: input.Frequency, WeekDays: flattenWeekDays(input.WeekDays), diff --git a/internal/services/labservice/lab_service_schedule_resource_test.go b/internal/services/labservice/lab_service_schedule_resource_test.go index 5c5c7cc1a610..0cab1382fa57 100644 --- a/internal/services/labservice/lab_service_schedule_resource_test.go +++ b/internal/services/labservice/lab_service_schedule_resource_test.go @@ -166,10 +166,10 @@ func (r LabServiceScheduleResource) basic(data acceptance.TestData, stopTime str %s resource "azurerm_lab_service_schedule" "test" { - name = "acctest-labschedule-%d" - lab_id = azurerm_lab_service_lab.test.id - stop_at = "%s" - time_zone_id = "America/Los_Angeles" + name = "acctest-labschedule-%d" + lab_id = azurerm_lab_service_lab.test.id + stop_time = "%s" + time_zone = "America/Los_Angeles" } `, r.template(data), data.RandomInteger, stopTime) } @@ -179,10 +179,10 @@ func (r LabServiceScheduleResource) requiresImport(data acceptance.TestData, sto %s resource "azurerm_lab_service_schedule" "import" { - name = azurerm_lab_service_schedule.test.name - lab_id = azurerm_lab_service_schedule.test.lab_id - stop_at = azurerm_lab_service_schedule.test.stop_at - time_zone_id = azurerm_lab_service_schedule.test.time_zone_id + name = azurerm_lab_service_schedule.test.name + lab_id = azurerm_lab_service_schedule.test.lab_id + stop_time = azurerm_lab_service_schedule.test.stop_time + time_zone = azurerm_lab_service_schedule.test.time_zone } `, r.basic(data, stopTime)) } @@ -192,14 +192,14 @@ func (r LabServiceScheduleResource) complete(data acceptance.TestData, startTime %s resource "azurerm_lab_service_schedule" "test" { - name = "acctest-labschedule-%d" - lab_id = azurerm_lab_service_lab.test.id - notes = "Testing" - start_at = "%s" - stop_at = "%s" - time_zone_id = "America/Los_Angeles" - - recurrence_pattern { + name = "acctest-labschedule-%d" + lab_id = azurerm_lab_service_lab.test.id + notes = "Testing" + start_time = "%s" + stop_time = "%s" + time_zone = "America/Los_Angeles" + + recurrence { expiration_date = "%s" frequency = "Weekly" interval = 1 @@ -214,14 +214,14 @@ func (r LabServiceScheduleResource) update(data acceptance.TestData, startTime, %s resource "azurerm_lab_service_schedule" "test" { - name = "acctest-labschedule-%d" - lab_id = azurerm_lab_service_lab.test.id - notes = "Testing2" - start_at = "%s" - stop_at = "%s" - time_zone_id = "America/Grenada" - - recurrence_pattern { + name = "acctest-labschedule-%d" + lab_id = azurerm_lab_service_lab.test.id + notes = "Testing2" + start_time = "%s" + stop_time = "%s" + time_zone = "America/Grenada" + + recurrence { expiration_date = "%s" frequency = "Daily" interval = 2 diff --git a/website/docs/r/lab_service_schedule.html.markdown b/website/docs/r/lab_service_schedule.html.markdown index 2db923a49fbd..dbaae281fd4e 100644 --- a/website/docs/r/lab_service_schedule.html.markdown +++ b/website/docs/r/lab_service_schedule.html.markdown @@ -49,10 +49,10 @@ resource "azurerm_lab_service_lab" "example" { } resource "azurerm_lab_service_schedule" "example" { - name = "example-labschedule" - lab_id = azurerm_lab_service_lab.example.id - stop_at = "2022-11-28T00:00:00Z" - time_zone_id = "America/Los_Angeles" + name = "example-labschedule" + lab_id = azurerm_lab_service_lab.example.id + stop_time = "2022-11-28T00:00:00Z" + time_zone = "America/Los_Angeles" } ``` @@ -64,19 +64,19 @@ The following arguments are supported: * `lab_id` - (Required) The resource ID of the Lab Service Schedule. Changing this forces a new resource to be created. -* `stop_at` - (Required) When Lab User Virtual Machines will be stopped in RFC-3339 format. +* `stop_time` - (Required) When Lab User Virtual Machines will be stopped in RFC-3339 format. -* `time_zone_id` - (Required) The IANA Time Zone ID for the Schedule. +* `time_zone` - (Required) The IANA Time Zone ID for the Schedule. * `notes` - (Optional) The notes for the Schedule. -* `recurrence_pattern` - (Optional) A `recurrence_pattern` block as defined below. +* `recurrence` - (Optional) A `recurrence` block as defined below. -* `start_at` - (Optional) When Lab User Virtual Machines will be started in RFC-3339 format. +* `start_time` - (Optional) When Lab User Virtual Machines will be started in RFC-3339 format. --- -A `recurrence_pattern` block supports the following: +A `recurrence` block supports the following: * `expiration_date` - (Required) When the recurrence will expire in RFC-3339 format. From 11e0ae4eede274893f9a52709e2cf18d02112655 Mon Sep 17 00:00:00 2001 From: neil-yechenwei Date: Fri, 13 Jan 2023 10:34:33 +0800 Subject: [PATCH 10/10] update code --- internal/services/labservice/lab_service_lab_resource.go | 2 +- internal/services/labservice/lab_service_user_resource_test.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/internal/services/labservice/lab_service_lab_resource.go b/internal/services/labservice/lab_service_lab_resource.go index dcb946fcd246..ff7f5c55ef22 100644 --- a/internal/services/labservice/lab_service_lab_resource.go +++ b/internal/services/labservice/lab_service_lab_resource.go @@ -757,7 +757,7 @@ func flattenAutoShutdownProfile(input lab.AutoShutdownProfile) []AutoShutdown { shutdownWhenNotConnectedEnabled := input.ShutdownWhenNotConnected != nil && *input.ShutdownWhenNotConnected != lab.EnableStateDisabled shutdownOnIdleModeConfigured := input.ShutdownOnIdle != nil && *input.ShutdownOnIdle != lab.ShutdownOnIdleModeNone idleDelayConfigured := input.IdleDelay != nil - if !shutdownOnDisconnectEnabled && !shutdownWhenNotConnectedEnabled && shutdownOnIdleModeConfigured && !idleDelayConfigured { + if !shutdownOnDisconnectEnabled && !shutdownWhenNotConnectedEnabled && !shutdownOnIdleModeConfigured && !idleDelayConfigured { return []AutoShutdown{} } diff --git a/internal/services/labservice/lab_service_user_resource_test.go b/internal/services/labservice/lab_service_user_resource_test.go index 25277f872ef4..14f3665c77a3 100644 --- a/internal/services/labservice/lab_service_user_resource_test.go +++ b/internal/services/labservice/lab_service_user_resource_test.go @@ -140,7 +140,7 @@ resource "azurerm_lab_service_lab" "test" { } } } -`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) +`, data.RandomInteger, data.Locations.Primary, data.RandomIntOfLength(17)) } func (r LabServiceUserResource) basic(data acceptance.TestData) string {