diff --git a/internal/services/automation/automation_hybrid_runbook_worker.go b/internal/services/automation/automation_hybrid_runbook_worker.go new file mode 100644 index 000000000000..a9b54607d43e --- /dev/null +++ b/internal/services/automation/automation_hybrid_runbook_worker.go @@ -0,0 +1,199 @@ +package automation + +import ( + "context" + "fmt" + "net/http" + "time" + + "github.com/hashicorp/terraform-provider-azurerm/utils" + + "github.com/hashicorp/go-azure-helpers/lang/response" + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonschema" + "github.com/hashicorp/go-azure-sdk/resource-manager/automation/2021-06-22/hybridrunbookworker" + "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 HybridRunbookWorkerModel struct { + ResourceGroupName string `tfschema:"resource_group_name"` + AutomationAccountName string `tfschema:"automation_account_name"` + WorkerGroupName string `tfschema:"worker_group_name"` + WorkerName string `tfschema:"worker_name"` + WorkerId string `tfschema:"worker_id"` + VmResourceId string `tfschema:"vm_resource_id"` + Ip string `tfschema:"ip"` + RegisteredDateTime string `tfschema:"registered_date_time"` + LastSeenDateTime string `tfschema:"last_seen_date_time"` + WorkerType string `tfschema:"worker_type"` +} + +type HybridRunbookWorkerResource struct{} + +var _ sdk.Resource = (*HybridRunbookWorkerResource)(nil) + +func (m HybridRunbookWorkerResource) Arguments() map[string]*pluginsdk.Schema { + return map[string]*pluginsdk.Schema{ + "resource_group_name": commonschema.ResourceGroupName(), + "automation_account_name": { + Type: pluginsdk.TypeString, + Required: true, + ForceNew: true, + ValidateFunc: validation.StringIsNotEmpty, + }, + "worker_group_name": { + Type: pluginsdk.TypeString, + Required: true, + ForceNew: true, + ValidateFunc: validation.StringIsNotEmpty, + }, + "worker_id": { + Type: pluginsdk.TypeString, + Required: true, + ForceNew: true, + ValidateFunc: validation.IsUUID, + }, + "vm_resource_id": { + Type: pluginsdk.TypeString, + Required: true, + ForceNew: true, + ValidateFunc: validation.StringIsNotEmpty, + }, + } +} + +func (m HybridRunbookWorkerResource) Attributes() map[string]*pluginsdk.Schema { + return map[string]*pluginsdk.Schema{ + "ip": { + Type: pluginsdk.TypeString, + Computed: true, + }, + "registered_date_time": { + Type: pluginsdk.TypeString, + Computed: true, + }, + "last_seen_date_time": { + Type: pluginsdk.TypeString, + Computed: true, + }, + "worker_name": { + Type: pluginsdk.TypeString, + Computed: true, + }, + "worker_type": { + Type: pluginsdk.TypeString, + Computed: true, + }, + } +} + +func (m HybridRunbookWorkerResource) ModelObject() interface{} { + return &HybridRunbookWorkerModel{} +} + +func (m HybridRunbookWorkerResource) ResourceType() string { + return "azurerm_automation_hybrid_runbook_worker" +} + +func (m HybridRunbookWorkerResource) Create() sdk.ResourceFunc { + return sdk.ResourceFunc{ + Timeout: 30 * time.Minute, + Func: func(ctx context.Context, meta sdk.ResourceMetaData) error { + client := meta.Client.Automation.RunbookWorkerClient + + var model HybridRunbookWorkerModel + if err := meta.Decode(&model); err != nil { + return err + } + + subscriptionID := meta.Client.Account.SubscriptionId + id := hybridrunbookworker.NewHybridRunbookWorkerID(subscriptionID, model.ResourceGroupName, + model.AutomationAccountName, model.WorkerGroupName, model.WorkerId) + existing, err := client.Get(ctx, id) + if !response.WasNotFound(existing.HttpResponse) { + if err != nil { + return fmt.Errorf("retreiving %s: %v", id, err) + } + return meta.ResourceRequiresImport(m.ResourceType(), id) + } + + req := hybridrunbookworker.HybridRunbookWorkerCreateParameters{} + if model.VmResourceId != "" { + req.Properties.VmResourceId = utils.String(model.VmResourceId) + } + + future, err := client.Create(ctx, id, req) + if err != nil { + // Workaround swagger issue https://github.com/Azure/azure-rest-api-specs/issues/19741 + if !response.WasStatusCode(future.HttpResponse, http.StatusCreated) { + return fmt.Errorf("creating %s: %v", id, err) + } + } + _ = future + + meta.SetID(id) + return nil + }, + } +} + +func (m HybridRunbookWorkerResource) Read() sdk.ResourceFunc { + return sdk.ResourceFunc{ + Timeout: 5 * time.Minute, + Func: func(ctx context.Context, meta sdk.ResourceMetaData) error { + id, err := hybridrunbookworker.ParseHybridRunbookWorkerID(meta.ResourceData.Id()) + if err != nil { + return err + } + client := meta.Client.Automation.RunbookWorkerClient + result, err := client.Get(ctx, *id) + if err != nil { + return err + } + if result.Model == nil { + return fmt.Errorf("retrieving %s got nil model", id) + } + + var output HybridRunbookWorkerModel + + // the name in response corresponding to work_id in request + output.WorkerId = utils.NormalizeNilableString(result.Model.Name) + output.AutomationAccountName = id.AutomationAccountName + output.ResourceGroupName = id.ResourceGroupName + output.WorkerGroupName = id.HybridRunbookWorkerGroupName + if prop := result.Model.Properties; prop != nil { + output.VmResourceId = utils.NormalizeNilableString(prop.VmResourceId) + output.WorkerType = utils.NormalizeNilableString((*string)(prop.WorkerType)) + output.LastSeenDateTime = utils.NormalizeNilableString(prop.LastSeenDateTime) + output.RegisteredDateTime = utils.NormalizeNilableString(prop.RegisteredDateTime) + output.Ip = utils.NormalizeNilableString(prop.Ip) + output.WorkerName = utils.NormalizeNilableString(prop.WorkerName) + } + // TODO: populate other fields + return meta.Encode(&output) + }, + } +} + +func (m HybridRunbookWorkerResource) Delete() sdk.ResourceFunc { + return sdk.ResourceFunc{ + Timeout: 10 * time.Minute, + Func: func(ctx context.Context, meta sdk.ResourceMetaData) error { + id, err := hybridrunbookworker.ParseHybridRunbookWorkerID(meta.ResourceData.Id()) + if err != nil { + return err + } + meta.Logger.Infof("deleting %s", id) + client := meta.Client.Automation.RunbookWorkerClient + if _, err = client.Delete(ctx, *id); err != nil { + return fmt.Errorf("deleting %s: %v", id, err) + } + return nil + }, + } +} + +func (m HybridRunbookWorkerResource) IDValidationFunc() pluginsdk.SchemaValidateFunc { + return hybridrunbookworker.ValidateHybridRunbookWorkerID +} diff --git a/internal/services/automation/automation_hybrid_runbook_worker_group.go b/internal/services/automation/automation_hybrid_runbook_worker_group.go index fbe74abb3c98..8e613e2a6a03 100644 --- a/internal/services/automation/automation_hybrid_runbook_worker_group.go +++ b/internal/services/automation/automation_hybrid_runbook_worker_group.go @@ -3,6 +3,7 @@ package automation import ( "context" "fmt" + "net/http" "time" "github.com/hashicorp/go-azure-helpers/lang/response" @@ -31,11 +32,13 @@ func (m HybridRunbookWorkerGroupResource) Arguments() map[string]*pluginsdk.Sche "automation_account_name": { Type: pluginsdk.TypeString, Required: true, + ForceNew: true, ValidateFunc: validation.StringIsNotEmpty, }, "name": { Type: pluginsdk.TypeString, Required: true, + ForceNew: true, ValidateFunc: validation.StringIsNotEmpty, }, "credential_name": { @@ -87,7 +90,10 @@ func (m HybridRunbookWorkerGroupResource) Create() sdk.ResourceFunc { } future, err := client.Create(ctx, id, req) if err != nil { - return fmt.Errorf("creating %s: %v", id, err) + // Workaround swagger issue https://github.com/Azure/azure-rest-api-specs/issues/19741 + if !response.WasStatusCode(future.HttpResponse, http.StatusCreated) { + return fmt.Errorf("creating %s: %v", id, err) + } } _ = future diff --git a/internal/services/automation/automation_hybrid_runbook_worker_group_test.go b/internal/services/automation/automation_hybrid_runbook_worker_group_test.go index 0036f99509f0..956b849ef8ab 100644 --- a/internal/services/automation/automation_hybrid_runbook_worker_group_test.go +++ b/internal/services/automation/automation_hybrid_runbook_worker_group_test.go @@ -63,8 +63,6 @@ func (a HybridRunbookWorkerGroupResource) basic(data acceptance.TestData) string %s resource "azurerm_automation_hybrid_runbook_worker_group" "test" { - // TODO modify fields - resource_group_name = azurerm_resource_group.test.name automation_account_name = azurerm_automation_account.test.name name = "acctest-%[2]d" @@ -87,8 +85,7 @@ resource "azurerm_automation_credential" "test2" { password = "test_pwd" } -resource "azurerm_automation_connection_type" "test" { - +resource "azurerm_automation_hybrid_runbook_worker_group" "test" { resource_group_name = azurerm_resource_group.test.name automation_account_name = azurerm_automation_account.test.name name = "acctest-%[2]d" @@ -105,7 +102,6 @@ func TestAccHybridRunbookWorkerGroup_basic(t *testing.T) { Config: r.basic(data), Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), - check.That(data.ResourceName).Key("credential_name").HasValue("example-foo"), ), }, }) @@ -119,7 +115,6 @@ func TestAccHybridRunbookWorkerGroup_update(t *testing.T) { Config: r.basic(data), Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), - check.That(data.ResourceName).Key("credential_name").HasValue("example-foo"), ), }, data.ImportStep(), @@ -127,7 +122,6 @@ func TestAccHybridRunbookWorkerGroup_update(t *testing.T) { Config: r.update(data), Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), - check.That(data.ResourceName).Key("credential_name").HasValue("example-bar"), ), }, data.ImportStep(), diff --git a/internal/services/automation/automation_hybrid_runbook_worker_test.go b/internal/services/automation/automation_hybrid_runbook_worker_test.go new file mode 100644 index 000000000000..50a3324ef429 --- /dev/null +++ b/internal/services/automation/automation_hybrid_runbook_worker_test.go @@ -0,0 +1,153 @@ +package automation_test + +import ( + "context" + "fmt" + "testing" + + "github.com/google/uuid" + + "github.com/hashicorp/go-azure-sdk/resource-manager/automation/2021-06-22/hybridrunbookworker" + "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/services/automation" + "github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk" + "github.com/hashicorp/terraform-provider-azurerm/utils" +) + +type HybridRunbookWorkerResource struct{} + +func (a HybridRunbookWorkerResource) Exists(ctx context.Context, client *clients.Client, state *pluginsdk.InstanceState) (*bool, error) { + id, err := hybridrunbookworker.ParseHybridRunbookWorkerID(state.ID) + if err != nil { + return nil, err + } + resp, err := client.Automation.RunbookWorkerClient.Get(ctx, *id) + if err != nil { + return nil, fmt.Errorf("retrieving HybridRunbookWorker %s: %+v", id, err) + } + return utils.Bool(resp.Model != nil), nil +} + +func (a HybridRunbookWorkerResource) template(data acceptance.TestData) string { + return fmt.Sprintf(` +provider "azurerm" { + features {} +} + +resource "azurerm_resource_group" "test" { + name = "acctestRG-auto-%[1]d" + location = "%[2]s" +} + +resource "azurerm_automation_account" "test" { + name = "acctestAA-%[1]d" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name + sku_name = "Basic" +} + +resource "azurerm_automation_credential" "test" { + name = "acctest-%[1]d" + resource_group_name = azurerm_resource_group.test.name + automation_account_name = azurerm_automation_account.test.name + username = "test_user" + password = "test_pwd" +} + +resource "azurerm_automation_hybrid_runbook_worker_group" "test" { + resource_group_name = azurerm_resource_group.test.name + automation_account_name = azurerm_automation_account.test.name + name = "acctest-%[1]d" + credential_name = azurerm_automation_credential.test.name +} + +resource "azurerm_virtual_network" "test" { + name = "acctestnw-%[1]d" + address_space = ["10.0.0.0/16"] + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name +} + +resource "azurerm_subnet" "test" { + name = "internal" + resource_group_name = azurerm_resource_group.test.name + virtual_network_name = azurerm_virtual_network.test.name + address_prefixes = ["10.0.2.0/24"] +} + +resource "azurerm_network_interface" "test" { + name = "acctni-%[1]d" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name + + ip_configuration { + name = "testconfiguration1" + subnet_id = azurerm_subnet.test.id + private_ip_address_allocation = "Dynamic" + } +} + +resource "azurerm_linux_virtual_machine" "test" { + name = "acctestVM-%[1]d" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location + size = "Standard_G5" + admin_username = "adminuser" + admin_password = "P@$$w0rd1234!" + + disable_password_authentication = false + + network_interface_ids = [ + azurerm_network_interface.test.id, + ] + + os_disk { + caching = "ReadWrite" + storage_account_type = "Standard_LRS" + } + + source_image_reference { + publisher = "Canonical" + offer = "UbuntuServer" + sku = "16.04-LTS" + version = "latest" + } + + tags = { + azsecpack = "nonprod" + "platformsettings.host_environment.service.platform_optedin_for_rootcerts" = "true" + } +} +`, data.RandomInteger, data.Locations.Primary) +} + +func (a HybridRunbookWorkerResource) basic(data acceptance.TestData) string { + return fmt.Sprintf(` + + +%s + +resource "azurerm_automation_hybrid_runbook_worker" "test" { + resource_group_name = azurerm_resource_group.test.name + automation_account_name = azurerm_automation_account.test.name + worker_group_name = azurerm_automation_hybrid_runbook_worker_group.test.name + worker_id = "%s" + vm_resource_id = azurerm_linux_virtual_machine.test.id +} +`, a.template(data), uuid.New().String()) +} + +func TestAccHybridRunbookWorker_basic(t *testing.T) { + data := acceptance.BuildTestData(t, automation.HybridRunbookWorkerResource{}.ResourceType(), "test") + r := HybridRunbookWorkerResource{} + data.ResourceTest(t, r, []acceptance.TestStep{ + { + Config: r.basic(data), + Check: acceptance.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + ), + }, + }) +} diff --git a/internal/services/automation/client/client.go b/internal/services/automation/client/client.go index 689c2a94654e..858a903637d1 100644 --- a/internal/services/automation/client/client.go +++ b/internal/services/automation/client/client.go @@ -3,6 +3,7 @@ package client import ( "github.com/Azure/azure-sdk-for-go/services/preview/automation/mgmt/2020-01-13-preview/automation" "github.com/hashicorp/go-azure-sdk/resource-manager/automation/2021-06-22/automationaccount" + "github.com/hashicorp/go-azure-sdk/resource-manager/automation/2021-06-22/hybridrunbookworker" "github.com/hashicorp/go-azure-sdk/resource-manager/automation/2021-06-22/hybridrunbookworkergroup" "github.com/hashicorp/terraform-provider-azurerm/internal/common" ) @@ -21,6 +22,7 @@ type Client struct { RunbookClient *automation.RunbookClient RunbookDraftClient *automation.RunbookDraftClient RunBookWgClient *hybridrunbookworkergroup.HybridRunbookWorkerGroupClient + RunbookWorkerClient *hybridrunbookworker.HybridRunbookWorkerClient ScheduleClient *automation.ScheduleClient VariableClient *automation.VariableClient WebhookClient *automation.WebhookClient @@ -66,6 +68,9 @@ func NewClient(o *common.ClientOptions) *Client { runbookWgClient := hybridrunbookworkergroup.NewHybridRunbookWorkerGroupClientWithBaseURI(o.ResourceManagerEndpoint) o.ConfigureClient(&runbookWgClient.Client, o.ResourceManagerAuthorizer) + runbookWorkerClient := hybridrunbookworker.NewHybridRunbookWorkerClientWithBaseURI(o.ResourceManagerEndpoint) + o.ConfigureClient(&runbookWorkerClient.Client, o.ResourceManagerAuthorizer) + scheduleClient := automation.NewScheduleClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId) o.ConfigureClient(&scheduleClient.Client, o.ResourceManagerAuthorizer) @@ -89,6 +94,7 @@ func NewClient(o *common.ClientOptions) *Client { RunbookClient: &runbookClient, RunbookDraftClient: &runbookDraftClient, RunBookWgClient: &runbookWgClient, + RunbookWorkerClient: &runbookWorkerClient, ScheduleClient: &scheduleClient, VariableClient: &variableClient, WebhookClient: &webhookClient, diff --git a/internal/services/automation/registration.go b/internal/services/automation/registration.go index 6d7b378060cb..e669895a3570 100644 --- a/internal/services/automation/registration.go +++ b/internal/services/automation/registration.go @@ -14,6 +14,7 @@ func (r Registration) DataSources() []sdk.DataSource { func (r Registration) Resources() []sdk.Resource { return []sdk.Resource{ HybridRunbookWorkerGroupResource{}, + HybridRunbookWorkerResource{}, } } diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/automation/2021-06-22/hybridrunbookworker/README.md b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/automation/2021-06-22/hybridrunbookworker/README.md new file mode 100644 index 000000000000..838221d672a4 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/automation/2021-06-22/hybridrunbookworker/README.md @@ -0,0 +1,111 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/automation/2021-06-22/hybridrunbookworker` Documentation + +The `hybridrunbookworker` SDK allows for interaction with the Azure Resource Manager Service `automation` (API Version `2021-06-22`). + +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/automation/2021-06-22/hybridrunbookworker" +``` + + +### Client Initialization + +```go +client := hybridrunbookworker.NewHybridRunbookWorkerClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `HybridRunbookWorkerClient.Create` + +```go +ctx := context.TODO() +id := hybridrunbookworker.NewHybridRunbookWorkerID("12345678-1234-9876-4563-123456789012", "example-resource-group", "automationAccountValue", "hybridRunbookWorkerGroupValue", "hybridRunbookWorkerIdValue") + +payload := hybridrunbookworker.HybridRunbookWorkerCreateParameters{ + // ... +} + + +read, err := client.Create(ctx, id, payload) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `HybridRunbookWorkerClient.Delete` + +```go +ctx := context.TODO() +id := hybridrunbookworker.NewHybridRunbookWorkerID("12345678-1234-9876-4563-123456789012", "example-resource-group", "automationAccountValue", "hybridRunbookWorkerGroupValue", "hybridRunbookWorkerIdValue") + +read, err := client.Delete(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `HybridRunbookWorkerClient.Get` + +```go +ctx := context.TODO() +id := hybridrunbookworker.NewHybridRunbookWorkerID("12345678-1234-9876-4563-123456789012", "example-resource-group", "automationAccountValue", "hybridRunbookWorkerGroupValue", "hybridRunbookWorkerIdValue") + +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: `HybridRunbookWorkerClient.ListByHybridRunbookWorkerGroup` + +```go +ctx := context.TODO() +id := hybridrunbookworker.NewHybridRunbookWorkerGroupID("12345678-1234-9876-4563-123456789012", "example-resource-group", "automationAccountValue", "hybridRunbookWorkerGroupValue") + +// alternatively `client.ListByHybridRunbookWorkerGroup(ctx, id, hybridrunbookworker.DefaultListByHybridRunbookWorkerGroupOperationOptions())` can be used to do batched pagination +items, err := client.ListByHybridRunbookWorkerGroupComplete(ctx, id, hybridrunbookworker.DefaultListByHybridRunbookWorkerGroupOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `HybridRunbookWorkerClient.Move` + +```go +ctx := context.TODO() +id := hybridrunbookworker.NewHybridRunbookWorkerID("12345678-1234-9876-4563-123456789012", "example-resource-group", "automationAccountValue", "hybridRunbookWorkerGroupValue", "hybridRunbookWorkerIdValue") + +payload := hybridrunbookworker.HybridRunbookWorkerMoveParameters{ + // ... +} + + +read, err := client.Move(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/automation/2021-06-22/hybridrunbookworker/client.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/automation/2021-06-22/hybridrunbookworker/client.go new file mode 100644 index 000000000000..5e3d4e4a14c9 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/automation/2021-06-22/hybridrunbookworker/client.go @@ -0,0 +1,18 @@ +package hybridrunbookworker + +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 HybridRunbookWorkerClient struct { + Client autorest.Client + baseUri string +} + +func NewHybridRunbookWorkerClientWithBaseURI(endpoint string) HybridRunbookWorkerClient { + return HybridRunbookWorkerClient{ + Client: autorest.NewClientWithUserAgent(userAgent()), + baseUri: endpoint, + } +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/automation/2021-06-22/hybridrunbookworker/constants.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/automation/2021-06-22/hybridrunbookworker/constants.go new file mode 100644 index 000000000000..e99ef8208761 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/automation/2021-06-22/hybridrunbookworker/constants.go @@ -0,0 +1,34 @@ +package hybridrunbookworker + +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 WorkerType string + +const ( + WorkerTypeHybridVOne WorkerType = "HybridV1" + WorkerTypeHybridVTwo WorkerType = "HybridV2" +) + +func PossibleValuesForWorkerType() []string { + return []string{ + string(WorkerTypeHybridVOne), + string(WorkerTypeHybridVTwo), + } +} + +func parseWorkerType(input string) (*WorkerType, error) { + vals := map[string]WorkerType{ + "hybridv1": WorkerTypeHybridVOne, + "hybridv2": WorkerTypeHybridVTwo, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := WorkerType(input) + return &out, nil +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/automation/2021-06-22/hybridrunbookworker/id_hybridrunbookworker.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/automation/2021-06-22/hybridrunbookworker/id_hybridrunbookworker.go new file mode 100644 index 000000000000..3b5581cb6a01 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/automation/2021-06-22/hybridrunbookworker/id_hybridrunbookworker.go @@ -0,0 +1,150 @@ +package hybridrunbookworker + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +var _ resourceids.ResourceId = HybridRunbookWorkerId{} + +// HybridRunbookWorkerId is a struct representing the Resource ID for a Hybrid Runbook Worker +type HybridRunbookWorkerId struct { + SubscriptionId string + ResourceGroupName string + AutomationAccountName string + HybridRunbookWorkerGroupName string + HybridRunbookWorkerId string +} + +// NewHybridRunbookWorkerID returns a new HybridRunbookWorkerId struct +func NewHybridRunbookWorkerID(subscriptionId string, resourceGroupName string, automationAccountName string, hybridRunbookWorkerGroupName string, hybridRunbookWorkerId string) HybridRunbookWorkerId { + return HybridRunbookWorkerId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + AutomationAccountName: automationAccountName, + HybridRunbookWorkerGroupName: hybridRunbookWorkerGroupName, + HybridRunbookWorkerId: hybridRunbookWorkerId, + } +} + +// ParseHybridRunbookWorkerID parses 'input' into a HybridRunbookWorkerId +func ParseHybridRunbookWorkerID(input string) (*HybridRunbookWorkerId, error) { + parser := resourceids.NewParserFromResourceIdType(HybridRunbookWorkerId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := HybridRunbookWorkerId{} + + 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.AutomationAccountName, ok = parsed.Parsed["automationAccountName"]; !ok { + return nil, fmt.Errorf("the segment 'automationAccountName' was not found in the resource id %q", input) + } + + if id.HybridRunbookWorkerGroupName, ok = parsed.Parsed["hybridRunbookWorkerGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'hybridRunbookWorkerGroupName' was not found in the resource id %q", input) + } + + if id.HybridRunbookWorkerId, ok = parsed.Parsed["hybridRunbookWorkerId"]; !ok { + return nil, fmt.Errorf("the segment 'hybridRunbookWorkerId' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ParseHybridRunbookWorkerIDInsensitively parses 'input' case-insensitively into a HybridRunbookWorkerId +// note: this method should only be used for API response data and not user input +func ParseHybridRunbookWorkerIDInsensitively(input string) (*HybridRunbookWorkerId, error) { + parser := resourceids.NewParserFromResourceIdType(HybridRunbookWorkerId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := HybridRunbookWorkerId{} + + 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.AutomationAccountName, ok = parsed.Parsed["automationAccountName"]; !ok { + return nil, fmt.Errorf("the segment 'automationAccountName' was not found in the resource id %q", input) + } + + if id.HybridRunbookWorkerGroupName, ok = parsed.Parsed["hybridRunbookWorkerGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'hybridRunbookWorkerGroupName' was not found in the resource id %q", input) + } + + if id.HybridRunbookWorkerId, ok = parsed.Parsed["hybridRunbookWorkerId"]; !ok { + return nil, fmt.Errorf("the segment 'hybridRunbookWorkerId' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ValidateHybridRunbookWorkerID checks that 'input' can be parsed as a Hybrid Runbook Worker ID +func ValidateHybridRunbookWorkerID(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 := ParseHybridRunbookWorkerID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Hybrid Runbook Worker ID +func (id HybridRunbookWorkerId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Automation/automationAccounts/%s/hybridRunbookWorkerGroups/%s/hybridRunbookWorkers/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.AutomationAccountName, id.HybridRunbookWorkerGroupName, id.HybridRunbookWorkerId) +} + +// Segments returns a slice of Resource ID Segments which comprise this Hybrid Runbook Worker ID +func (id HybridRunbookWorkerId) 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("staticMicrosoftAutomation", "Microsoft.Automation", "Microsoft.Automation"), + resourceids.StaticSegment("staticAutomationAccounts", "automationAccounts", "automationAccounts"), + resourceids.UserSpecifiedSegment("automationAccountName", "automationAccountValue"), + resourceids.StaticSegment("staticHybridRunbookWorkerGroups", "hybridRunbookWorkerGroups", "hybridRunbookWorkerGroups"), + resourceids.UserSpecifiedSegment("hybridRunbookWorkerGroupName", "hybridRunbookWorkerGroupValue"), + resourceids.StaticSegment("staticHybridRunbookWorkers", "hybridRunbookWorkers", "hybridRunbookWorkers"), + resourceids.UserSpecifiedSegment("hybridRunbookWorkerId", "hybridRunbookWorkerIdValue"), + } +} + +// String returns a human-readable description of this Hybrid Runbook Worker ID +func (id HybridRunbookWorkerId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Automation Account Name: %q", id.AutomationAccountName), + fmt.Sprintf("Hybrid Runbook Worker Group Name: %q", id.HybridRunbookWorkerGroupName), + fmt.Sprintf("Hybrid Runbook Worker: %q", id.HybridRunbookWorkerId), + } + return fmt.Sprintf("Hybrid Runbook Worker (%s)", strings.Join(components, "\n")) +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/automation/2021-06-22/hybridrunbookworker/id_hybridrunbookworkergroup.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/automation/2021-06-22/hybridrunbookworker/id_hybridrunbookworkergroup.go new file mode 100644 index 000000000000..a95e02358732 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/automation/2021-06-22/hybridrunbookworker/id_hybridrunbookworkergroup.go @@ -0,0 +1,137 @@ +package hybridrunbookworker + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +var _ resourceids.ResourceId = HybridRunbookWorkerGroupId{} + +// HybridRunbookWorkerGroupId is a struct representing the Resource ID for a Hybrid Runbook Worker Group +type HybridRunbookWorkerGroupId struct { + SubscriptionId string + ResourceGroupName string + AutomationAccountName string + HybridRunbookWorkerGroupName string +} + +// NewHybridRunbookWorkerGroupID returns a new HybridRunbookWorkerGroupId struct +func NewHybridRunbookWorkerGroupID(subscriptionId string, resourceGroupName string, automationAccountName string, hybridRunbookWorkerGroupName string) HybridRunbookWorkerGroupId { + return HybridRunbookWorkerGroupId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + AutomationAccountName: automationAccountName, + HybridRunbookWorkerGroupName: hybridRunbookWorkerGroupName, + } +} + +// ParseHybridRunbookWorkerGroupID parses 'input' into a HybridRunbookWorkerGroupId +func ParseHybridRunbookWorkerGroupID(input string) (*HybridRunbookWorkerGroupId, error) { + parser := resourceids.NewParserFromResourceIdType(HybridRunbookWorkerGroupId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := HybridRunbookWorkerGroupId{} + + 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.AutomationAccountName, ok = parsed.Parsed["automationAccountName"]; !ok { + return nil, fmt.Errorf("the segment 'automationAccountName' was not found in the resource id %q", input) + } + + if id.HybridRunbookWorkerGroupName, ok = parsed.Parsed["hybridRunbookWorkerGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'hybridRunbookWorkerGroupName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ParseHybridRunbookWorkerGroupIDInsensitively parses 'input' case-insensitively into a HybridRunbookWorkerGroupId +// note: this method should only be used for API response data and not user input +func ParseHybridRunbookWorkerGroupIDInsensitively(input string) (*HybridRunbookWorkerGroupId, error) { + parser := resourceids.NewParserFromResourceIdType(HybridRunbookWorkerGroupId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := HybridRunbookWorkerGroupId{} + + 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.AutomationAccountName, ok = parsed.Parsed["automationAccountName"]; !ok { + return nil, fmt.Errorf("the segment 'automationAccountName' was not found in the resource id %q", input) + } + + if id.HybridRunbookWorkerGroupName, ok = parsed.Parsed["hybridRunbookWorkerGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'hybridRunbookWorkerGroupName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ValidateHybridRunbookWorkerGroupID checks that 'input' can be parsed as a Hybrid Runbook Worker Group ID +func ValidateHybridRunbookWorkerGroupID(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 := ParseHybridRunbookWorkerGroupID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Hybrid Runbook Worker Group ID +func (id HybridRunbookWorkerGroupId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Automation/automationAccounts/%s/hybridRunbookWorkerGroups/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.AutomationAccountName, id.HybridRunbookWorkerGroupName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Hybrid Runbook Worker Group ID +func (id HybridRunbookWorkerGroupId) 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("staticMicrosoftAutomation", "Microsoft.Automation", "Microsoft.Automation"), + resourceids.StaticSegment("staticAutomationAccounts", "automationAccounts", "automationAccounts"), + resourceids.UserSpecifiedSegment("automationAccountName", "automationAccountValue"), + resourceids.StaticSegment("staticHybridRunbookWorkerGroups", "hybridRunbookWorkerGroups", "hybridRunbookWorkerGroups"), + resourceids.UserSpecifiedSegment("hybridRunbookWorkerGroupName", "hybridRunbookWorkerGroupValue"), + } +} + +// String returns a human-readable description of this Hybrid Runbook Worker Group ID +func (id HybridRunbookWorkerGroupId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Automation Account Name: %q", id.AutomationAccountName), + fmt.Sprintf("Hybrid Runbook Worker Group Name: %q", id.HybridRunbookWorkerGroupName), + } + return fmt.Sprintf("Hybrid Runbook Worker Group (%s)", strings.Join(components, "\n")) +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/automation/2021-06-22/hybridrunbookworker/method_create_autorest.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/automation/2021-06-22/hybridrunbookworker/method_create_autorest.go new file mode 100644 index 000000000000..218a09be0793 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/automation/2021-06-22/hybridrunbookworker/method_create_autorest.go @@ -0,0 +1,68 @@ +package hybridrunbookworker + +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 CreateOperationResponse struct { + HttpResponse *http.Response + Model *HybridRunbookWorker +} + +// Create ... +func (c HybridRunbookWorkerClient) Create(ctx context.Context, id HybridRunbookWorkerId, input HybridRunbookWorkerCreateParameters) (result CreateOperationResponse, err error) { + req, err := c.preparerForCreate(ctx, id, input) + if err != nil { + err = autorest.NewErrorWithError(err, "hybridrunbookworker.HybridRunbookWorkerClient", "Create", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "hybridrunbookworker.HybridRunbookWorkerClient", "Create", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForCreate(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "hybridrunbookworker.HybridRunbookWorkerClient", "Create", result.HttpResponse, "Failure responding to request") + return + } + + return +} + +// preparerForCreate prepares the Create request. +func (c HybridRunbookWorkerClient) preparerForCreate(ctx context.Context, id HybridRunbookWorkerId, input HybridRunbookWorkerCreateParameters) (*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)) +} + +// responderForCreate handles the response to the Create request. The method always +// closes the http.Response Body. +func (c HybridRunbookWorkerClient) responderForCreate(resp *http.Response) (result CreateOperationResponse, 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/automation/2021-06-22/hybridrunbookworker/method_delete_autorest.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/automation/2021-06-22/hybridrunbookworker/method_delete_autorest.go new file mode 100644 index 000000000000..b235ac83781a --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/automation/2021-06-22/hybridrunbookworker/method_delete_autorest.go @@ -0,0 +1,65 @@ +package hybridrunbookworker + +import ( + "context" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeleteOperationResponse struct { + HttpResponse *http.Response +} + +// Delete ... +func (c HybridRunbookWorkerClient) Delete(ctx context.Context, id HybridRunbookWorkerId) (result DeleteOperationResponse, err error) { + req, err := c.preparerForDelete(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "hybridrunbookworker.HybridRunbookWorkerClient", "Delete", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "hybridrunbookworker.HybridRunbookWorkerClient", "Delete", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForDelete(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "hybridrunbookworker.HybridRunbookWorkerClient", "Delete", result.HttpResponse, "Failure responding to request") + return + } + + return +} + +// preparerForDelete prepares the Delete request. +func (c HybridRunbookWorkerClient) preparerForDelete(ctx context.Context, id HybridRunbookWorkerId) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsDelete(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(id.ID()), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForDelete handles the response to the Delete request. The method always +// closes the http.Response Body. +func (c HybridRunbookWorkerClient) responderForDelete(resp *http.Response) (result DeleteOperationResponse, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusNoContent, http.StatusOK), + autorest.ByClosing()) + result.HttpResponse = resp + return +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/automation/2021-06-22/hybridrunbookworker/method_get_autorest.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/automation/2021-06-22/hybridrunbookworker/method_get_autorest.go new file mode 100644 index 000000000000..b0d3c06b45c7 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/automation/2021-06-22/hybridrunbookworker/method_get_autorest.go @@ -0,0 +1,67 @@ +package hybridrunbookworker + +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 *HybridRunbookWorker +} + +// Get ... +func (c HybridRunbookWorkerClient) Get(ctx context.Context, id HybridRunbookWorkerId) (result GetOperationResponse, err error) { + req, err := c.preparerForGet(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "hybridrunbookworker.HybridRunbookWorkerClient", "Get", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "hybridrunbookworker.HybridRunbookWorkerClient", "Get", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForGet(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "hybridrunbookworker.HybridRunbookWorkerClient", "Get", result.HttpResponse, "Failure responding to request") + return + } + + return +} + +// preparerForGet prepares the Get request. +func (c HybridRunbookWorkerClient) preparerForGet(ctx context.Context, id HybridRunbookWorkerId) (*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 HybridRunbookWorkerClient) 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/automation/2021-06-22/hybridrunbookworker/method_listbyhybridrunbookworkergroup_autorest.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/automation/2021-06-22/hybridrunbookworker/method_listbyhybridrunbookworkergroup_autorest.go new file mode 100644 index 000000000000..0772e8542c3f --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/automation/2021-06-22/hybridrunbookworker/method_listbyhybridrunbookworkergroup_autorest.go @@ -0,0 +1,215 @@ +package hybridrunbookworker + +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 ListByHybridRunbookWorkerGroupOperationResponse struct { + HttpResponse *http.Response + Model *[]HybridRunbookWorker + + nextLink *string + nextPageFunc func(ctx context.Context, nextLink string) (ListByHybridRunbookWorkerGroupOperationResponse, error) +} + +type ListByHybridRunbookWorkerGroupCompleteResult struct { + Items []HybridRunbookWorker +} + +func (r ListByHybridRunbookWorkerGroupOperationResponse) HasMore() bool { + return r.nextLink != nil +} + +func (r ListByHybridRunbookWorkerGroupOperationResponse) LoadMore(ctx context.Context) (resp ListByHybridRunbookWorkerGroupOperationResponse, err error) { + if !r.HasMore() { + err = fmt.Errorf("no more pages returned") + return + } + return r.nextPageFunc(ctx, *r.nextLink) +} + +type ListByHybridRunbookWorkerGroupOperationOptions struct { + Filter *string +} + +func DefaultListByHybridRunbookWorkerGroupOperationOptions() ListByHybridRunbookWorkerGroupOperationOptions { + return ListByHybridRunbookWorkerGroupOperationOptions{} +} + +func (o ListByHybridRunbookWorkerGroupOperationOptions) toHeaders() map[string]interface{} { + out := make(map[string]interface{}) + + return out +} + +func (o ListByHybridRunbookWorkerGroupOperationOptions) toQueryString() map[string]interface{} { + out := make(map[string]interface{}) + + if o.Filter != nil { + out["$filter"] = *o.Filter + } + + return out +} + +// ListByHybridRunbookWorkerGroup ... +func (c HybridRunbookWorkerClient) ListByHybridRunbookWorkerGroup(ctx context.Context, id HybridRunbookWorkerGroupId, options ListByHybridRunbookWorkerGroupOperationOptions) (resp ListByHybridRunbookWorkerGroupOperationResponse, err error) { + req, err := c.preparerForListByHybridRunbookWorkerGroup(ctx, id, options) + if err != nil { + err = autorest.NewErrorWithError(err, "hybridrunbookworker.HybridRunbookWorkerClient", "ListByHybridRunbookWorkerGroup", nil, "Failure preparing request") + return + } + + resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "hybridrunbookworker.HybridRunbookWorkerClient", "ListByHybridRunbookWorkerGroup", resp.HttpResponse, "Failure sending request") + return + } + + resp, err = c.responderForListByHybridRunbookWorkerGroup(resp.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "hybridrunbookworker.HybridRunbookWorkerClient", "ListByHybridRunbookWorkerGroup", resp.HttpResponse, "Failure responding to request") + return + } + return +} + +// ListByHybridRunbookWorkerGroupComplete retrieves all of the results into a single object +func (c HybridRunbookWorkerClient) ListByHybridRunbookWorkerGroupComplete(ctx context.Context, id HybridRunbookWorkerGroupId, options ListByHybridRunbookWorkerGroupOperationOptions) (ListByHybridRunbookWorkerGroupCompleteResult, error) { + return c.ListByHybridRunbookWorkerGroupCompleteMatchingPredicate(ctx, id, options, HybridRunbookWorkerOperationPredicate{}) +} + +// ListByHybridRunbookWorkerGroupCompleteMatchingPredicate retrieves all of the results and then applied the predicate +func (c HybridRunbookWorkerClient) ListByHybridRunbookWorkerGroupCompleteMatchingPredicate(ctx context.Context, id HybridRunbookWorkerGroupId, options ListByHybridRunbookWorkerGroupOperationOptions, predicate HybridRunbookWorkerOperationPredicate) (resp ListByHybridRunbookWorkerGroupCompleteResult, err error) { + items := make([]HybridRunbookWorker, 0) + + page, err := c.ListByHybridRunbookWorkerGroup(ctx, id, options) + 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 := ListByHybridRunbookWorkerGroupCompleteResult{ + Items: items, + } + return out, nil +} + +// preparerForListByHybridRunbookWorkerGroup prepares the ListByHybridRunbookWorkerGroup request. +func (c HybridRunbookWorkerClient) preparerForListByHybridRunbookWorkerGroup(ctx context.Context, id HybridRunbookWorkerGroupId, options ListByHybridRunbookWorkerGroupOperationOptions) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + for k, v := range options.toQueryString() { + queryParameters[k] = autorest.Encode("query", v) + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithHeaders(options.toHeaders()), + autorest.WithPath(fmt.Sprintf("%s/hybridRunbookWorkers", id.ID())), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// preparerForListByHybridRunbookWorkerGroupWithNextLink prepares the ListByHybridRunbookWorkerGroup request with the given nextLink token. +func (c HybridRunbookWorkerClient) preparerForListByHybridRunbookWorkerGroupWithNextLink(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)) +} + +// responderForListByHybridRunbookWorkerGroup handles the response to the ListByHybridRunbookWorkerGroup request. The method always +// closes the http.Response Body. +func (c HybridRunbookWorkerClient) responderForListByHybridRunbookWorkerGroup(resp *http.Response) (result ListByHybridRunbookWorkerGroupOperationResponse, err error) { + type page struct { + Values []HybridRunbookWorker `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 ListByHybridRunbookWorkerGroupOperationResponse, err error) { + req, err := c.preparerForListByHybridRunbookWorkerGroupWithNextLink(ctx, nextLink) + if err != nil { + err = autorest.NewErrorWithError(err, "hybridrunbookworker.HybridRunbookWorkerClient", "ListByHybridRunbookWorkerGroup", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "hybridrunbookworker.HybridRunbookWorkerClient", "ListByHybridRunbookWorkerGroup", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForListByHybridRunbookWorkerGroup(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "hybridrunbookworker.HybridRunbookWorkerClient", "ListByHybridRunbookWorkerGroup", result.HttpResponse, "Failure responding to request") + return + } + + return + } + } + return +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/automation/2021-06-22/hybridrunbookworker/method_move_autorest.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/automation/2021-06-22/hybridrunbookworker/method_move_autorest.go new file mode 100644 index 000000000000..2e426f012234 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/automation/2021-06-22/hybridrunbookworker/method_move_autorest.go @@ -0,0 +1,67 @@ +package hybridrunbookworker + +import ( + "context" + "fmt" + "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 MoveOperationResponse struct { + HttpResponse *http.Response +} + +// Move ... +func (c HybridRunbookWorkerClient) Move(ctx context.Context, id HybridRunbookWorkerId, input HybridRunbookWorkerMoveParameters) (result MoveOperationResponse, err error) { + req, err := c.preparerForMove(ctx, id, input) + if err != nil { + err = autorest.NewErrorWithError(err, "hybridrunbookworker.HybridRunbookWorkerClient", "Move", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "hybridrunbookworker.HybridRunbookWorkerClient", "Move", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForMove(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "hybridrunbookworker.HybridRunbookWorkerClient", "Move", result.HttpResponse, "Failure responding to request") + return + } + + return +} + +// preparerForMove prepares the Move request. +func (c HybridRunbookWorkerClient) preparerForMove(ctx context.Context, id HybridRunbookWorkerId, input HybridRunbookWorkerMoveParameters) (*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/move", id.ID())), + autorest.WithJSON(input), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForMove handles the response to the Move request. The method always +// closes the http.Response Body. +func (c HybridRunbookWorkerClient) responderForMove(resp *http.Response) (result MoveOperationResponse, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByClosing()) + result.HttpResponse = resp + return +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/automation/2021-06-22/hybridrunbookworker/model_hybridrunbookworker.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/automation/2021-06-22/hybridrunbookworker/model_hybridrunbookworker.go new file mode 100644 index 000000000000..2568120011c9 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/automation/2021-06-22/hybridrunbookworker/model_hybridrunbookworker.go @@ -0,0 +1,16 @@ +package hybridrunbookworker + +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 HybridRunbookWorker struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *HybridRunbookWorkerProperties `json:"properties,omitempty"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/automation/2021-06-22/hybridrunbookworker/model_hybridrunbookworkercreateorupdateparameters.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/automation/2021-06-22/hybridrunbookworker/model_hybridrunbookworkercreateorupdateparameters.go new file mode 100644 index 000000000000..47c4d3a052d9 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/automation/2021-06-22/hybridrunbookworker/model_hybridrunbookworkercreateorupdateparameters.go @@ -0,0 +1,8 @@ +package hybridrunbookworker + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type HybridRunbookWorkerCreateOrUpdateParameters struct { + VmResourceId *string `json:"vmResourceId,omitempty"` +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/automation/2021-06-22/hybridrunbookworker/model_hybridrunbookworkercreateparameters.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/automation/2021-06-22/hybridrunbookworker/model_hybridrunbookworkercreateparameters.go new file mode 100644 index 000000000000..e4f54e2e4c2c --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/automation/2021-06-22/hybridrunbookworker/model_hybridrunbookworkercreateparameters.go @@ -0,0 +1,9 @@ +package hybridrunbookworker + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type HybridRunbookWorkerCreateParameters struct { + Name *string `json:"name,omitempty"` + Properties HybridRunbookWorkerCreateOrUpdateParameters `json:"properties"` +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/automation/2021-06-22/hybridrunbookworker/model_hybridrunbookworkermoveparameters.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/automation/2021-06-22/hybridrunbookworker/model_hybridrunbookworkermoveparameters.go new file mode 100644 index 000000000000..6b3d154457be --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/automation/2021-06-22/hybridrunbookworker/model_hybridrunbookworkermoveparameters.go @@ -0,0 +1,8 @@ +package hybridrunbookworker + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type HybridRunbookWorkerMoveParameters struct { + HybridRunbookWorkerGroupName *string `json:"hybridRunbookWorkerGroupName,omitempty"` +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/automation/2021-06-22/hybridrunbookworker/model_hybridrunbookworkerproperties.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/automation/2021-06-22/hybridrunbookworker/model_hybridrunbookworkerproperties.go new file mode 100644 index 000000000000..a6c49147c5f4 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/automation/2021-06-22/hybridrunbookworker/model_hybridrunbookworkerproperties.go @@ -0,0 +1,43 @@ +package hybridrunbookworker + +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 HybridRunbookWorkerProperties struct { + Ip *string `json:"ip,omitempty"` + LastSeenDateTime *string `json:"lastSeenDateTime,omitempty"` + RegisteredDateTime *string `json:"registeredDateTime,omitempty"` + VmResourceId *string `json:"vmResourceId,omitempty"` + WorkerName *string `json:"workerName,omitempty"` + WorkerType *WorkerType `json:"workerType,omitempty"` +} + +func (o *HybridRunbookWorkerProperties) GetLastSeenDateTimeAsTime() (*time.Time, error) { + if o.LastSeenDateTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.LastSeenDateTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *HybridRunbookWorkerProperties) SetLastSeenDateTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.LastSeenDateTime = &formatted +} + +func (o *HybridRunbookWorkerProperties) GetRegisteredDateTimeAsTime() (*time.Time, error) { + if o.RegisteredDateTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.RegisteredDateTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *HybridRunbookWorkerProperties) SetRegisteredDateTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.RegisteredDateTime = &formatted +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/automation/2021-06-22/hybridrunbookworker/predicates.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/automation/2021-06-22/hybridrunbookworker/predicates.go new file mode 100644 index 000000000000..efb02cb00189 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/automation/2021-06-22/hybridrunbookworker/predicates.go @@ -0,0 +1,24 @@ +package hybridrunbookworker + +type HybridRunbookWorkerOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p HybridRunbookWorkerOperationPredicate) Matches(input HybridRunbookWorker) 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/automation/2021-06-22/hybridrunbookworker/version.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/automation/2021-06-22/hybridrunbookworker/version.go new file mode 100644 index 000000000000..bb33a40f3174 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/automation/2021-06-22/hybridrunbookworker/version.go @@ -0,0 +1,12 @@ +package hybridrunbookworker + +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 = "2021-06-22" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/hybridrunbookworker/%s", defaultApiVersion) +} diff --git a/website/docs/r/automation_hybrid_runbook_worker.html.markdown b/website/docs/r/automation_hybrid_runbook_worker.html.markdown new file mode 100644 index 000000000000..bc703e834383 --- /dev/null +++ b/website/docs/r/automation_hybrid_runbook_worker.html.markdown @@ -0,0 +1,69 @@ +--- +subcategory: "Automation" +layout: "azurerm" +page_title: "Azure Resource Manager: azurerm_automation_hybrid_runbook_worker" +description: |- + Manages a Automation. +--- + +# azurerm_automation_hybrid_runbook_worker + +Manages a Automation Hybrid Runbook Worker. + +## Example Usage + +```hcl +resource "azurerm_automation_hybrid_runbook_worker" "example" { + resource_group_name = azurerm_resource_group.test.name + automation_account_name = azurerm_automation_account.test.name + worker_group_name = azurerm_automation_hybrid_runbook_worker_group.test.name + vm_resource_id = azurerm_linux_virtual_machine.test.id + worker_id = "00000000-0000-0000-0000-000000000000" +} +``` + +## Arguments Reference + +The following arguments are supported: + +* `resource_group_name` - (Required) The name of the Resource Group where the Automation should exist. Changing this forces a new Automation to be created. + +* `automation_account_name` - (Required) The name of the automation account in which the Hybrid Worker is created. Changing this forces a new resource to be created. + +* `worker_group_name` - (Required) The name of the HybridWorker Group. Changing this forces a new Automation to be created. + +* `worker_id` - (Required) The ID of the HybridWorker. Changing this forces a new Automation to be created. + +* `vm_resource_id` - (Required) The ID of the virtual machine used for this HybridWorker. Changing this forces a new Automation to be created. + +## Attributes Reference + +In addition to the Arguments listed above - the following Attributes are exported: + +* `id` - The ID of the Automation Hybrid Runbook Worker. + +* `ip` - The IP address of assigned machine . + +* `last_seen_date_time` - Last Heartbeat from the Worker. + +* `registered_date_time` - The registration time of the worker machine. + +* `worker_name` - The name of HybridWorker. + +* `worker_type` - The type of the HybridWorker, the possible values are `HybridV1` and `HybridV2`. + +## 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 Automation. +* `read` - (Defaults to 5 minutes) Used when retrieving the Automation. +* `delete` - (Defaults to 10 minutes) Used when deleting the Automation. + +## Import + +Automations can be imported using the `resource id`, e.g. + +```shell +terraform import azurerm_automation_hybrid_runbook_worker.example /subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/group1/providers/Microsoft.Automation/automationAccounts/account1/hybridRunbookWorkerGroups/group1/hybridRunbookWorkers/00000000-0000-0000-0000-000000000000 +``` \ No newline at end of file