From f56f9250d8887881cc2f7a69affc3e944d167e30 Mon Sep 17 00:00:00 2001 From: ziyeqf <51212351+ziyeqf@users.noreply.github.com> Date: Mon, 29 May 2023 15:15:15 +0800 Subject: [PATCH 01/15] New Resource: `azurerm_site_recovery_vmware_replicated_vm` Signed-off-by: ziyeqf <51212351+ziyeqf@users.noreply.github.com> --- internal/clients/client.go | 4 +- .../method_getallrunasaccountsinsite.go | 85 ++ .../azuresdkhacks/model_vmwarerunasaccount.go | 18 + .../recoveryservices/client/client.go | 24 +- .../services/recoveryservices/registration.go | 1 + ..._recovery_vmware_replicated_vm_resource.go | 1185 +++++++++++++++++ ...very_vmware_replicated_vm_resource_test.go | 147 ++ .../migrate/2020-01-01/machines/README.md | 85 ++ .../migrate/2020-01-01/machines/client.go | 26 + .../migrate/2020-01-01/machines/constants.go | 63 + .../2020-01-01/machines/id_vmwaresite.go | 127 ++ .../machines/method_getallmachinesinsite.go | 129 ++ .../2020-01-01/machines/method_getmachine.go | 52 + .../machines/method_startmachine.go | 48 + .../2020-01-01/machines/method_stopmachine.go | 48 + .../2020-01-01/machines/model_application.go | 10 + .../2020-01-01/machines/model_appsandroles.go | 16 + .../machines/model_biztalkserver.go | 9 + .../machines/model_exchangeserver.go | 12 + .../2020-01-01/machines/model_feature.go | 11 + .../machines/model_guestosdetails.go | 10 + .../machines/model_healtherrordetails.go | 16 + .../machines/model_operatingsystem.go | 10 + .../machines/model_otherdatabase.go | 10 + .../machines/model_sharepointserver.go | 11 + .../2020-01-01/machines/model_sqlserver.go | 13 + .../2020-01-01/machines/model_systemcenter.go | 10 + .../2020-01-01/machines/model_vmwaredisk.go | 17 + .../machines/model_vmwaremachine.go | 11 + .../machines/model_vmwaremachineproperties.go | 73 + .../machines/model_vmwarenetworkadapter.go | 13 + .../machines/model_webapplication.go | 13 + .../migrate/2020-01-01/machines/predicates.go | 27 + .../migrate/2020-01-01/machines/version.go | 12 + .../2020-01-01/runasaccounts/README.md | 53 + .../2020-01-01/runasaccounts/client.go | 26 + .../2020-01-01/runasaccounts/constants.go | 63 + .../2020-01-01/runasaccounts/id_vmwaresite.go | 127 ++ .../method_getallrunasaccountsinsite.go | 89 ++ .../runasaccounts/method_getrunasaccount.go | 52 + .../model_runasaccountproperties.go | 11 + .../runasaccounts/model_vmwarerunasaccount.go | 11 + .../2020-01-01/runasaccounts/predicates.go | 27 + .../2020-01-01/runasaccounts/version.go | 12 + .../replicationprotectableitems/README.md | 53 + .../replicationprotectableitems/client.go | 18 + .../replicationprotectableitems/constants.go | 65 + .../id_replicationprotectableitem.go | 166 +++ .../id_replicationprotectioncontainer.go | 153 +++ .../method_get_autorest.go | 68 + ...eplicationprotectioncontainers_autorest.go | 220 +++ .../model_configurationsettings.go | 64 + .../model_diskdetails.go | 11 + .../model_diskvolumedetails.go | 9 + .../model_healtherror.go | 40 + .../model_hypervvirtualmachinedetails.go | 48 + .../model_inmagediskdetails.go | 13 + .../model_innerhealtherror.go | 39 + .../model_osdetails.go | 13 + .../model_protectableitem.go | 12 + .../model_protectableitemproperties.go | 50 + .../model_replicationgroupdetails.go | 40 + .../model_vmmvirtualmachinedetails.go | 48 + .../model_vmwarevirtualmachinedetails.go | 50 + .../replicationprotectableitems/predicates.go | 32 + .../replicationprotectableitems/version.go | 12 + vendor/modules.txt | 3 + ...ecovery_vmware_replicated_vm.html.markdown | 217 +++ 68 files changed, 4258 insertions(+), 3 deletions(-) create mode 100644 internal/services/recoveryservices/azuresdkhacks/method_getallrunasaccountsinsite.go create mode 100644 internal/services/recoveryservices/azuresdkhacks/model_vmwarerunasaccount.go create mode 100644 internal/services/recoveryservices/site_recovery_vmware_replicated_vm_resource.go create mode 100644 internal/services/recoveryservices/site_recovery_vmware_replicated_vm_resource_test.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/migrate/2020-01-01/machines/README.md create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/migrate/2020-01-01/machines/client.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/migrate/2020-01-01/machines/constants.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/migrate/2020-01-01/machines/id_vmwaresite.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/migrate/2020-01-01/machines/method_getallmachinesinsite.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/migrate/2020-01-01/machines/method_getmachine.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/migrate/2020-01-01/machines/method_startmachine.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/migrate/2020-01-01/machines/method_stopmachine.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/migrate/2020-01-01/machines/model_application.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/migrate/2020-01-01/machines/model_appsandroles.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/migrate/2020-01-01/machines/model_biztalkserver.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/migrate/2020-01-01/machines/model_exchangeserver.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/migrate/2020-01-01/machines/model_feature.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/migrate/2020-01-01/machines/model_guestosdetails.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/migrate/2020-01-01/machines/model_healtherrordetails.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/migrate/2020-01-01/machines/model_operatingsystem.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/migrate/2020-01-01/machines/model_otherdatabase.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/migrate/2020-01-01/machines/model_sharepointserver.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/migrate/2020-01-01/machines/model_sqlserver.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/migrate/2020-01-01/machines/model_systemcenter.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/migrate/2020-01-01/machines/model_vmwaredisk.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/migrate/2020-01-01/machines/model_vmwaremachine.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/migrate/2020-01-01/machines/model_vmwaremachineproperties.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/migrate/2020-01-01/machines/model_vmwarenetworkadapter.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/migrate/2020-01-01/machines/model_webapplication.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/migrate/2020-01-01/machines/predicates.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/migrate/2020-01-01/machines/version.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/migrate/2020-01-01/runasaccounts/README.md create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/migrate/2020-01-01/runasaccounts/client.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/migrate/2020-01-01/runasaccounts/constants.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/migrate/2020-01-01/runasaccounts/id_vmwaresite.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/migrate/2020-01-01/runasaccounts/method_getallrunasaccountsinsite.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/migrate/2020-01-01/runasaccounts/method_getrunasaccount.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/migrate/2020-01-01/runasaccounts/model_runasaccountproperties.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/migrate/2020-01-01/runasaccounts/model_vmwarerunasaccount.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/migrate/2020-01-01/runasaccounts/predicates.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/migrate/2020-01-01/runasaccounts/version.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2022-10-01/replicationprotectableitems/README.md create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2022-10-01/replicationprotectableitems/client.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2022-10-01/replicationprotectableitems/constants.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2022-10-01/replicationprotectableitems/id_replicationprotectableitem.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2022-10-01/replicationprotectableitems/id_replicationprotectioncontainer.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2022-10-01/replicationprotectableitems/method_get_autorest.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2022-10-01/replicationprotectableitems/method_listbyreplicationprotectioncontainers_autorest.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2022-10-01/replicationprotectableitems/model_configurationsettings.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2022-10-01/replicationprotectableitems/model_diskdetails.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2022-10-01/replicationprotectableitems/model_diskvolumedetails.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2022-10-01/replicationprotectableitems/model_healtherror.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2022-10-01/replicationprotectableitems/model_hypervvirtualmachinedetails.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2022-10-01/replicationprotectableitems/model_inmagediskdetails.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2022-10-01/replicationprotectableitems/model_innerhealtherror.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2022-10-01/replicationprotectableitems/model_osdetails.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2022-10-01/replicationprotectableitems/model_protectableitem.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2022-10-01/replicationprotectableitems/model_protectableitemproperties.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2022-10-01/replicationprotectableitems/model_replicationgroupdetails.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2022-10-01/replicationprotectableitems/model_vmmvirtualmachinedetails.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2022-10-01/replicationprotectableitems/model_vmwarevirtualmachinedetails.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2022-10-01/replicationprotectableitems/predicates.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2022-10-01/replicationprotectableitems/version.go create mode 100644 website/docs/r/site_recovery_vmware_replicated_vm.html.markdown diff --git a/internal/clients/client.go b/internal/clients/client.go index a859f87ebf87..bffb685538a0 100644 --- a/internal/clients/client.go +++ b/internal/clients/client.go @@ -473,7 +473,9 @@ func (client *Client) Build(ctx context.Context, o *common.ClientOptions) error return fmt.Errorf("building clients for PrivateDnsResolver: %+v", err) } client.Purview = purview.NewClient(o) - client.RecoveryServices = recoveryServices.NewClient(o) + if client.RecoveryServices, err = recoveryServices.NewClient(o); err != nil { + return fmt.Errorf("building clients for RecoveryServices: %+v", err) + } if client.Redis, err = redis.NewClient(o); err != nil { return fmt.Errorf("building clients for Redis: %+v", err) } diff --git a/internal/services/recoveryservices/azuresdkhacks/method_getallrunasaccountsinsite.go b/internal/services/recoveryservices/azuresdkhacks/method_getallrunasaccountsinsite.go new file mode 100644 index 000000000000..6e3ba99c97ea --- /dev/null +++ b/internal/services/recoveryservices/azuresdkhacks/method_getallrunasaccountsinsite.go @@ -0,0 +1,85 @@ +package azuresdkhacks + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/resource-manager/migrate/2020-01-01/runasaccounts" + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// workaround for https://github.com/Azure/azure-rest-api-specs/issues/24712 +// TODO 4.0: check if this could be removed + +type RunAsAccountsClient struct { + Client *resourcemanager.Client +} + +type GetAllRunAsAccountsInSiteOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]VMwareRunAsAccount +} + +type GetAllRunAsAccountsInSiteCompleteResult struct { + Items []VMwareRunAsAccount +} + +// GetAllRunAsAccountsInSite ... +func (c RunAsAccountsClient) GetAllRunAsAccountsInSite(ctx context.Context, id runasaccounts.VMwareSiteId) (result GetAllRunAsAccountsInSiteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/runAsAccounts", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]VMwareRunAsAccount `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// GetAllRunAsAccountsInSiteComplete retrieves all the results into a single object +func (c RunAsAccountsClient) GetAllRunAsAccountsInSiteComplete(ctx context.Context, id runasaccounts.VMwareSiteId) (GetAllRunAsAccountsInSiteCompleteResult, error) { + items := make([]VMwareRunAsAccount, 0) + + resp, err := c.GetAllRunAsAccountsInSite(ctx, id) + if err != nil { + err = fmt.Errorf("loading results: %+v", err) + return GetAllRunAsAccountsInSiteCompleteResult{}, err + } + if resp.Model != nil { + for _, v := range *resp.Model { + items = append(items, v) + } + } + + return GetAllRunAsAccountsInSiteCompleteResult{Items: items}, nil +} diff --git a/internal/services/recoveryservices/azuresdkhacks/model_vmwarerunasaccount.go b/internal/services/recoveryservices/azuresdkhacks/model_vmwarerunasaccount.go new file mode 100644 index 000000000000..e919962cbb07 --- /dev/null +++ b/internal/services/recoveryservices/azuresdkhacks/model_vmwarerunasaccount.go @@ -0,0 +1,18 @@ +package azuresdkhacks + +import "github.com/hashicorp/go-azure-sdk/resource-manager/migrate/2020-01-01/runasaccounts" + +type VMwareRunAsAccount struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *RunAsAccountProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} + +type RunAsAccountProperties struct { + CreatedTimestamp *string `json:"createdTimestamp,omitempty"` + CredentialType *runasaccounts.CredentialType `json:"credentialType,omitempty"` + DisplayName *string `json:"displayName,omitempty"` + UpdatedTimestamp *string `json:"updatedTimestamp,omitempty"` + ApplianceName *string `json:"applianceName,omitempty"` +} diff --git a/internal/services/recoveryservices/client/client.go b/internal/services/recoveryservices/client/client.go index 7aa0a2353be5..a01afe58a70f 100644 --- a/internal/services/recoveryservices/client/client.go +++ b/internal/services/recoveryservices/client/client.go @@ -4,7 +4,11 @@ package client import ( + "fmt" + "github.com/Azure/azure-sdk-for-go/services/recoveryservices/mgmt/2021-12-01/backup" // nolint: staticcheck + vmwaremachines "github.com/hashicorp/go-azure-sdk/resource-manager/migrate/2020-01-01/machines" + vmwarerunasaccounts "github.com/hashicorp/go-azure-sdk/resource-manager/migrate/2020-01-01/runasaccounts" "github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservices/2022-10-01/vaults" "github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicesbackup/2023-02-01/backupprotectableitems" "github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicesbackup/2023-02-01/backupprotecteditems" @@ -54,9 +58,11 @@ type Client struct { ReplicationRecoveryPlansClient *replicationrecoveryplans.ReplicationRecoveryPlansClient ReplicationNetworksClient *replicationnetworks.ReplicationNetworksClient ResourceGuardProxyClient *resourceguardproxy.ResourceGuardProxyClient + VMWareMachinesClient *vmwaremachines.MachinesClient + VMWareRunAsAccountsClient *vmwarerunasaccounts.RunAsAccountsClient } -func NewClient(o *common.ClientOptions) *Client { +func NewClient(o *common.ClientOptions) (*Client, error) { vaultConfigsClient := backupresourcevaultconfigs.NewBackupResourceVaultConfigsClientWithBaseURI(o.ResourceManagerEndpoint) o.ConfigureClient(&vaultConfigsClient.Client, o.ResourceManagerAuthorizer) @@ -126,6 +132,18 @@ func NewClient(o *common.ClientOptions) *Client { resourceGuardProxyClient := resourceguardproxy.NewResourceGuardProxyClientWithBaseURI(o.ResourceManagerEndpoint) o.ConfigureClient(&resourceGuardProxyClient.Client, o.ResourceManagerAuthorizer) + vmwareMachinesClient, err := vmwaremachines.NewMachinesClientWithBaseURI(o.Environment.ResourceManager) + if err != nil { + return nil, fmt.Errorf("building VMWare Machine client: %+v", err) + } + o.Configure(vmwareMachinesClient.Client, o.Authorizers.ResourceManager) + + vmwareRunAsAccountsClient, err := vmwarerunasaccounts.NewRunAsAccountsClientWithBaseURI(o.Environment.ResourceManager) + if err != nil { + return nil, fmt.Errorf("building VMWare Machine client: %+v", err) + } + o.Configure(vmwareRunAsAccountsClient.Client, o.Authorizers.ResourceManager) + return &Client{ ProtectableItemsClient: &protectableItemsClient, ProtectedItemsClient: &protectedItemsClient, @@ -150,5 +168,7 @@ func NewClient(o *common.ClientOptions) *Client { ReplicationRecoveryPlansClient: &replicationRecoveryPlanClient, ReplicationNetworksClient: &replicationNetworksClient, ResourceGuardProxyClient: &resourceGuardProxyClient, - } + VMWareMachinesClient: vmwareMachinesClient, + VMWareRunAsAccountsClient: vmwareRunAsAccountsClient, + }, nil } diff --git a/internal/services/recoveryservices/registration.go b/internal/services/recoveryservices/registration.go index d62133fc9928..27bff567db10 100644 --- a/internal/services/recoveryservices/registration.go +++ b/internal/services/recoveryservices/registration.go @@ -36,6 +36,7 @@ func (r Registration) Resources() []sdk.Resource { VMWareReplicationPolicyResource{}, VMWareReplicationPolicyAssociationResource{}, VaultGuardProxyResource{}, + VMWareReplicatedVmResource{}, } } diff --git a/internal/services/recoveryservices/site_recovery_vmware_replicated_vm_resource.go b/internal/services/recoveryservices/site_recovery_vmware_replicated_vm_resource.go new file mode 100644 index 000000000000..0d474785f24c --- /dev/null +++ b/internal/services/recoveryservices/site_recovery_vmware_replicated_vm_resource.go @@ -0,0 +1,1185 @@ +package recoveryservices + +import ( + "context" + "fmt" + "net/http" + "net/url" + "strconv" + "strings" + "time" + + "github.com/Azure/azure-sdk-for-go/services/recoveryservices/mgmt/2018-07-10/siterecovery" // nolint: staticcheck + "github.com/hashicorp/go-azure-helpers/lang/pointer" + "github.com/hashicorp/go-azure-helpers/lang/response" + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" + "github.com/hashicorp/go-azure-sdk/resource-manager/compute/2021-11-01/availabilitysets" + "github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-01/proximityplacementgroups" + "github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-02/diskencryptionsets" + vmwaremachines "github.com/hashicorp/go-azure-sdk/resource-manager/migrate/2020-01-01/machines" + vmwarerunasaccounts "github.com/hashicorp/go-azure-sdk/resource-manager/migrate/2020-01-01/runasaccounts" + "github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2022-10-01/replicationfabrics" + "github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2022-10-01/replicationpolicies" + "github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2022-10-01/replicationprotecteditems" + "github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2022-10-01/replicationprotectioncontainers" + "github.com/hashicorp/go-azure-sdk/resource-manager/storage/2022-05-01/storageaccounts" + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/hashicorp/terraform-provider-azurerm/helpers/azure" + "github.com/hashicorp/terraform-provider-azurerm/helpers/tf" + "github.com/hashicorp/terraform-provider-azurerm/internal/sdk" + "github.com/hashicorp/terraform-provider-azurerm/internal/services/recoveryservices/azuresdkhacks" + validateResourceGroup "github.com/hashicorp/terraform-provider-azurerm/internal/services/resource/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" + "github.com/hashicorp/terraform-provider-azurerm/utils" +) + +type installAccountType string + +const lincreds installAccountType = "lincreds" +const v2arcmlab installAccountType = "v2arcmlab" +const wincreds installAccountType = "wincreds" + +type IncludedDiskModel struct { + DiskId string `tfschema:"disk_id"` + LogStorageAccountId string `tfschema:"log_storage_account_id"` + TargetDiskEncryptionSetId string `tfschema:"target_disk_encryption_set_id"` + TargetDiskType string `tfschema:"target_disk_type"` +} + +type NetworkInterfaceModel struct { + SourceMacAddress string `tfschema:"source_mac_address"` + TargetStaticIp string `tfschema:"target_static_ip"` + TargetSubnetName string `tfschema:"target_subnet_name"` + TestSubnetName string `tfschema:"test_subnet_name"` + IsPrimary bool `tfschema:"is_primary"` +} + +type SiteRecoveryReplicatedVmVMwareModel struct { + Name string `tfschema:"name"` + RecoveryVaultId string `tfschema:"recovery_vault_id"` + SourceVmName string `tfschema:"source_vm_name"` + ApplianceName string `tfschema:"appliance_name"` + RecoveryReplicationPolicyId string `tfschema:"recovery_replication_policy_id"` + LicenseType string `tfschema:"license_type"` + TargetResourceGroupId string `tfschema:"target_resource_group_id"` + TargetVmName string `tfschema:"target_vm_name"` + MultiVmGroupName string `tfschema:"multi_vm_group_name"` + TargetProximityPlacementGroupId string `tfschema:"target_proximity_placement_group_id"` + TargetVmSize string `tfschema:"target_vm_size"` + TargetAvailabilitySetId string `tfschema:"target_availability_set_id"` + TargetZone string `tfschema:"target_zone"` + TargetNetworkId string `tfschema:"target_network_id"` + TestNetworkId string `tfschema:"test_network_id"` + TargetBootDiagnosticsStorageAccountId string `tfschema:"target_boot_diagnostics_storage_account_id"` + DiskToInclude []IncludedDiskModel `tfschema:"managed_disk"` + NetworkInterface []NetworkInterfaceModel `tfschema:"network_interface"` + CredentialType string `tfschema:"credential_type"` + DefaultLogStorageAccountId string `tfschema:"default_log_storage_account_id"` + DefaultRecoveryDiskType string `tfschema:"default_recovery_disk_type"` + DefaultTargetDiskEncryptionSetId string `tfschema:"default_target_disk_encryption_set_id"` +} + +type VMWareReplicatedVmResource struct{} + +func (s VMWareReplicatedVmResource) ModelObject() interface{} { + return &SiteRecoveryReplicatedVmVMwareModel{} +} + +func (s VMWareReplicatedVmResource) ResourceType() string { + return "azurerm_site_recovery_vmware_replicated_vm" +} + +func (s VMWareReplicatedVmResource) IDValidationFunc() pluginsdk.SchemaValidateFunc { + return replicationprotecteditems.ValidateReplicationProtectedItemID +} + +var _ sdk.ResourceWithUpdate = VMWareReplicatedVmResource{} +var _ sdk.ResourceWithCustomizeDiff = VMWareReplicatedVmResource{} + +func (s VMWareReplicatedVmResource) Arguments() map[string]*pluginsdk.Schema { + return map[string]*pluginsdk.Schema{ + "name": { + Type: pluginsdk.TypeString, + Required: true, + ForceNew: true, + ValidateFunc: validation.StringIsNotEmpty, + }, + + "recovery_vault_id": { + Type: pluginsdk.TypeString, + Required: true, + ForceNew: true, + ValidateFunc: replicationprotecteditems.ValidateVaultID, + }, + + "source_vm_name": { + Type: pluginsdk.TypeString, + Required: true, + ForceNew: true, + ValidateFunc: validation.StringIsNotEmpty, + }, + + "appliance_name": { + Type: pluginsdk.TypeString, + Required: true, + ForceNew: true, + ValidateFunc: validation.StringIsNotEmpty, + }, + + "recovery_replication_policy_id": { + Type: pluginsdk.TypeString, + Required: true, + ForceNew: true, + ValidateFunc: azure.ValidateResourceID, + DiffSuppressFunc: suppress.CaseDifference, + }, + + "credential_type": { + Type: pluginsdk.TypeString, + Optional: true, + ValidateFunc: validation.StringInSlice([]string{ + string(lincreds), + string(v2arcmlab), + string(wincreds), + }, false), + }, + + "license_type": { + Type: pluginsdk.TypeString, + Optional: true, + Default: string(replicationprotecteditems.LicenseTypeNotSpecified), + ValidateFunc: validation.StringInSlice(replicationprotecteditems.PossibleValuesForLicenseType(), false), + }, + + "target_resource_group_id": { + Type: pluginsdk.TypeString, + Required: true, + ForceNew: true, + ValidateFunc: validateResourceGroup.ResourceGroupID, + DiffSuppressFunc: suppress.CaseDifference, + }, + + "target_vm_name": { + Type: pluginsdk.TypeString, + Required: true, + ForceNew: true, + ValidateFunc: validation.StringIsNotEmpty, + }, + + "default_log_storage_account_id": { + Type: pluginsdk.TypeString, + Optional: true, + ValidateFunc: storageaccounts.ValidateStorageAccountID, + AtLeastOneOf: []string{"managed_disk", "default_log_storage_account_id"}, + }, + + "default_recovery_disk_type": { // only works in creation and will not be returned from service + Type: pluginsdk.TypeString, + Optional: true, + AtLeastOneOf: []string{"managed_disk", "default_recovery_disk_type"}, + ValidateFunc: validation.StringInSlice(replicationprotecteditems.PossibleValuesForDiskAccountType(), false), + }, + + "default_target_disk_encryption_set_id": { + Type: pluginsdk.TypeString, + Optional: true, + ConflictsWith: []string{"managed_disk"}, + ValidateFunc: diskencryptionsets.ValidateDiskEncryptionSetID, + }, + + "multi_vm_group_name": { + Type: pluginsdk.TypeString, + Optional: true, + ValidateFunc: validation.StringIsNotEmpty, + }, + + "target_proximity_placement_group_id": { + Type: pluginsdk.TypeString, + Optional: true, + ValidateFunc: proximityplacementgroups.ValidateProximityPlacementGroupID, + }, + + "target_vm_size": { + Type: pluginsdk.TypeString, + Optional: true, + ValidateFunc: validation.StringIsNotEmpty, + }, + + "target_availability_set_id": { + Type: pluginsdk.TypeString, + Optional: true, + ValidateFunc: availabilitysets.ValidateAvailabilitySetID, + DiffSuppressFunc: suppress.CaseDifference, + ConflictsWith: []string{ + "target_zone", + }, + }, + + "target_zone": { + Type: schema.TypeString, + Optional: true, + ValidateFunc: validation.StringIsNotEmpty, + ConflictsWith: []string{ + "target_availability_set_id", + }, + }, + + "target_network_id": { + Type: pluginsdk.TypeString, + Optional: true, + ValidateFunc: commonids.ValidateVirtualNetworkID, + }, + + "target_subnet_name": { + Type: pluginsdk.TypeString, + Optional: true, + ValidateFunc: validation.StringIsNotEmpty, + }, + + "test_network_id": { + Type: pluginsdk.TypeString, + Optional: true, + ValidateFunc: commonids.ValidateVirtualNetworkID, + }, + + "test_subnet_name": { + Type: pluginsdk.TypeString, + Optional: true, + ValidateFunc: validation.StringIsNotEmpty, + }, + + "target_boot_diagnostics_storage_account_id": { + Type: pluginsdk.TypeString, + Optional: true, + ValidateFunc: storageaccounts.ValidateStorageAccountID, + }, + + // managed disk is enabled only if mobility service is already installed. (in most cases, it's not installed) + "managed_disk": { + Type: pluginsdk.TypeSet, + Optional: true, + Elem: resourceSiteRecoveryVMWareReplicatedVMManagedDiskSchema(), + }, + + "network_interface": { + Type: pluginsdk.TypeSet, + Required: true, + Elem: resourceSiteRecoveryVMWareReplicatedVMNetworkInterfaceSchema(), + }, + } +} + +func resourceSiteRecoveryVMWareReplicatedVMManagedDiskSchema() *pluginsdk.Resource { + return &pluginsdk.Resource{ + Schema: map[string]*pluginsdk.Schema{ + "disk_id": { + Type: pluginsdk.TypeString, + Required: true, + ValidateFunc: validation.StringIsNotEmpty, + DiffSuppressFunc: suppress.CaseDifference, + }, + + "target_disk_type": { + Type: pluginsdk.TypeString, + Required: true, + ValidateFunc: validation.StringInSlice(replicationprotecteditems.PossibleValuesForDiskAccountType(), false), + }, + + "target_disk_encryption_set_id": { + Type: pluginsdk.TypeString, + Optional: true, + ValidateFunc: diskencryptionsets.ValidateDiskEncryptionSetID, + DiffSuppressFunc: suppress.CaseDifference, + }, + + "log_storage_account_id": { + Type: pluginsdk.TypeString, + Required: true, + ValidateFunc: azure.ValidateResourceID, + }, + }, + } +} + +func resourceSiteRecoveryVMWareReplicatedVMNetworkInterfaceSchema() *pluginsdk.Resource { + return &pluginsdk.Resource{ + Schema: map[string]*pluginsdk.Schema{ + "source_mac_address": { // if it was left blank, we can use the only one NIC id as the source mac address + Type: pluginsdk.TypeString, + Optional: true, + ValidateFunc: azure.ValidateResourceID, + }, + + "target_static_ip": { + Type: pluginsdk.TypeString, + Optional: true, + ValidateFunc: validation.StringIsNotEmpty, + }, + + "target_subnet_name": { + Type: pluginsdk.TypeString, + Optional: true, + ValidateFunc: validation.StringIsNotEmpty, + }, + + "test_subnet_name": { + Type: pluginsdk.TypeString, + Optional: true, + ValidateFunc: validation.StringIsNotEmpty, + }, + + "is_primary": { + Type: pluginsdk.TypeBool, + Required: true, + }, + }, + } +} + +func (s VMWareReplicatedVmResource) Attributes() map[string]*pluginsdk.Schema { + return map[string]*pluginsdk.Schema{} +} + +func (k VMWareReplicatedVmResource) CustomizeDiff() sdk.ResourceFunc { + return sdk.ResourceFunc{ + Func: func(ctx context.Context, metadata sdk.ResourceMetaData) error { + // these fields are not returned by API, and only used in creation. + diff := metadata.ResourceDiff + + _, newStorageAcc := diff.GetChange("default_log_storage_account_id") + _, newDiskType := diff.GetChange("default_recovery_disk_type") + _, newDes := diff.GetChange("default_target_disk_encryption_set_id") + _, newDisks := diff.GetChange("managed_disk") + for _, disk := range newDisks.(*schema.Set).List() { + disk := disk.(map[string]interface{}) + if newStorageAcc.(string) != "" && disk["log_storage_account_id"] != newStorageAcc.(string) { + metadata.ResourceDiff.ForceNew("default_log_storage_account_id") + } + if newDiskType.(string) != "" && disk["target_disk_type"] != newDiskType.(string) { + metadata.ResourceDiff.ForceNew("default_recovery_disk_type") + } + if newDes.(string) != "" && disk["target_disk_encryption_set_id"] != newDes.(string) { + metadata.ResourceDiff.ForceNew("default_target_disk_encryption_set_id") + } + } + + if diff.HasChanges("managed_disk") { + // if user has specified `managed_disk`, it's force new. + // or it acts as an optional field. + if len(newDisks.(*schema.Set).List()) != 1 { + metadata.ResourceDiff.ForceNew("managed_disk") + } + } + + return nil + }, + Timeout: 30 * time.Minute, + } +} + +func (s VMWareReplicatedVmResource) Create() sdk.ResourceFunc { + return sdk.ResourceFunc{ + // waiting for fully protected cost very long time. + Timeout: 300 * time.Minute, + Func: func(ctx context.Context, metadata sdk.ResourceMetaData) error { + client := metadata.Client.RecoveryServices.ReplicationProtectedItemsClient + fabricClient := metadata.Client.RecoveryServices.FabricClient + containerClient := metadata.Client.RecoveryServices.ProtectionContainerClient + vmwareMachinesClient := metadata.Client.RecoveryServices.VMWareMachinesClient + runAsAccountsClient := metadata.Client.RecoveryServices.VMWareRunAsAccountsClient + + var model SiteRecoveryReplicatedVmVMwareModel + err := metadata.Decode(&model) + if err != nil { + return fmt.Errorf("decoding %+v", err) + } + + if model.CredentialType == "" { + return fmt.Errorf("`credential_type` must be specified in creation") + } + + vaultId, err := replicationprotecteditems.ParseVaultID(model.RecoveryVaultId) + if err != nil { + return fmt.Errorf("parsing vault id %q: %+v", model.RecoveryVaultId, err) + } + + containerId, err := fetchSiteRecoveryReplicatedVmVMWareContainerId(ctx, containerClient, vaultId.ID()) + if err != nil { + return fmt.Errorf("fetch Replication Container from vault %q: %+v", vaultId, err) + } + + parsedContainerId, err := replicationprotecteditems.ParseReplicationProtectionContainerID(containerId) + if err != nil { + return fmt.Errorf("parse %s: %+v", containerId, err) + } + + id := replicationprotecteditems.NewReplicationProtectedItemID(parsedContainerId.SubscriptionId, parsedContainerId.ResourceGroupName, parsedContainerId.VaultName, parsedContainerId.ReplicationFabricName, parsedContainerId.ReplicationProtectionContainerName, model.Name) + fabricId := replicationfabrics.NewReplicationFabricID(parsedContainerId.SubscriptionId, parsedContainerId.ResourceGroupName, parsedContainerId.VaultName, parsedContainerId.ReplicationFabricName) + + processServerId, err := fetchProcessServerIdByName(ctx, fabricClient, fabricId, model.ApplianceName) + if err != nil { + return fmt.Errorf("fetch process server id: %+v", err) + } + + siteID, err := fetchVmwareSiteIdByFabric(ctx, fabricClient, fabricId) + if err != nil { + return fmt.Errorf("fetch VMWare site id: %+v", err) + } + + discoveryMachineId, err := fetchDiscoveryMachineIdBySite(ctx, vmwareMachinesClient, siteID, model.SourceVmName) + if err != nil { + return fmt.Errorf("fetch discovery machine id %s: %+v", model.SourceVmName, err) + } + + runAsAccountId, err := fetchRunAsAccountsIdBySite(ctx, runAsAccountsClient, siteID, model.CredentialType, model.ApplianceName) + if err != nil { + return fmt.Errorf("fetch run as account id %s: %+v", model.CredentialType, err) + } + + existing, err := client.Get(ctx, id) + if err != nil { + if !response.WasNotFound(existing.HttpResponse) { + return fmt.Errorf("checking for presence of existing site recovery vmware replicated vm %q: %+v", id, err) + } + } + + if existing.Model != nil { + return tf.ImportAsExistsError("azurerm_site_recovery_vmware_replicated_vm", *existing.Model.Id) + } + + providerSpecificDetail := replicationprotecteditems.InMageRcmEnableProtectionInput{ + LicenseType: pointer.To(replicationprotecteditems.LicenseType(model.LicenseType)), + TargetVMName: &model.TargetVmName, + TargetResourceGroupId: model.TargetResourceGroupId, + FabricDiscoveryMachineId: discoveryMachineId, + RunAsAccountId: &runAsAccountId, + } + + if model.TargetVmSize != "" { + providerSpecificDetail.TargetVMSize = &model.TargetVmSize + } + + diskDefaultValueSet := false + diskDefaultValue := replicationprotecteditems.InMageRcmDisksDefaultInput{} + + if model.DefaultRecoveryDiskType != "" { + diskDefaultValueSet = true + diskDefaultValue.DiskType = replicationprotecteditems.DiskAccountType(model.DefaultRecoveryDiskType) + } + + if model.DefaultLogStorageAccountId != "" { + diskDefaultValueSet = true + diskDefaultValue.LogStorageAccountId = model.DefaultLogStorageAccountId + } + + if model.DefaultTargetDiskEncryptionSetId != "" { + diskDefaultValueSet = true + diskDefaultValue.DiskEncryptionSetId = &model.DefaultTargetDiskEncryptionSetId + } + + if diskDefaultValueSet { + providerSpecificDetail.DisksDefault = &diskDefaultValue + } + + if model.TargetAvailabilitySetId != "" { + providerSpecificDetail.TargetAvailabilitySetId = pointer.To(model.TargetAvailabilitySetId) + } + + if model.TargetZone != "" { + providerSpecificDetail.TargetAvailabilityZone = pointer.To(model.TargetZone) + } + + if model.TargetBootDiagnosticsStorageAccountId != "" { + providerSpecificDetail.TargetBootDiagnosticsStorageAccountId = pointer.To(model.TargetBootDiagnosticsStorageAccountId) + } + + if model.MultiVmGroupName != "" { + providerSpecificDetail.MultiVMGroupName = &model.MultiVmGroupName + } + + if model.TargetProximityPlacementGroupId != "" { + providerSpecificDetail.TargetProximityPlacementGroupId = &model.TargetProximityPlacementGroupId + } + + if model.ApplianceName != "" { + providerSpecificDetail.ProcessServerId = processServerId + } + + // split test network and subnet into isolated parameters + if model.TargetNetworkId != "" { + providerSpecificDetail.TargetNetworkId = &model.TargetNetworkId + } + + if model.TestNetworkId != "" { + providerSpecificDetail.TestNetworkId = &model.TestNetworkId + } + + diskToIncludeOutput := make([]replicationprotecteditems.InMageRcmDiskInput, 0) + for _, diskRaw := range model.DiskToInclude { + diskToIncludeOutput = append(diskToIncludeOutput, replicationprotecteditems.InMageRcmDiskInput{ + DiskEncryptionSetId: &diskRaw.TargetDiskEncryptionSetId, + DiskId: diskRaw.DiskId, + DiskType: replicationprotecteditems.DiskAccountType(diskRaw.TargetDiskType), + LogStorageAccountId: diskRaw.LogStorageAccountId, + }) + } + + if len(diskToIncludeOutput) > 0 { + providerSpecificDetail.DisksToInclude = &diskToIncludeOutput + } + + parameters := replicationprotecteditems.EnableProtectionInput{ + Properties: &replicationprotecteditems.EnableProtectionInputProperties{ + PolicyId: &model.RecoveryReplicationPolicyId, + ProviderSpecificDetails: providerSpecificDetail, + }, + } + + poller, err := client.Create(ctx, id, parameters) + if err != nil { + return fmt.Errorf("creating %q: %+v", id, err) + } + metadata.SetID(id) // once the PUT request returned successfully, an item has been created, even if it may fail in the poll process. + + err = poller.Poller.PollUntilDone() + if err != nil { + return fmt.Errorf("polling %q: %+v", id, err) + } + + err = resourceSiteRecoveryReplicatedVmVMWareClassicUpdateInternal(ctx, metadata) + if err != nil { + return fmt.Errorf("creating %q: %+v", id, err) + } + + return nil + }, + } +} + +func (s VMWareReplicatedVmResource) Update() sdk.ResourceFunc { + return sdk.ResourceFunc{ + Timeout: 90 * time.Minute, + Func: func(ctx context.Context, metadata sdk.ResourceMetaData) error { + return resourceSiteRecoveryReplicatedVmVMWareClassicUpdateInternal(ctx, metadata) + }, + } +} + +func (s VMWareReplicatedVmResource) Read() sdk.ResourceFunc { + return sdk.ResourceFunc{ + Timeout: 5 * time.Minute, + Func: func(ctx context.Context, metadata sdk.ResourceMetaData) error { + id, err := replicationprotecteditems.ParseReplicationProtectedItemID(metadata.ResourceData.Id()) + if err != nil { + return err + } + + client := metadata.Client.RecoveryServices.ReplicationProtectedItemsClient + + resp, err := client.Get(ctx, *id) + if err != nil { + if response.WasNotFound(resp.HttpResponse) { + return metadata.MarkAsGone(id) + } + return fmt.Errorf("reading %s: %+v", id.String(), err) + } + + vaultId := replicationprotecteditems.NewVaultID(id.SubscriptionId, id.ResourceGroupName, id.VaultName) + + state := SiteRecoveryReplicatedVmVMwareModel{ + Name: id.ReplicationProtectedItemName, + RecoveryVaultId: vaultId.ID(), + } + + if resp.Model != nil && resp.Model.Properties != nil { + prop := *resp.Model.Properties + + state.SourceVmName = pointer.From(prop.FriendlyName) + + policyId := "" + if respPolicyId := pointer.From(prop.PolicyId); respPolicyId != "" { + parsedPolicyId, err := replicationpolicies.ParseReplicationPolicyIDInsensitively(respPolicyId) + if err != nil { + return fmt.Errorf("parse %q: %+v", respPolicyId, err) + } + policyId = parsedPolicyId.ID() + } + state.RecoveryReplicationPolicyId = policyId + + if inMageRcm, isV2A := prop.ProviderSpecificDetails.(replicationprotecteditems.InMageRcmReplicationDetails); isV2A { + state.ApplianceName = pointer.From(inMageRcm.ProcessServerName) + + state.LicenseType = pointer.From(inMageRcm.LicenseType) + + state.MultiVmGroupName = pointer.From(inMageRcm.MultiVMGroupName) + + state.TargetProximityPlacementGroupId = pointer.From(inMageRcm.TargetProximityPlacementGroupId) + + state.TargetResourceGroupId = pointer.From(inMageRcm.TargetResourceGroupId) + + state.TargetVmName = pointer.From(inMageRcm.TargetVMName) + + state.TargetVmSize = pointer.From(inMageRcm.TargetVMSize) + + state.TargetAvailabilitySetId = pointer.From(inMageRcm.TargetAvailabilitySetId) + + state.TargetZone = pointer.From(inMageRcm.TargetAvailabilityZone) + + state.TargetNetworkId = pointer.From(inMageRcm.TargetNetworkId) + + state.TestNetworkId = pointer.From(inMageRcm.TestNetworkId) + + state.TargetBootDiagnosticsStorageAccountId = pointer.From(inMageRcm.TargetBootDiagnosticsStorageAccountId) + + if inMageRcm.ProtectedDisks != nil { + diskOutputs := make([]IncludedDiskModel, 0) + for _, diskRaw := range *inMageRcm.ProtectedDisks { + diskModel := IncludedDiskModel{ + DiskId: *diskRaw.DiskId, + TargetDiskType: string(*diskRaw.DiskType), + } + if diskRaw.DiskEncryptionSetId != nil { + diskModel.TargetDiskEncryptionSetId = *diskRaw.DiskEncryptionSetId + } + diskOutputs = append(diskOutputs, diskModel) + } + state.DiskToInclude = diskOutputs + } + + networkInterfaceModel := NetworkInterfaceModel{} + networkInterfaceModel.TargetStaticIp = pointer.From(inMageRcm.PrimaryNicIPAddress) + + if inMageRcm.VMNics != nil { + nicsOutput := make([]NetworkInterfaceModel, 0) + for _, nic := range *inMageRcm.VMNics { + nicModel := NetworkInterfaceModel{} + nicModel.TargetStaticIp = pointer.From(nic.TargetIPAddress) + nicModel.TargetSubnetName = pointer.From(nic.TargetSubnetName) + nicModel.TestSubnetName = pointer.From(nic.TestSubnetName) + nicModel.SourceMacAddress = pointer.From(nic.NicId) + nicModel.IsPrimary = pointer.From(nic.IsPrimaryNic) == "true" + + nicsOutput = append(nicsOutput, nicModel) + } + state.NetworkInterface = nicsOutput + } + } + } + + var plan SiteRecoveryReplicatedVmVMwareModel + if err := metadata.Decode(&plan); err != nil { + return fmt.Errorf("decoding: %+v", err) + } + + return metadata.Encode(&state) + }, + } +} + +func (s VMWareReplicatedVmResource) Delete() sdk.ResourceFunc { + return sdk.ResourceFunc{ + Timeout: 90 * time.Minute, + Func: func(ctx context.Context, metadata sdk.ResourceMetaData) error { + id, err := replicationprotecteditems.ParseReplicationProtectedItemID(metadata.ResourceData.Id()) + if err != nil { + return err + } + + client := metadata.Client.RecoveryServices.ReplicationProtectedItemsClient + + disableProtectionReason := replicationprotecteditems.DisableProtectionReasonNotSpecified + + disableProtectionInput := replicationprotecteditems.DisableProtectionInput{ + Properties: replicationprotecteditems.DisableProtectionInputProperties{ + DisableProtectionReason: &disableProtectionReason, + // It's a workaround for https://github.com/hashicorp/pandora/issues/1864 + ReplicationProviderInput: &siterecovery.DisableProtectionProviderSpecificInput{ + InstanceType: siterecovery.InstanceTypeDisableProtectionProviderSpecificInput, + }, + }, + } + + err = client.DeleteThenPoll(ctx, *id, disableProtectionInput) + if err != nil { + return fmt.Errorf("deleting %s : %+v", id.String(), err) + } + + return nil + }, + } +} + +func resourceSiteRecoveryReplicatedVmVMWareClassicUpdateInternal(ctx context.Context, metadata sdk.ResourceMetaData) error { + client := metadata.Client.RecoveryServices.ReplicationProtectedItemsClient + containerClient := metadata.Client.RecoveryServices.ProtectionContainerClient + // We are only allowed to update the configuration once the VM is fully protected + state, err := waitForVmwareReplicationToBeHealthy(ctx, metadata) + if err != nil { + return err + } + + var model SiteRecoveryReplicatedVmVMwareModel + err = metadata.Decode(&model) + if err != nil { + return fmt.Errorf("decoding %+v", err) + } + + containerId, err := fetchSiteRecoveryReplicatedVmVMWareContainerId(ctx, containerClient, model.RecoveryVaultId) + if err != nil { + return fmt.Errorf("fetch Replication Container from vault %q: %+v", model.RecoveryVaultId, err) + } + parsedContainerId, err := replicationprotectioncontainers.ParseReplicationProtectionContainerID(containerId) + if err != nil { + return fmt.Errorf("parsing %q: %+v", containerId, err) + } + + id := replicationprotecteditems.NewReplicationProtectedItemID(parsedContainerId.SubscriptionId, parsedContainerId.ResourceGroupName, parsedContainerId.VaultName, parsedContainerId.ReplicationFabricName, parsedContainerId.ReplicationProtectionContainerName, model.Name) + + existing, err := client.Get(ctx, id) + if err != nil { + return fmt.Errorf("retrieving %s: %+v", id, err) + } + + if existing.Model == nil { + return fmt.Errorf("retrieving %s: Model was nil", id) + } + if existing.Model.Properties == nil { + return fmt.Errorf("retrieving %s: Properties was nil", id) + } + if existing.Model.Properties.ProviderSpecificDetails == nil { + return fmt.Errorf("retrieving %s: ProviderSpecificDetails was nil", id) + } + if _, ok := existing.Model.Properties.ProviderSpecificDetails.(replicationprotecteditems.InMageRcmReplicationDetails); !ok { + return fmt.Errorf("retrieving %s: ProviderSpecificDetails was not InMageRcmProtectedItemDetails", id) + } + + existingProps := *existing.Model.Properties + existingDetails := existingProps.ProviderSpecificDetails.(replicationprotecteditems.InMageRcmReplicationDetails) + + var targetAvailabilitySetID *string + if model.TargetAvailabilitySetId != "" { + targetAvailabilitySetID = &model.TargetAvailabilitySetId + } else { + targetAvailabilitySetID = nil + } + + var targetAvailabilityZone *string + if model.TargetZone != "" { + targetAvailabilityZone = &model.TargetZone + } else { + targetAvailabilityZone = nil + } + + vmNics := make([]replicationprotecteditems.InMageRcmNicInput, 0) + if metadata.ResourceData.HasChange("network_interface") { + for _, nic := range model.NetworkInterface { + vmNic := replicationprotecteditems.InMageRcmNicInput{ + TargetSubnetName: &nic.TargetSubnetName, + } + if nic.SourceMacAddress != "" { + vmNic.NicId = nic.SourceMacAddress + } else { + if len(model.NetworkInterface) > 1 { + return fmt.Errorf("when `source_mac_address` is not set, there must be exactly one `network_interface` block") + } + if state == nil || state.Properties == nil || state.Properties.ProviderSpecificDetails == nil { + return fmt.Errorf("failed to get nic id from state") + } + + if detail, ok := state.Properties.ProviderSpecificDetails.(replicationprotecteditems.InMageRcmReplicationDetails); ok { + if detail.VMNics != nil && len(*detail.VMNics) == 1 && (*detail.VMNics)[0].NicId != nil { + vmNic.NicId = *(*detail.VMNics)[0].NicId + } else { + return fmt.Errorf("when `source_mac_address` is not set, there must be exactly one Network Adapter on the source VM") + } + } else { + return fmt.Errorf("unexpected provider specific details type: %T", state.Properties.ProviderSpecificDetails) + } + } + + if nic.TargetStaticIp != "" { + vmNic.TargetStaticIPAddress = &nic.TargetStaticIp + } + if nic.IsPrimary { + vmNic.IsPrimaryNic = strconv.FormatBool(true) + vmNic.IsSelectedForFailover = utils.String("true") + } else { + vmNic.IsPrimaryNic = strconv.FormatBool(false) + vmNic.IsSelectedForFailover = utils.String("false") + } + vmNics = append(vmNics, vmNic) + } + + if model.TargetNetworkId == "" && len(vmNics) > 0 { + return fmt.Errorf("`target_network_id` must be set when a `network_interface` is configured") + } + } else { + if existingDetails.VMNics == nil { + return fmt.Errorf("retrieving `network_interface`: VMNics was nil.") + } else { + for _, respNic := range *existingDetails.VMNics { + vmNics = append(vmNics, replicationprotecteditems.InMageRcmNicInput{ + IsPrimaryNic: pointer.From(respNic.IsPrimaryNic), + IsSelectedForFailover: respNic.IsSelectedForFailover, + NicId: pointer.From(respNic.NicId), + TargetStaticIPAddress: respNic.TargetIPAddress, + TargetSubnetName: respNic.TargetSubnetName, + TestStaticIPAddress: respNic.TestIPAddress, + TestSubnetName: respNic.TestSubnetName, + }) + } + } + } + + updateInput := replicationprotecteditems.InMageRcmUpdateReplicationProtectedItemInput{ + VMNics: &vmNics, + } + + if metadata.ResourceData.HasChange("license_type") { + updateInput.LicenseType = pointer.To(replicationprotecteditems.LicenseType(model.LicenseType)) + } else { + if existingDetails.LicenseType != nil { + updateInput.LicenseType = pointer.To(replicationprotecteditems.LicenseType(*existingDetails.LicenseType)) + } + } + + if metadata.ResourceData.HasChange("target_vm_name") { + updateInput.TargetVMName = &model.TargetVmName + } else { + updateInput.TargetVMName = existingDetails.TargetVMName + } + + if metadata.ResourceData.HasChange("target_resource_group_id") { + updateInput.TargetResourceGroupId = &model.TargetResourceGroupId + } else { + updateInput.TargetResourceGroupId = existingDetails.TargetResourceGroupId + } + + if metadata.ResourceData.HasChange("target_availability_set_id") { + updateInput.TargetAvailabilitySetId = targetAvailabilitySetID + } else { + updateInput.TargetAvailabilitySetId = existingDetails.TargetAvailabilitySetId + } + + if metadata.ResourceData.HasChange("target_zone") { + updateInput.TargetAvailabilityZone = targetAvailabilityZone + } else { + updateInput.TargetAvailabilityZone = existingDetails.TargetAvailabilityZone + } + + if metadata.ResourceData.HasChange("target_network_id") { + updateInput.TargetNetworkId = &model.TargetNetworkId + } else { + updateInput.TargetNetworkId = existingDetails.TargetNetworkId + } + + if metadata.ResourceData.HasChange("target_proximity_placement_group_id") { + updateInput.TargetProximityPlacementGroupId = &model.TargetProximityPlacementGroupId + } else { + updateInput.TargetProximityPlacementGroupId = existingDetails.TargetProximityPlacementGroupId + } + + if metadata.ResourceData.HasChange("target_boot_diagnostics_storage_account_id") { + updateInput.TargetBootDiagnosticsStorageAccountId = &model.TargetBootDiagnosticsStorageAccountId + } else { + updateInput.TargetBootDiagnosticsStorageAccountId = existingDetails.TargetBootDiagnosticsStorageAccountId + } + + props := replicationprotecteditems.UpdateReplicationProtectedItemInputProperties{ + ProviderSpecificDetails: updateInput, + } + + if metadata.ResourceData.HasChange("target_vm_name") { + props.RecoveryAzureVMName = &model.TargetVmName + } else { + props.RecoveryAzureVMName = existingDetails.TargetVMName + } + + if metadata.ResourceData.HasChange("target_network_id") { + props.SelectedRecoveryAzureNetworkId = &model.TargetNetworkId + } else { + props.SelectedRecoveryAzureNetworkId = existingDetails.TargetNetworkId + } + + if metadata.ResourceData.HasChange("target_availability_set_id") { + props.RecoveryAvailabilitySetId = targetAvailabilitySetID + } else { + props.RecoveryAvailabilitySetId = existingDetails.TargetAvailabilitySetId + } + + if metadata.ResourceData.HasChange("target_vm_size") { + props.RecoveryAzureVMSize = &model.TargetVmSize + } else { + props.RecoveryAzureVMSize = existingDetails.TargetVMSize + } + + parameters := replicationprotecteditems.UpdateReplicationProtectedItemInput{ + Properties: &props, + } + + err = client.UpdateThenPoll(ctx, id, parameters) + if err != nil { + return fmt.Errorf("updating %q: %+v", id, err) + } + + return nil +} + +func waitForVmwareReplicationToBeHealthy(ctx context.Context, metadata sdk.ResourceMetaData) (*replicationprotecteditems.ReplicationProtectedItem, error) { + stateConf := &pluginsdk.StateChangeConf{ + Target: []string{"Protected", "normal"}, + Refresh: waitForVmwareClassicReplicationToBeHealthyRefreshFunc(ctx, metadata), + PollInterval: time.Minute, + } + + deadline, ok := ctx.Deadline() + if !ok { + return nil, fmt.Errorf("context had no deadline") + } + stateConf.Timeout = time.Until(deadline) + + result, err := stateConf.WaitForStateContext(ctx) + if err != nil { + return nil, fmt.Errorf("waiting for site recovery to replicate vm: %+v", err) + } + + protectedItem, ok := result.(replicationprotecteditems.ReplicationProtectedItem) + if ok { + return &protectedItem, nil + } else { + return nil, fmt.Errorf("waiting for site recovery return incompatible type") + } +} + +func waitForVmwareClassicReplicationToBeHealthyRefreshFunc(ctx context.Context, metadata sdk.ResourceMetaData) pluginsdk.StateRefreshFunc { + return func() (interface{}, string, error) { + id, err := replicationprotecteditems.ParseReplicationProtectedItemID(metadata.ResourceData.Id()) + if err != nil { + return nil, "", err + } + + client := metadata.Client.RecoveryServices.ReplicationProtectedItemsClient + + resp, err := client.Get(ctx, *id) + if err != nil { + return nil, "", fmt.Errorf("making Read request on site recovery replicated vm Vmware Classic %s : %+v", id.String(), err) + } + + if resp.Model == nil { + return nil, "", fmt.Errorf("Missing Model in response when making Read request on site recovery replicated vm Vmware Classic %s %+v", id.String(), err) + } + + if resp.Model.Properties == nil { + return nil, "", fmt.Errorf("Missing Properties in response when making Read request on site recovery replicated vm Vmware Classic %s %+v", id.String(), err) + } + + if resp.Model.Properties.ProviderSpecificDetails == nil { + return nil, "", fmt.Errorf("missing Properties.ProviderSpecificDetails in response when making Read request on site recovery replicated vm Vmware Classic %s : %+v", id.String(), err) + } + + // Find first disk that is not fully replicated yet + if resp.Model.Properties.ProtectionState == nil { + return nil, "", fmt.Errorf("missing ProtectionState in response when making Read request on site recovery replicated vm Vmware Classic %s : %+v", id.String(), err) + } + return *resp.Model, *resp.Model.Properties.ProtectionState, nil + } +} + +func fetchSiteRecoveryReplicatedVmVMWareContainerId(ctx context.Context, containerClient *replicationprotectioncontainers.ReplicationProtectionContainersClient, vaultId string) (string, error) { + vId, err := replicationprotectioncontainers.ParseVaultID(vaultId) + if err != nil { + return "", fmt.Errorf("parse %s: %+v", vaultId, err) + } + + resp, err := containerClient.ListComplete(ctx, *vId) + if err != nil { + return "", err + } + + if len(resp.Items) != 1 { + return "", fmt.Errorf("there should be only 1 protection container in Recovery Vault, get: %v", len(resp.Items)) + } + + parsedID, err := replicationprotectioncontainers.ParseReplicationProtectionContainerIDInsensitively(*resp.Items[0].Id) + if err != nil { + return "", fmt.Errorf("parse %s: %+v", *resp.Items[0].Id, err) + } + + return parsedID.ID(), nil +} + +func fetchRunAsAccountsIdBySite(ctx context.Context, runAsAccountClient *vmwarerunasaccounts.RunAsAccountsClient, siteId string, accountType string, applianceName string) (string, error) { + parsedSiteId, err := vmwarerunasaccounts.ParseVMwareSiteIDInsensitively(siteId) + if err != nil { + return "", fmt.Errorf("parse %s: %+v", siteId, err) + } + + hackedClinet := azuresdkhacks.RunAsAccountsClient{Client: runAsAccountClient.Client} + resp, err := hackedClinet.GetAllRunAsAccountsInSiteComplete(ctx, *parsedSiteId) + if err != nil { + return "", err + } + + if len(resp.Items) == 0 { + return "", fmt.Errorf("retire run as account from %s, get 0 item", siteId) + } + + for _, account := range resp.Items { + if account.Properties == nil { + continue + } + if account.Properties.DisplayName == nil { + continue + } + if account.Properties.ApplianceName == nil { + continue + } + if strings.EqualFold(*account.Properties.DisplayName, accountType) && strings.EqualFold(*account.Properties.ApplianceName, applianceName) { + return *account.Id, nil + } + } + + return "", fmt.Errorf("retiring %q: run as account %s not found", siteId, accountType) +} + +func fetchProcessServerIdByName(ctx context.Context, fabricClient *replicationfabrics.ReplicationFabricsClient, fabricId replicationfabrics.ReplicationFabricId, processServerName string) (string, error) { + resp, err := fabricClient.Get(ctx, fabricId, replicationfabrics.DefaultGetOperationOptions()) + if err != nil { + return "", err + } + + if resp.Model == nil { + return "", fmt.Errorf("retiring %q: Model is nil", fabricId) + } + + if resp.Model.Properties == nil { + return "", fmt.Errorf("retiring %q: Properties is nil", fabricId) + } + + if resp.Model.Properties.CustomDetails == nil { + return "", fmt.Errorf("retiring %q: CustomDetails is nil", fabricId) + } + + if detail, ok := resp.Model.Properties.CustomDetails.(replicationfabrics.InMageRcmFabricSpecificDetails); ok { + if detail.ProcessServers == nil || len(*detail.ProcessServers) < 1 { + return "", fmt.Errorf("retiring %q: count of Process Servers is 0", fabricId) + } + for _, server := range *detail.ProcessServers { + if strings.EqualFold(*server.Name, processServerName) { + return *server.Id, nil + } + } + return "", fmt.Errorf("retiring %q: process server %s not found", fabricId, processServerName) + } + return "", fmt.Errorf("retiring %q: Detail Type mismatch", fabricId) +} + +func fetchDiscoveryMachineIdBySite(ctx context.Context, machinesClient *vmwaremachines.MachinesClient, siteId string, machineName string) (string, error) { + parsedSiteId, err := vmwaremachines.ParseVMwareSiteIDInsensitively(siteId) + if err != nil { + return "", fmt.Errorf("parse %s: %+v", siteId, err) + } + + resp, err := getAllVMWareMachinesInSite(ctx, machinesClient, *parsedSiteId, vmwaremachines.DefaultGetAllMachinesInSiteOperationOptions()) + if err != nil { + return "", err + } + + if model := resp.Model; model != nil { + for _, machine := range *model { + if machine.Properties == nil { + continue + } + if machine.Properties.DisplayName == nil { + continue + } + if strings.EqualFold(*machine.Properties.DisplayName, machineName) { + return handleAzureSdkForGoBug2824(*machine.Id), nil + } + } + } + + return "", fmt.Errorf("retiring %q: machine %s not found", siteId, machineName) +} + +// workaround for https://github.com/hashicorp/go-azure-sdk/issues/492 +func getAllVMWareMachinesInSite(ctx context.Context, c *vmwaremachines.MachinesClient, id vmwaremachines.VMwareSiteId, options vmwaremachines.GetAllMachinesInSiteOperationOptions) (result vmwaremachines.GetAllMachinesInSiteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/machines", id.ID()), + OptionsObject: options, + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + return warpedExecutePaged(ctx, req) +} + +func warpedExecutePaged(ctx context.Context, req *client.Request) (result vmwaremachines.GetAllMachinesInSiteOperationResponse, err error) { + resp, err := req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]vmwaremachines.VMwareMachine `json:"value"` + NextLink *string `json:"nextLink"` + } + + if err = resp.Unmarshal(&values); err != nil { + return + } + result.Model = values.Values + + if values.NextLink != nil { + nextReq := req + u, err := url.Parse(*values.NextLink) + if err != nil { + return result, err + } + nextReq.URL = u + nextResp, err := warpedExecutePaged(ctx, nextReq) + if err != nil { + return result, err + } + if nextResp.Model != nil { + result.Model = pointer.To(append(*result.Model, *nextResp.Model...)) + } + } + + return +} + +func fetchVmwareSiteIdByFabric(ctx context.Context, fabricClient *replicationfabrics.ReplicationFabricsClient, fabricId replicationfabrics.ReplicationFabricId) (string, error) { + resp, err := fabricClient.Get(ctx, fabricId, replicationfabrics.DefaultGetOperationOptions()) + if err != nil { + return "", err + } + if resp.Model == nil { + return "", fmt.Errorf("retiring %q: Model is nil", fabricId) + } + if resp.Model.Properties == nil { + return "", fmt.Errorf("retiring %q: Properties is nil", fabricId) + } + if v, ok := resp.Model.Properties.CustomDetails.(replicationfabrics.InMageRcmFabricSpecificDetails); ok { + if v.VMwareSiteId == nil { + return "", fmt.Errorf("retiring %q: VMwareSiteId is nil", fabricId) + } + return *v.VMwareSiteId, nil + } + return "", fmt.Errorf("retiring %q: Detail Type mismatch", fabricId) +} diff --git a/internal/services/recoveryservices/site_recovery_vmware_replicated_vm_resource_test.go b/internal/services/recoveryservices/site_recovery_vmware_replicated_vm_resource_test.go new file mode 100644 index 000000000000..87566f69f55b --- /dev/null +++ b/internal/services/recoveryservices/site_recovery_vmware_replicated_vm_resource_test.go @@ -0,0 +1,147 @@ +package recoveryservices_test + +import ( + "context" + "fmt" + "os" + "testing" + + "github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2022-10-01/replicationprotecteditems" + "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 SiteRecoveryVMWareReplicatedVmResource struct{} + +func (r SiteRecoveryVMWareReplicatedVmResource) Exists(ctx context.Context, clients *clients.Client, state *pluginsdk.InstanceState) (*bool, error) { + id, err := replicationprotecteditems.ParseReplicationProtectedItemID(state.ID) + if err != nil { + return nil, err + } + + resp, err := clients.RecoveryServices.ReplicationProtectedItemsClient.Get(ctx, *id) + if err != nil { + return nil, fmt.Errorf("reading %s: %+v", id, err) + } + + return utils.Bool(resp.Model != nil), nil +} + +func TestAccSiteVMWareRecoveryReplicatedVM_basic(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_site_recovery_vmware_replicated_vm", "test") + r := SiteRecoveryVMWareReplicatedVmResource{} + + vaultId := os.Getenv("ARM_TEST_VMWARE_VAULT_ID") + sourceVMName := os.Getenv("ARM_TEST_VMWARE_SOURCE_VM_NAME") + applianceName := os.Getenv("ARM_TEST_VMWARE_APPLIANCE_NAME") + location := os.Getenv("ARM_TEST_VMWARE_VAULT_LOCATION") + + if vaultId == "" || sourceVMName == "" || applianceName == "" || location == "" { + t.Skip("Skipping since ARM_TEST_VMWARE_VAULT_ID, ARM_TEST_VMWARE_SOURCE_VM_NAME, ARM_TEST_VMWARE_LOCATION and ARM_TEST_VMWARE_APPLIANCE_NAME are not specified") + return + } + + data.Locations.Primary = location + + data.ResourceTest(t, r, []acceptance.TestStep{ + { + Config: r.basic(data, vaultId, sourceVMName, applianceName), + Check: acceptance.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + ), + }, + data.ImportStep(), + }) +} + +func (SiteRecoveryVMWareReplicatedVmResource) basic(data acceptance.TestData, vaultId, sourceVMName, applianceName string) string { + return fmt.Sprintf(` +provider "azurerm" { + features { + resource_group { + prevent_deletion_if_contains_resources = false + } + } +} + +resource "azurerm_site_recovery_vmware_replication_policy" "test" { + recovery_vault_id = "%[1]s" + name = "acctest-policy-%[2]d" + recovery_point_retention_in_minutes = 1440 + application_consistent_snapshot_frequency_in_minutes = 240 +} + +resource "azurerm_site_recovery_vmware_replication_policy_association" "test" { + name = "acctest-%[2]d" + recovery_vault_id = "%[1]s" + policy_id = azurerm_site_recovery_vmware_replication_policy.test.id +} + +resource "azurerm_resource_group" "target" { + name = "acctestRG-%[2]d" + location = "%[4]s" +} + +resource "azurerm_storage_account" "target" { + name = "acct%[3]s" + resource_group_name = azurerm_resource_group.target.name + location = azurerm_resource_group.target.location + account_tier = "Standard" + account_replication_type = "LRS" +} + +resource "azurerm_virtual_network" "target" { + name = "acctestvn-%[2]d" + address_space = ["10.0.0.0/16"] + location = azurerm_resource_group.target.location + resource_group_name = azurerm_resource_group.target.name +} + +resource "azurerm_subnet" "target" { + name = "internal" + resource_group_name = azurerm_resource_group.target.name + virtual_network_name = azurerm_virtual_network.target.name + address_prefixes = ["10.0.2.0/24"] +} + + +resource "azurerm_site_recovery_vmware_replicated_vm" "test" { + name = "acct%[2]d" + recovery_vault_id = "%[1]s" + source_vm_name = "%[5]s" + appliance_name = "%[6]s" + recovery_replication_policy_id = azurerm_site_recovery_vmware_replication_policy.test.id + credential_type = "lincreds" + license_type = "NotSpecified" + target_boot_diagnostics_storage_account_id = azurerm_storage_account.target.id + target_vm_name = "%[5]s" + target_resource_group_id = azurerm_resource_group.target.id + default_log_storage_account_id = azurerm_storage_account.target.id + default_recovery_disk_type = "Standard_LRS" + target_network_id = azurerm_virtual_network.target.id + + network_interface { + target_subnet_name = azurerm_subnet.target.name + is_primary = true + } + + timeouts { + create = "600m" + } + + lifecycle { + ignore_changes = [ + target_vm_size, + credential_type, + default_log_storage_account_id, + default_recovery_disk_type, + managed_disk, + network_interface + ] + } +} +`, vaultId, data.RandomInteger, data.RandomString, data.Locations.Primary, sourceVMName, applianceName) +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/migrate/2020-01-01/machines/README.md b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/migrate/2020-01-01/machines/README.md new file mode 100644 index 000000000000..a5acf2832f98 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/migrate/2020-01-01/machines/README.md @@ -0,0 +1,85 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/migrate/2020-01-01/machines` Documentation + +The `machines` SDK allows for interaction with the Azure Resource Manager Service `migrate` (API Version `2020-01-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/migrate/2020-01-01/machines" +``` + + +### Client Initialization + +```go +client := machines.NewMachinesClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `MachinesClient.GetAllMachinesInSite` + +```go +ctx := context.TODO() +id := machines.NewVMwareSiteID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vmwareSiteValue") + +// alternatively `client.GetAllMachinesInSite(ctx, id, machines.DefaultGetAllMachinesInSiteOperationOptions())` can be used to do batched pagination +items, err := client.GetAllMachinesInSiteComplete(ctx, id, machines.DefaultGetAllMachinesInSiteOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `MachinesClient.GetMachine` + +```go +ctx := context.TODO() +id := machines.NewVMwareSiteMachineID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vmwareSiteValue", "machineValue") + +read, err := client.GetMachine(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `MachinesClient.StartMachine` + +```go +ctx := context.TODO() +id := machines.NewVMwareSiteMachineID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vmwareSiteValue", "machineValue") + +read, err := client.StartMachine(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `MachinesClient.StopMachine` + +```go +ctx := context.TODO() +id := machines.NewVMwareSiteMachineID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vmwareSiteValue", "machineValue") + +read, err := client.StopMachine(ctx, id) +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/migrate/2020-01-01/machines/client.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/migrate/2020-01-01/machines/client.go new file mode 100644 index 000000000000..80e10f009c71 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/migrate/2020-01-01/machines/client.go @@ -0,0 +1,26 @@ +package machines + +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type MachinesClient struct { + Client *resourcemanager.Client +} + +func NewMachinesClientWithBaseURI(api environments.Api) (*MachinesClient, error) { + client, err := resourcemanager.NewResourceManagerClient(api, "machines", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating MachinesClient: %+v", err) + } + + return &MachinesClient{ + Client: client, + }, nil +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/migrate/2020-01-01/machines/constants.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/migrate/2020-01-01/machines/constants.go new file mode 100644 index 000000000000..2e9c98c034e1 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/migrate/2020-01-01/machines/constants.go @@ -0,0 +1,63 @@ +package machines + +import ( + "encoding/json" + "fmt" + "strings" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type VirtualDiskMode string + +const ( + VirtualDiskModeAppend VirtualDiskMode = "append" + VirtualDiskModeIndependentNonpersistent VirtualDiskMode = "independent_nonpersistent" + VirtualDiskModeIndependentPersistent VirtualDiskMode = "independent_persistent" + VirtualDiskModeNonpersistent VirtualDiskMode = "nonpersistent" + VirtualDiskModePersistent VirtualDiskMode = "persistent" + VirtualDiskModeUndoable VirtualDiskMode = "undoable" +) + +func PossibleValuesForVirtualDiskMode() []string { + return []string{ + string(VirtualDiskModeAppend), + string(VirtualDiskModeIndependentNonpersistent), + string(VirtualDiskModeIndependentPersistent), + string(VirtualDiskModeNonpersistent), + string(VirtualDiskModePersistent), + string(VirtualDiskModeUndoable), + } +} + +func (s *VirtualDiskMode) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseVirtualDiskMode(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseVirtualDiskMode(input string) (*VirtualDiskMode, error) { + vals := map[string]VirtualDiskMode{ + "append": VirtualDiskModeAppend, + "independent_nonpersistent": VirtualDiskModeIndependentNonpersistent, + "independent_persistent": VirtualDiskModeIndependentPersistent, + "nonpersistent": VirtualDiskModeNonpersistent, + "persistent": VirtualDiskModePersistent, + "undoable": VirtualDiskModeUndoable, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := VirtualDiskMode(input) + return &out, nil +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/migrate/2020-01-01/machines/id_vmwaresite.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/migrate/2020-01-01/machines/id_vmwaresite.go new file mode 100644 index 000000000000..d7c350b4e0f6 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/migrate/2020-01-01/machines/id_vmwaresite.go @@ -0,0 +1,127 @@ +package machines + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = VMwareSiteId{} + +// VMwareSiteId is a struct representing the Resource ID for a V Mware Site +type VMwareSiteId struct { + SubscriptionId string + ResourceGroupName string + VmwareSiteName string +} + +// NewVMwareSiteID returns a new VMwareSiteId struct +func NewVMwareSiteID(subscriptionId string, resourceGroupName string, vmwareSiteName string) VMwareSiteId { + return VMwareSiteId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + VmwareSiteName: vmwareSiteName, + } +} + +// ParseVMwareSiteID parses 'input' into a VMwareSiteId +func ParseVMwareSiteID(input string) (*VMwareSiteId, error) { + parser := resourceids.NewParserFromResourceIdType(VMwareSiteId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := VMwareSiteId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", *parsed) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", *parsed) + } + + if id.VmwareSiteName, ok = parsed.Parsed["vmwareSiteName"]; !ok { + return nil, resourceids.NewSegmentNotSpecifiedError(id, "vmwareSiteName", *parsed) + } + + return &id, nil +} + +// ParseVMwareSiteIDInsensitively parses 'input' case-insensitively into a VMwareSiteId +// note: this method should only be used for API response data and not user input +func ParseVMwareSiteIDInsensitively(input string) (*VMwareSiteId, error) { + parser := resourceids.NewParserFromResourceIdType(VMwareSiteId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := VMwareSiteId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", *parsed) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", *parsed) + } + + if id.VmwareSiteName, ok = parsed.Parsed["vmwareSiteName"]; !ok { + return nil, resourceids.NewSegmentNotSpecifiedError(id, "vmwareSiteName", *parsed) + } + + return &id, nil +} + +// ValidateVMwareSiteID checks that 'input' can be parsed as a V Mware Site ID +func ValidateVMwareSiteID(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 := ParseVMwareSiteID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted V Mware Site ID +func (id VMwareSiteId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.OffAzure/vmwareSites/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.VmwareSiteName) +} + +// Segments returns a slice of Resource ID Segments which comprise this V Mware Site ID +func (id VMwareSiteId) 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("staticMicrosoftOffAzure", "Microsoft.OffAzure", "Microsoft.OffAzure"), + resourceids.StaticSegment("staticVmwareSites", "vmwareSites", "vmwareSites"), + resourceids.UserSpecifiedSegment("vmwareSiteName", "vmwareSiteValue"), + } +} + +// String returns a human-readable description of this V Mware Site ID +func (id VMwareSiteId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Vmware Site Name: %q", id.VmwareSiteName), + } + return fmt.Sprintf("V Mware Site (%s)", strings.Join(components, "\n")) +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/migrate/2020-01-01/machines/method_getallmachinesinsite.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/migrate/2020-01-01/machines/method_getallmachinesinsite.go new file mode 100644 index 000000000000..cdfa5bcaf889 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/migrate/2020-01-01/machines/method_getallmachinesinsite.go @@ -0,0 +1,129 @@ +package machines + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetAllMachinesInSiteOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]VMwareMachine +} + +type GetAllMachinesInSiteCompleteResult struct { + Items []VMwareMachine +} + +type GetAllMachinesInSiteOperationOptions struct { + ContinuationToken *string + Filter *string + Top *int64 + TotalRecordCount *int64 +} + +func DefaultGetAllMachinesInSiteOperationOptions() GetAllMachinesInSiteOperationOptions { + return GetAllMachinesInSiteOperationOptions{} +} + +func (o GetAllMachinesInSiteOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o GetAllMachinesInSiteOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o GetAllMachinesInSiteOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.ContinuationToken != nil { + out.Append("continuationToken", fmt.Sprintf("%v", *o.ContinuationToken)) + } + if o.Filter != nil { + out.Append("$filter", fmt.Sprintf("%v", *o.Filter)) + } + if o.Top != nil { + out.Append("$top", fmt.Sprintf("%v", *o.Top)) + } + if o.TotalRecordCount != nil { + out.Append("totalRecordCount", fmt.Sprintf("%v", *o.TotalRecordCount)) + } + return &out +} + +// GetAllMachinesInSite ... +func (c MachinesClient) GetAllMachinesInSite(ctx context.Context, id VMwareSiteId, options GetAllMachinesInSiteOperationOptions) (result GetAllMachinesInSiteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/machines", id.ID()), + OptionsObject: options, + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]VMwareMachine `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// GetAllMachinesInSiteComplete retrieves all the results into a single object +func (c MachinesClient) GetAllMachinesInSiteComplete(ctx context.Context, id VMwareSiteId, options GetAllMachinesInSiteOperationOptions) (GetAllMachinesInSiteCompleteResult, error) { + return c.GetAllMachinesInSiteCompleteMatchingPredicate(ctx, id, options, VMwareMachineOperationPredicate{}) +} + +// GetAllMachinesInSiteCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c MachinesClient) GetAllMachinesInSiteCompleteMatchingPredicate(ctx context.Context, id VMwareSiteId, options GetAllMachinesInSiteOperationOptions, predicate VMwareMachineOperationPredicate) (result GetAllMachinesInSiteCompleteResult, err error) { + items := make([]VMwareMachine, 0) + + resp, err := c.GetAllMachinesInSite(ctx, id, options) + if err != nil { + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = GetAllMachinesInSiteCompleteResult{ + Items: items, + } + return +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/migrate/2020-01-01/machines/method_getmachine.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/migrate/2020-01-01/machines/method_getmachine.go new file mode 100644 index 000000000000..500d851642e6 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/migrate/2020-01-01/machines/method_getmachine.go @@ -0,0 +1,52 @@ +package machines + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetMachineOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *VMwareMachine +} + +// GetMachine ... +func (c MachinesClient) GetMachine(ctx context.Context, id commonids.VMwareSiteMachineId) (result GetMachineOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/migrate/2020-01-01/machines/method_startmachine.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/migrate/2020-01-01/machines/method_startmachine.go new file mode 100644 index 000000000000..56eeb9c4d933 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/migrate/2020-01-01/machines/method_startmachine.go @@ -0,0 +1,48 @@ +package machines + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type StartMachineOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// StartMachine ... +func (c MachinesClient) StartMachine(ctx context.Context, id commonids.VMwareSiteMachineId) (result StartMachineOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/start", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/migrate/2020-01-01/machines/method_stopmachine.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/migrate/2020-01-01/machines/method_stopmachine.go new file mode 100644 index 000000000000..de2580cd3b84 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/migrate/2020-01-01/machines/method_stopmachine.go @@ -0,0 +1,48 @@ +package machines + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type StopMachineOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// StopMachine ... +func (c MachinesClient) StopMachine(ctx context.Context, id commonids.VMwareSiteMachineId) (result StopMachineOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/stop", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/migrate/2020-01-01/machines/model_application.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/migrate/2020-01-01/machines/model_application.go new file mode 100644 index 000000000000..3cc5f9c1cc39 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/migrate/2020-01-01/machines/model_application.go @@ -0,0 +1,10 @@ +package machines + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type Application struct { + Name *string `json:"name,omitempty"` + Provider *string `json:"provider,omitempty"` + Version *string `json:"version,omitempty"` +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/migrate/2020-01-01/machines/model_appsandroles.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/migrate/2020-01-01/machines/model_appsandroles.go new file mode 100644 index 000000000000..b1d02fdea3ae --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/migrate/2020-01-01/machines/model_appsandroles.go @@ -0,0 +1,16 @@ +package machines + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AppsAndRoles struct { + Applications *[]Application `json:"applications,omitempty"` + BizTalkServers *[]BizTalkServer `json:"bizTalkServers,omitempty"` + ExchangeServers *[]ExchangeServer `json:"exchangeServers,omitempty"` + Features *[]Feature `json:"features,omitempty"` + OtherDatabases *[]OtherDatabase `json:"otherDatabases,omitempty"` + SharePointServers *[]SharePointServer `json:"sharePointServers,omitempty"` + SqlServers *[]SQLServer `json:"sqlServers,omitempty"` + SystemCenters *[]SystemCenter `json:"systemCenters,omitempty"` + WebApplications *[]WebApplication `json:"webApplications,omitempty"` +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/migrate/2020-01-01/machines/model_biztalkserver.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/migrate/2020-01-01/machines/model_biztalkserver.go new file mode 100644 index 000000000000..78fa9a908e7f --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/migrate/2020-01-01/machines/model_biztalkserver.go @@ -0,0 +1,9 @@ +package machines + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type BizTalkServer struct { + ProductName *string `json:"productName,omitempty"` + Status *string `json:"status,omitempty"` +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/migrate/2020-01-01/machines/model_exchangeserver.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/migrate/2020-01-01/machines/model_exchangeserver.go new file mode 100644 index 000000000000..26dd1b2e4637 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/migrate/2020-01-01/machines/model_exchangeserver.go @@ -0,0 +1,12 @@ +package machines + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ExchangeServer struct { + Edition *string `json:"edition,omitempty"` + ProductName *string `json:"productName,omitempty"` + Roles *string `json:"roles,omitempty"` + ServicePack *string `json:"servicePack,omitempty"` + Version *string `json:"version,omitempty"` +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/migrate/2020-01-01/machines/model_feature.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/migrate/2020-01-01/machines/model_feature.go new file mode 100644 index 000000000000..7d99cf9017ba --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/migrate/2020-01-01/machines/model_feature.go @@ -0,0 +1,11 @@ +package machines + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type Feature struct { + FeatureType *string `json:"featureType,omitempty"` + Name *string `json:"name,omitempty"` + Parent *string `json:"parent,omitempty"` + Status *string `json:"status,omitempty"` +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/migrate/2020-01-01/machines/model_guestosdetails.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/migrate/2020-01-01/machines/model_guestosdetails.go new file mode 100644 index 000000000000..007ec0b1e3d0 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/migrate/2020-01-01/machines/model_guestosdetails.go @@ -0,0 +1,10 @@ +package machines + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GuestOSDetails struct { + OsName *string `json:"osName,omitempty"` + OsType *string `json:"osType,omitempty"` + OsVersion *string `json:"osVersion,omitempty"` +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/migrate/2020-01-01/machines/model_healtherrordetails.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/migrate/2020-01-01/machines/model_healtherrordetails.go new file mode 100644 index 000000000000..48f82e65ceaa --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/migrate/2020-01-01/machines/model_healtherrordetails.go @@ -0,0 +1,16 @@ +package machines + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type HealthErrorDetails struct { + Code *string `json:"code,omitempty"` + Id *int64 `json:"id,omitempty"` + Message *string `json:"message,omitempty"` + MessageParameters *map[string]string `json:"messageParameters,omitempty"` + PossibleCauses *string `json:"possibleCauses,omitempty"` + RecommendedAction *string `json:"recommendedAction,omitempty"` + Severity *string `json:"severity,omitempty"` + Source *string `json:"source,omitempty"` + SummaryMessage *string `json:"summaryMessage,omitempty"` +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/migrate/2020-01-01/machines/model_operatingsystem.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/migrate/2020-01-01/machines/model_operatingsystem.go new file mode 100644 index 000000000000..358760587b78 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/migrate/2020-01-01/machines/model_operatingsystem.go @@ -0,0 +1,10 @@ +package machines + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type OperatingSystem struct { + OsName *string `json:"osName,omitempty"` + OsType *string `json:"osType,omitempty"` + OsVersion *string `json:"osVersion,omitempty"` +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/migrate/2020-01-01/machines/model_otherdatabase.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/migrate/2020-01-01/machines/model_otherdatabase.go new file mode 100644 index 000000000000..8014cb880e0c --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/migrate/2020-01-01/machines/model_otherdatabase.go @@ -0,0 +1,10 @@ +package machines + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type OtherDatabase struct { + DatabaseType *string `json:"databaseType,omitempty"` + Instance *string `json:"instance,omitempty"` + Version *string `json:"version,omitempty"` +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/migrate/2020-01-01/machines/model_sharepointserver.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/migrate/2020-01-01/machines/model_sharepointserver.go new file mode 100644 index 000000000000..5aaefcef0e92 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/migrate/2020-01-01/machines/model_sharepointserver.go @@ -0,0 +1,11 @@ +package machines + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SharePointServer struct { + IsEnterprise *bool `json:"isEnterprise,omitempty"` + ProductName *string `json:"productName,omitempty"` + Status *string `json:"status,omitempty"` + Version *string `json:"version,omitempty"` +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/migrate/2020-01-01/machines/model_sqlserver.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/migrate/2020-01-01/machines/model_sqlserver.go new file mode 100644 index 000000000000..034ab8266a8c --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/migrate/2020-01-01/machines/model_sqlserver.go @@ -0,0 +1,13 @@ +package machines + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SQLServer struct { + ClusterName *string `json:"clusterName,omitempty"` + Clustered *string `json:"clustered,omitempty"` + Edition *string `json:"edition,omitempty"` + Name *string `json:"name,omitempty"` + ServicePack *string `json:"servicePack,omitempty"` + Version *string `json:"version,omitempty"` +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/migrate/2020-01-01/machines/model_systemcenter.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/migrate/2020-01-01/machines/model_systemcenter.go new file mode 100644 index 000000000000..b269a7c1e1ab --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/migrate/2020-01-01/machines/model_systemcenter.go @@ -0,0 +1,10 @@ +package machines + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SystemCenter struct { + ProductName *string `json:"productName,omitempty"` + Status *string `json:"status,omitempty"` + Version *string `json:"version,omitempty"` +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/migrate/2020-01-01/machines/model_vmwaredisk.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/migrate/2020-01-01/machines/model_vmwaredisk.go new file mode 100644 index 000000000000..4cc6da44fe59 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/migrate/2020-01-01/machines/model_vmwaredisk.go @@ -0,0 +1,17 @@ +package machines + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type VMwareDisk struct { + DiskMode *VirtualDiskMode `json:"diskMode,omitempty"` + DiskProvisioningPolicy *string `json:"diskProvisioningPolicy,omitempty"` + DiskScrubbingPolicy *string `json:"diskScrubbingPolicy,omitempty"` + DiskType *string `json:"diskType,omitempty"` + Label *string `json:"label,omitempty"` + Lun *int64 `json:"lun,omitempty"` + MaxSizeInBytes *int64 `json:"maxSizeInBytes,omitempty"` + Name *string `json:"name,omitempty"` + Path *string `json:"path,omitempty"` + Uuid *string `json:"uuid,omitempty"` +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/migrate/2020-01-01/machines/model_vmwaremachine.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/migrate/2020-01-01/machines/model_vmwaremachine.go new file mode 100644 index 000000000000..b51f2577378b --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/migrate/2020-01-01/machines/model_vmwaremachine.go @@ -0,0 +1,11 @@ +package machines + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type VMwareMachine struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *VMwareMachineProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/migrate/2020-01-01/machines/model_vmwaremachineproperties.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/migrate/2020-01-01/machines/model_vmwaremachineproperties.go new file mode 100644 index 000000000000..3d95d8a1a6bc --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/migrate/2020-01-01/machines/model_vmwaremachineproperties.go @@ -0,0 +1,73 @@ +package machines + +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 VMwareMachineProperties struct { + AllocatedMemoryInMB *float64 `json:"allocatedMemoryInMB,omitempty"` + AppsAndRoles *AppsAndRoles `json:"appsAndRoles,omitempty"` + BiosGuid *string `json:"biosGuid,omitempty"` + BiosSerialNumber *string `json:"biosSerialNumber,omitempty"` + ChangeTrackingEnabled *bool `json:"changeTrackingEnabled,omitempty"` + ChangeTrackingSupported *bool `json:"changeTrackingSupported,omitempty"` + CreatedTimestamp *string `json:"createdTimestamp,omitempty"` + DataCenterScope *string `json:"dataCenterScope,omitempty"` + DependencyMapping *string `json:"dependencyMapping,omitempty"` + DependencyMappingStartTime *string `json:"dependencyMappingStartTime,omitempty"` + Description *string `json:"description,omitempty"` + Disks *[]VMwareDisk `json:"disks,omitempty"` + DisplayName *string `json:"displayName,omitempty"` + Errors *[]HealthErrorDetails `json:"errors,omitempty"` + Firmware *string `json:"firmware,omitempty"` + GuestDetailsDiscoveryTimestamp *string `json:"guestDetailsDiscoveryTimestamp,omitempty"` + GuestOSDetails *GuestOSDetails `json:"guestOSDetails,omitempty"` + HostInMaintenanceMode *bool `json:"hostInMaintenanceMode,omitempty"` + HostName *string `json:"hostName,omitempty"` + HostPowerState *string `json:"hostPowerState,omitempty"` + HostVersion *string `json:"hostVersion,omitempty"` + InstanceUuid *string `json:"instanceUuid,omitempty"` + IsDeleted *bool `json:"isDeleted,omitempty"` + IsGuestDetailsDiscoveryInProgress *bool `json:"isGuestDetailsDiscoveryInProgress,omitempty"` + MaxSnapshots *int64 `json:"maxSnapshots,omitempty"` + NetworkAdapters *[]VMwareNetworkAdapter `json:"networkAdapters,omitempty"` + NumberOfApplications *int64 `json:"numberOfApplications,omitempty"` + NumberOfProcessorCore *int64 `json:"numberOfProcessorCore,omitempty"` + OperatingSystemDetails *OperatingSystem `json:"operatingSystemDetails,omitempty"` + PowerStatus *string `json:"powerStatus,omitempty"` + UpdatedTimestamp *string `json:"updatedTimestamp,omitempty"` + VCenterFQDN *string `json:"vCenterFQDN,omitempty"` + VCenterId *string `json:"vCenterId,omitempty"` + VMConfigurationFileLocation *string `json:"vmConfigurationFileLocation,omitempty"` + VMFqdn *string `json:"vmFqdn,omitempty"` + VMwareToolsStatus *string `json:"vMwareToolsStatus,omitempty"` +} + +func (o *VMwareMachineProperties) GetDependencyMappingStartTimeAsTime() (*time.Time, error) { + if o.DependencyMappingStartTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.DependencyMappingStartTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *VMwareMachineProperties) SetDependencyMappingStartTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.DependencyMappingStartTime = &formatted +} + +func (o *VMwareMachineProperties) GetGuestDetailsDiscoveryTimestampAsTime() (*time.Time, error) { + if o.GuestDetailsDiscoveryTimestamp == nil { + return nil, nil + } + return dates.ParseAsFormat(o.GuestDetailsDiscoveryTimestamp, "2006-01-02T15:04:05Z07:00") +} + +func (o *VMwareMachineProperties) SetGuestDetailsDiscoveryTimestampAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.GuestDetailsDiscoveryTimestamp = &formatted +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/migrate/2020-01-01/machines/model_vmwarenetworkadapter.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/migrate/2020-01-01/machines/model_vmwarenetworkadapter.go new file mode 100644 index 000000000000..3ffc1e25b8a7 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/migrate/2020-01-01/machines/model_vmwarenetworkadapter.go @@ -0,0 +1,13 @@ +package machines + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type VMwareNetworkAdapter struct { + IPAddressList *[]string `json:"ipAddressList,omitempty"` + IPAddressType *string `json:"ipAddressType,omitempty"` + Label *string `json:"label,omitempty"` + MacAddress *string `json:"macAddress,omitempty"` + NetworkName *string `json:"networkName,omitempty"` + NicId *string `json:"nicId,omitempty"` +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/migrate/2020-01-01/machines/model_webapplication.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/migrate/2020-01-01/machines/model_webapplication.go new file mode 100644 index 000000000000..fea275a48c88 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/migrate/2020-01-01/machines/model_webapplication.go @@ -0,0 +1,13 @@ +package machines + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type WebApplication struct { + ApplicationPool *string `json:"applicationPool,omitempty"` + GroupName *string `json:"groupName,omitempty"` + Name *string `json:"name,omitempty"` + Platform *string `json:"platform,omitempty"` + Status *string `json:"status,omitempty"` + WebServer *string `json:"webServer,omitempty"` +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/migrate/2020-01-01/machines/predicates.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/migrate/2020-01-01/machines/predicates.go new file mode 100644 index 000000000000..8b58b0f2f032 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/migrate/2020-01-01/machines/predicates.go @@ -0,0 +1,27 @@ +package machines + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type VMwareMachineOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p VMwareMachineOperationPredicate) Matches(input VMwareMachine) 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/migrate/2020-01-01/machines/version.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/migrate/2020-01-01/machines/version.go new file mode 100644 index 000000000000..c0980e7be08a --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/migrate/2020-01-01/machines/version.go @@ -0,0 +1,12 @@ +package machines + +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 = "2020-01-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/machines/%s", defaultApiVersion) +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/migrate/2020-01-01/runasaccounts/README.md b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/migrate/2020-01-01/runasaccounts/README.md new file mode 100644 index 000000000000..215d6f649894 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/migrate/2020-01-01/runasaccounts/README.md @@ -0,0 +1,53 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/migrate/2020-01-01/runasaccounts` Documentation + +The `runasaccounts` SDK allows for interaction with the Azure Resource Manager Service `migrate` (API Version `2020-01-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/migrate/2020-01-01/runasaccounts" +``` + + +### Client Initialization + +```go +client := runasaccounts.NewRunAsAccountsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `RunAsAccountsClient.GetAllRunAsAccountsInSite` + +```go +ctx := context.TODO() +id := runasaccounts.NewVMwareSiteID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vmwareSiteValue") + +// alternatively `client.GetAllRunAsAccountsInSite(ctx, id)` can be used to do batched pagination +items, err := client.GetAllRunAsAccountsInSiteComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `RunAsAccountsClient.GetRunAsAccount` + +```go +ctx := context.TODO() +id := runasaccounts.NewVMwareSiteRunAsAccountID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vmwareSiteValue", "runAsAccountValue") + +read, err := client.GetRunAsAccount(ctx, id) +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/migrate/2020-01-01/runasaccounts/client.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/migrate/2020-01-01/runasaccounts/client.go new file mode 100644 index 000000000000..d117011f8e54 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/migrate/2020-01-01/runasaccounts/client.go @@ -0,0 +1,26 @@ +package runasaccounts + +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RunAsAccountsClient struct { + Client *resourcemanager.Client +} + +func NewRunAsAccountsClientWithBaseURI(api environments.Api) (*RunAsAccountsClient, error) { + client, err := resourcemanager.NewResourceManagerClient(api, "runasaccounts", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating RunAsAccountsClient: %+v", err) + } + + return &RunAsAccountsClient{ + Client: client, + }, nil +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/migrate/2020-01-01/runasaccounts/constants.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/migrate/2020-01-01/runasaccounts/constants.go new file mode 100644 index 000000000000..b800ddda1e76 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/migrate/2020-01-01/runasaccounts/constants.go @@ -0,0 +1,63 @@ +package runasaccounts + +import ( + "encoding/json" + "fmt" + "strings" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CredentialType string + +const ( + CredentialTypeHyperVFabric CredentialType = "HyperVFabric" + CredentialTypeLinuxGuest CredentialType = "LinuxGuest" + CredentialTypeLinuxServer CredentialType = "LinuxServer" + CredentialTypeVMwareFabric CredentialType = "VMwareFabric" + CredentialTypeWindowsGuest CredentialType = "WindowsGuest" + CredentialTypeWindowsServer CredentialType = "WindowsServer" +) + +func PossibleValuesForCredentialType() []string { + return []string{ + string(CredentialTypeHyperVFabric), + string(CredentialTypeLinuxGuest), + string(CredentialTypeLinuxServer), + string(CredentialTypeVMwareFabric), + string(CredentialTypeWindowsGuest), + string(CredentialTypeWindowsServer), + } +} + +func (s *CredentialType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseCredentialType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseCredentialType(input string) (*CredentialType, error) { + vals := map[string]CredentialType{ + "hypervfabric": CredentialTypeHyperVFabric, + "linuxguest": CredentialTypeLinuxGuest, + "linuxserver": CredentialTypeLinuxServer, + "vmwarefabric": CredentialTypeVMwareFabric, + "windowsguest": CredentialTypeWindowsGuest, + "windowsserver": CredentialTypeWindowsServer, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := CredentialType(input) + return &out, nil +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/migrate/2020-01-01/runasaccounts/id_vmwaresite.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/migrate/2020-01-01/runasaccounts/id_vmwaresite.go new file mode 100644 index 000000000000..efaf5b4477f6 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/migrate/2020-01-01/runasaccounts/id_vmwaresite.go @@ -0,0 +1,127 @@ +package runasaccounts + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = VMwareSiteId{} + +// VMwareSiteId is a struct representing the Resource ID for a V Mware Site +type VMwareSiteId struct { + SubscriptionId string + ResourceGroupName string + VmwareSiteName string +} + +// NewVMwareSiteID returns a new VMwareSiteId struct +func NewVMwareSiteID(subscriptionId string, resourceGroupName string, vmwareSiteName string) VMwareSiteId { + return VMwareSiteId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + VmwareSiteName: vmwareSiteName, + } +} + +// ParseVMwareSiteID parses 'input' into a VMwareSiteId +func ParseVMwareSiteID(input string) (*VMwareSiteId, error) { + parser := resourceids.NewParserFromResourceIdType(VMwareSiteId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := VMwareSiteId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", *parsed) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", *parsed) + } + + if id.VmwareSiteName, ok = parsed.Parsed["vmwareSiteName"]; !ok { + return nil, resourceids.NewSegmentNotSpecifiedError(id, "vmwareSiteName", *parsed) + } + + return &id, nil +} + +// ParseVMwareSiteIDInsensitively parses 'input' case-insensitively into a VMwareSiteId +// note: this method should only be used for API response data and not user input +func ParseVMwareSiteIDInsensitively(input string) (*VMwareSiteId, error) { + parser := resourceids.NewParserFromResourceIdType(VMwareSiteId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := VMwareSiteId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", *parsed) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", *parsed) + } + + if id.VmwareSiteName, ok = parsed.Parsed["vmwareSiteName"]; !ok { + return nil, resourceids.NewSegmentNotSpecifiedError(id, "vmwareSiteName", *parsed) + } + + return &id, nil +} + +// ValidateVMwareSiteID checks that 'input' can be parsed as a V Mware Site ID +func ValidateVMwareSiteID(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 := ParseVMwareSiteID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted V Mware Site ID +func (id VMwareSiteId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.OffAzure/vmwareSites/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.VmwareSiteName) +} + +// Segments returns a slice of Resource ID Segments which comprise this V Mware Site ID +func (id VMwareSiteId) 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("staticMicrosoftOffAzure", "Microsoft.OffAzure", "Microsoft.OffAzure"), + resourceids.StaticSegment("staticVmwareSites", "vmwareSites", "vmwareSites"), + resourceids.UserSpecifiedSegment("vmwareSiteName", "vmwareSiteValue"), + } +} + +// String returns a human-readable description of this V Mware Site ID +func (id VMwareSiteId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Vmware Site Name: %q", id.VmwareSiteName), + } + return fmt.Sprintf("V Mware Site (%s)", strings.Join(components, "\n")) +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/migrate/2020-01-01/runasaccounts/method_getallrunasaccountsinsite.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/migrate/2020-01-01/runasaccounts/method_getallrunasaccountsinsite.go new file mode 100644 index 000000000000..bb7345b48a4e --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/migrate/2020-01-01/runasaccounts/method_getallrunasaccountsinsite.go @@ -0,0 +1,89 @@ +package runasaccounts + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetAllRunAsAccountsInSiteOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]VMwareRunAsAccount +} + +type GetAllRunAsAccountsInSiteCompleteResult struct { + Items []VMwareRunAsAccount +} + +// GetAllRunAsAccountsInSite ... +func (c RunAsAccountsClient) GetAllRunAsAccountsInSite(ctx context.Context, id VMwareSiteId) (result GetAllRunAsAccountsInSiteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/runAsAccounts", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]VMwareRunAsAccount `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// GetAllRunAsAccountsInSiteComplete retrieves all the results into a single object +func (c RunAsAccountsClient) GetAllRunAsAccountsInSiteComplete(ctx context.Context, id VMwareSiteId) (GetAllRunAsAccountsInSiteCompleteResult, error) { + return c.GetAllRunAsAccountsInSiteCompleteMatchingPredicate(ctx, id, VMwareRunAsAccountOperationPredicate{}) +} + +// GetAllRunAsAccountsInSiteCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c RunAsAccountsClient) GetAllRunAsAccountsInSiteCompleteMatchingPredicate(ctx context.Context, id VMwareSiteId, predicate VMwareRunAsAccountOperationPredicate) (result GetAllRunAsAccountsInSiteCompleteResult, err error) { + items := make([]VMwareRunAsAccount, 0) + + resp, err := c.GetAllRunAsAccountsInSite(ctx, id) + if err != nil { + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = GetAllRunAsAccountsInSiteCompleteResult{ + Items: items, + } + return +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/migrate/2020-01-01/runasaccounts/method_getrunasaccount.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/migrate/2020-01-01/runasaccounts/method_getrunasaccount.go new file mode 100644 index 000000000000..7acf449765c0 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/migrate/2020-01-01/runasaccounts/method_getrunasaccount.go @@ -0,0 +1,52 @@ +package runasaccounts + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetRunAsAccountOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *VMwareRunAsAccount +} + +// GetRunAsAccount ... +func (c RunAsAccountsClient) GetRunAsAccount(ctx context.Context, id commonids.VMwareSiteRunAsAccountId) (result GetRunAsAccountOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/migrate/2020-01-01/runasaccounts/model_runasaccountproperties.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/migrate/2020-01-01/runasaccounts/model_runasaccountproperties.go new file mode 100644 index 000000000000..568a58ae0217 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/migrate/2020-01-01/runasaccounts/model_runasaccountproperties.go @@ -0,0 +1,11 @@ +package runasaccounts + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RunAsAccountProperties struct { + CreatedTimestamp *string `json:"createdTimestamp,omitempty"` + CredentialType *CredentialType `json:"credentialType,omitempty"` + DisplayName *string `json:"displayName,omitempty"` + UpdatedTimestamp *string `json:"updatedTimestamp,omitempty"` +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/migrate/2020-01-01/runasaccounts/model_vmwarerunasaccount.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/migrate/2020-01-01/runasaccounts/model_vmwarerunasaccount.go new file mode 100644 index 000000000000..960acd23b420 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/migrate/2020-01-01/runasaccounts/model_vmwarerunasaccount.go @@ -0,0 +1,11 @@ +package runasaccounts + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type VMwareRunAsAccount struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *RunAsAccountProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/migrate/2020-01-01/runasaccounts/predicates.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/migrate/2020-01-01/runasaccounts/predicates.go new file mode 100644 index 000000000000..d1a8b7a5cffb --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/migrate/2020-01-01/runasaccounts/predicates.go @@ -0,0 +1,27 @@ +package runasaccounts + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type VMwareRunAsAccountOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p VMwareRunAsAccountOperationPredicate) Matches(input VMwareRunAsAccount) 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/migrate/2020-01-01/runasaccounts/version.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/migrate/2020-01-01/runasaccounts/version.go new file mode 100644 index 000000000000..8c3c4c0c7b81 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/migrate/2020-01-01/runasaccounts/version.go @@ -0,0 +1,12 @@ +package runasaccounts + +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 = "2020-01-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/runasaccounts/%s", defaultApiVersion) +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2022-10-01/replicationprotectableitems/README.md b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2022-10-01/replicationprotectableitems/README.md new file mode 100644 index 000000000000..cb5b55687b0b --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2022-10-01/replicationprotectableitems/README.md @@ -0,0 +1,53 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2022-10-01/replicationprotectableitems` Documentation + +The `replicationprotectableitems` SDK allows for interaction with the Azure Resource Manager Service `recoveryservicessiterecovery` (API Version `2022-10-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/recoveryservicessiterecovery/2022-10-01/replicationprotectableitems" +``` + + +### Client Initialization + +```go +client := replicationprotectableitems.NewReplicationProtectableItemsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `ReplicationProtectableItemsClient.Get` + +```go +ctx := context.TODO() +id := replicationprotectableitems.NewReplicationProtectableItemID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue", "replicationFabricValue", "replicationProtectionContainerValue", "replicationProtectableItemValue") + +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: `ReplicationProtectableItemsClient.ListByReplicationProtectionContainers` + +```go +ctx := context.TODO() +id := replicationprotectableitems.NewReplicationProtectionContainerID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue", "replicationFabricValue", "replicationProtectionContainerValue") + +// alternatively `client.ListByReplicationProtectionContainers(ctx, id, replicationprotectableitems.DefaultListByReplicationProtectionContainersOperationOptions())` can be used to do batched pagination +items, err := client.ListByReplicationProtectionContainersComplete(ctx, id, replicationprotectableitems.DefaultListByReplicationProtectionContainersOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2022-10-01/replicationprotectableitems/client.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2022-10-01/replicationprotectableitems/client.go new file mode 100644 index 000000000000..cd1356d41c0a --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2022-10-01/replicationprotectableitems/client.go @@ -0,0 +1,18 @@ +package replicationprotectableitems + +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 ReplicationProtectableItemsClient struct { + Client autorest.Client + baseUri string +} + +func NewReplicationProtectableItemsClientWithBaseURI(endpoint string) ReplicationProtectableItemsClient { + return ReplicationProtectableItemsClient{ + Client: autorest.NewClientWithUserAgent(userAgent()), + baseUri: endpoint, + } +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2022-10-01/replicationprotectableitems/constants.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2022-10-01/replicationprotectableitems/constants.go new file mode 100644 index 000000000000..7ae2eaa30c8b --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2022-10-01/replicationprotectableitems/constants.go @@ -0,0 +1,65 @@ +package replicationprotectableitems + +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 HealthErrorCustomerResolvability string + +const ( + HealthErrorCustomerResolvabilityAllowed HealthErrorCustomerResolvability = "Allowed" + HealthErrorCustomerResolvabilityNotAllowed HealthErrorCustomerResolvability = "NotAllowed" +) + +func PossibleValuesForHealthErrorCustomerResolvability() []string { + return []string{ + string(HealthErrorCustomerResolvabilityAllowed), + string(HealthErrorCustomerResolvabilityNotAllowed), + } +} + +func parseHealthErrorCustomerResolvability(input string) (*HealthErrorCustomerResolvability, error) { + vals := map[string]HealthErrorCustomerResolvability{ + "allowed": HealthErrorCustomerResolvabilityAllowed, + "notallowed": HealthErrorCustomerResolvabilityNotAllowed, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := HealthErrorCustomerResolvability(input) + return &out, nil +} + +type PresenceStatus string + +const ( + PresenceStatusNotPresent PresenceStatus = "NotPresent" + PresenceStatusPresent PresenceStatus = "Present" + PresenceStatusUnknown PresenceStatus = "Unknown" +) + +func PossibleValuesForPresenceStatus() []string { + return []string{ + string(PresenceStatusNotPresent), + string(PresenceStatusPresent), + string(PresenceStatusUnknown), + } +} + +func parsePresenceStatus(input string) (*PresenceStatus, error) { + vals := map[string]PresenceStatus{ + "notpresent": PresenceStatusNotPresent, + "present": PresenceStatusPresent, + "unknown": PresenceStatusUnknown, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := PresenceStatus(input) + return &out, nil +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2022-10-01/replicationprotectableitems/id_replicationprotectableitem.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2022-10-01/replicationprotectableitems/id_replicationprotectableitem.go new file mode 100644 index 000000000000..f7f0b3936cee --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2022-10-01/replicationprotectableitems/id_replicationprotectableitem.go @@ -0,0 +1,166 @@ +package replicationprotectableitems + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = ReplicationProtectableItemId{} + +// ReplicationProtectableItemId is a struct representing the Resource ID for a Replication Protectable Item +type ReplicationProtectableItemId struct { + SubscriptionId string + ResourceGroupName string + VaultName string + ReplicationFabricName string + ReplicationProtectionContainerName string + ReplicationProtectableItemName string +} + +// NewReplicationProtectableItemID returns a new ReplicationProtectableItemId struct +func NewReplicationProtectableItemID(subscriptionId string, resourceGroupName string, vaultName string, replicationFabricName string, replicationProtectionContainerName string, replicationProtectableItemName string) ReplicationProtectableItemId { + return ReplicationProtectableItemId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + VaultName: vaultName, + ReplicationFabricName: replicationFabricName, + ReplicationProtectionContainerName: replicationProtectionContainerName, + ReplicationProtectableItemName: replicationProtectableItemName, + } +} + +// ParseReplicationProtectableItemID parses 'input' into a ReplicationProtectableItemId +func ParseReplicationProtectableItemID(input string) (*ReplicationProtectableItemId, error) { + parser := resourceids.NewParserFromResourceIdType(ReplicationProtectableItemId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := ReplicationProtectableItemId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", *parsed) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", *parsed) + } + + if id.VaultName, ok = parsed.Parsed["vaultName"]; !ok { + return nil, resourceids.NewSegmentNotSpecifiedError(id, "vaultName", *parsed) + } + + if id.ReplicationFabricName, ok = parsed.Parsed["replicationFabricName"]; !ok { + return nil, resourceids.NewSegmentNotSpecifiedError(id, "replicationFabricName", *parsed) + } + + if id.ReplicationProtectionContainerName, ok = parsed.Parsed["replicationProtectionContainerName"]; !ok { + return nil, resourceids.NewSegmentNotSpecifiedError(id, "replicationProtectionContainerName", *parsed) + } + + if id.ReplicationProtectableItemName, ok = parsed.Parsed["replicationProtectableItemName"]; !ok { + return nil, resourceids.NewSegmentNotSpecifiedError(id, "replicationProtectableItemName", *parsed) + } + + return &id, nil +} + +// ParseReplicationProtectableItemIDInsensitively parses 'input' case-insensitively into a ReplicationProtectableItemId +// note: this method should only be used for API response data and not user input +func ParseReplicationProtectableItemIDInsensitively(input string) (*ReplicationProtectableItemId, error) { + parser := resourceids.NewParserFromResourceIdType(ReplicationProtectableItemId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := ReplicationProtectableItemId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", *parsed) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", *parsed) + } + + if id.VaultName, ok = parsed.Parsed["vaultName"]; !ok { + return nil, resourceids.NewSegmentNotSpecifiedError(id, "vaultName", *parsed) + } + + if id.ReplicationFabricName, ok = parsed.Parsed["replicationFabricName"]; !ok { + return nil, resourceids.NewSegmentNotSpecifiedError(id, "replicationFabricName", *parsed) + } + + if id.ReplicationProtectionContainerName, ok = parsed.Parsed["replicationProtectionContainerName"]; !ok { + return nil, resourceids.NewSegmentNotSpecifiedError(id, "replicationProtectionContainerName", *parsed) + } + + if id.ReplicationProtectableItemName, ok = parsed.Parsed["replicationProtectableItemName"]; !ok { + return nil, resourceids.NewSegmentNotSpecifiedError(id, "replicationProtectableItemName", *parsed) + } + + return &id, nil +} + +// ValidateReplicationProtectableItemID checks that 'input' can be parsed as a Replication Protectable Item ID +func ValidateReplicationProtectableItemID(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 := ParseReplicationProtectableItemID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Replication Protectable Item ID +func (id ReplicationProtectableItemId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.RecoveryServices/vaults/%s/replicationFabrics/%s/replicationProtectionContainers/%s/replicationProtectableItems/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.VaultName, id.ReplicationFabricName, id.ReplicationProtectionContainerName, id.ReplicationProtectableItemName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Replication Protectable Item ID +func (id ReplicationProtectableItemId) 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("staticMicrosoftRecoveryServices", "Microsoft.RecoveryServices", "Microsoft.RecoveryServices"), + resourceids.StaticSegment("staticVaults", "vaults", "vaults"), + resourceids.UserSpecifiedSegment("vaultName", "vaultValue"), + resourceids.StaticSegment("staticReplicationFabrics", "replicationFabrics", "replicationFabrics"), + resourceids.UserSpecifiedSegment("replicationFabricName", "replicationFabricValue"), + resourceids.StaticSegment("staticReplicationProtectionContainers", "replicationProtectionContainers", "replicationProtectionContainers"), + resourceids.UserSpecifiedSegment("replicationProtectionContainerName", "replicationProtectionContainerValue"), + resourceids.StaticSegment("staticReplicationProtectableItems", "replicationProtectableItems", "replicationProtectableItems"), + resourceids.UserSpecifiedSegment("replicationProtectableItemName", "replicationProtectableItemValue"), + } +} + +// String returns a human-readable description of this Replication Protectable Item ID +func (id ReplicationProtectableItemId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Vault Name: %q", id.VaultName), + fmt.Sprintf("Replication Fabric Name: %q", id.ReplicationFabricName), + fmt.Sprintf("Replication Protection Container Name: %q", id.ReplicationProtectionContainerName), + fmt.Sprintf("Replication Protectable Item Name: %q", id.ReplicationProtectableItemName), + } + return fmt.Sprintf("Replication Protectable Item (%s)", strings.Join(components, "\n")) +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2022-10-01/replicationprotectableitems/id_replicationprotectioncontainer.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2022-10-01/replicationprotectableitems/id_replicationprotectioncontainer.go new file mode 100644 index 000000000000..927a68eca8c3 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2022-10-01/replicationprotectableitems/id_replicationprotectioncontainer.go @@ -0,0 +1,153 @@ +package replicationprotectableitems + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = ReplicationProtectionContainerId{} + +// ReplicationProtectionContainerId is a struct representing the Resource ID for a Replication Protection Container +type ReplicationProtectionContainerId struct { + SubscriptionId string + ResourceGroupName string + VaultName string + ReplicationFabricName string + ReplicationProtectionContainerName string +} + +// NewReplicationProtectionContainerID returns a new ReplicationProtectionContainerId struct +func NewReplicationProtectionContainerID(subscriptionId string, resourceGroupName string, vaultName string, replicationFabricName string, replicationProtectionContainerName string) ReplicationProtectionContainerId { + return ReplicationProtectionContainerId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + VaultName: vaultName, + ReplicationFabricName: replicationFabricName, + ReplicationProtectionContainerName: replicationProtectionContainerName, + } +} + +// ParseReplicationProtectionContainerID parses 'input' into a ReplicationProtectionContainerId +func ParseReplicationProtectionContainerID(input string) (*ReplicationProtectionContainerId, error) { + parser := resourceids.NewParserFromResourceIdType(ReplicationProtectionContainerId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := ReplicationProtectionContainerId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", *parsed) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", *parsed) + } + + if id.VaultName, ok = parsed.Parsed["vaultName"]; !ok { + return nil, resourceids.NewSegmentNotSpecifiedError(id, "vaultName", *parsed) + } + + if id.ReplicationFabricName, ok = parsed.Parsed["replicationFabricName"]; !ok { + return nil, resourceids.NewSegmentNotSpecifiedError(id, "replicationFabricName", *parsed) + } + + if id.ReplicationProtectionContainerName, ok = parsed.Parsed["replicationProtectionContainerName"]; !ok { + return nil, resourceids.NewSegmentNotSpecifiedError(id, "replicationProtectionContainerName", *parsed) + } + + return &id, nil +} + +// ParseReplicationProtectionContainerIDInsensitively parses 'input' case-insensitively into a ReplicationProtectionContainerId +// note: this method should only be used for API response data and not user input +func ParseReplicationProtectionContainerIDInsensitively(input string) (*ReplicationProtectionContainerId, error) { + parser := resourceids.NewParserFromResourceIdType(ReplicationProtectionContainerId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := ReplicationProtectionContainerId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", *parsed) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", *parsed) + } + + if id.VaultName, ok = parsed.Parsed["vaultName"]; !ok { + return nil, resourceids.NewSegmentNotSpecifiedError(id, "vaultName", *parsed) + } + + if id.ReplicationFabricName, ok = parsed.Parsed["replicationFabricName"]; !ok { + return nil, resourceids.NewSegmentNotSpecifiedError(id, "replicationFabricName", *parsed) + } + + if id.ReplicationProtectionContainerName, ok = parsed.Parsed["replicationProtectionContainerName"]; !ok { + return nil, resourceids.NewSegmentNotSpecifiedError(id, "replicationProtectionContainerName", *parsed) + } + + return &id, nil +} + +// ValidateReplicationProtectionContainerID checks that 'input' can be parsed as a Replication Protection Container ID +func ValidateReplicationProtectionContainerID(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 := ParseReplicationProtectionContainerID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Replication Protection Container ID +func (id ReplicationProtectionContainerId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.RecoveryServices/vaults/%s/replicationFabrics/%s/replicationProtectionContainers/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.VaultName, id.ReplicationFabricName, id.ReplicationProtectionContainerName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Replication Protection Container ID +func (id ReplicationProtectionContainerId) 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("staticMicrosoftRecoveryServices", "Microsoft.RecoveryServices", "Microsoft.RecoveryServices"), + resourceids.StaticSegment("staticVaults", "vaults", "vaults"), + resourceids.UserSpecifiedSegment("vaultName", "vaultValue"), + resourceids.StaticSegment("staticReplicationFabrics", "replicationFabrics", "replicationFabrics"), + resourceids.UserSpecifiedSegment("replicationFabricName", "replicationFabricValue"), + resourceids.StaticSegment("staticReplicationProtectionContainers", "replicationProtectionContainers", "replicationProtectionContainers"), + resourceids.UserSpecifiedSegment("replicationProtectionContainerName", "replicationProtectionContainerValue"), + } +} + +// String returns a human-readable description of this Replication Protection Container ID +func (id ReplicationProtectionContainerId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Vault Name: %q", id.VaultName), + fmt.Sprintf("Replication Fabric Name: %q", id.ReplicationFabricName), + fmt.Sprintf("Replication Protection Container Name: %q", id.ReplicationProtectionContainerName), + } + return fmt.Sprintf("Replication Protection Container (%s)", strings.Join(components, "\n")) +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2022-10-01/replicationprotectableitems/method_get_autorest.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2022-10-01/replicationprotectableitems/method_get_autorest.go new file mode 100644 index 000000000000..5f174d7a1ccf --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2022-10-01/replicationprotectableitems/method_get_autorest.go @@ -0,0 +1,68 @@ +package replicationprotectableitems + +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 *ProtectableItem +} + +// Get ... +func (c ReplicationProtectableItemsClient) Get(ctx context.Context, id ReplicationProtectableItemId) (result GetOperationResponse, err error) { + req, err := c.preparerForGet(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationprotectableitems.ReplicationProtectableItemsClient", "Get", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationprotectableitems.ReplicationProtectableItemsClient", "Get", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForGet(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationprotectableitems.ReplicationProtectableItemsClient", "Get", result.HttpResponse, "Failure responding to request") + return + } + + return +} + +// preparerForGet prepares the Get request. +func (c ReplicationProtectableItemsClient) preparerForGet(ctx context.Context, id ReplicationProtectableItemId) (*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 ReplicationProtectableItemsClient) 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/recoveryservicessiterecovery/2022-10-01/replicationprotectableitems/method_listbyreplicationprotectioncontainers_autorest.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2022-10-01/replicationprotectableitems/method_listbyreplicationprotectioncontainers_autorest.go new file mode 100644 index 000000000000..5c77821d594b --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2022-10-01/replicationprotectableitems/method_listbyreplicationprotectioncontainers_autorest.go @@ -0,0 +1,220 @@ +package replicationprotectableitems + +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 ListByReplicationProtectionContainersOperationResponse struct { + HttpResponse *http.Response + Model *[]ProtectableItem + + nextLink *string + nextPageFunc func(ctx context.Context, nextLink string) (ListByReplicationProtectionContainersOperationResponse, error) +} + +type ListByReplicationProtectionContainersCompleteResult struct { + Items []ProtectableItem +} + +func (r ListByReplicationProtectionContainersOperationResponse) HasMore() bool { + return r.nextLink != nil +} + +func (r ListByReplicationProtectionContainersOperationResponse) LoadMore(ctx context.Context) (resp ListByReplicationProtectionContainersOperationResponse, err error) { + if !r.HasMore() { + err = fmt.Errorf("no more pages returned") + return + } + return r.nextPageFunc(ctx, *r.nextLink) +} + +type ListByReplicationProtectionContainersOperationOptions struct { + Filter *string + Take *string +} + +func DefaultListByReplicationProtectionContainersOperationOptions() ListByReplicationProtectionContainersOperationOptions { + return ListByReplicationProtectionContainersOperationOptions{} +} + +func (o ListByReplicationProtectionContainersOperationOptions) toHeaders() map[string]interface{} { + out := make(map[string]interface{}) + + return out +} + +func (o ListByReplicationProtectionContainersOperationOptions) toQueryString() map[string]interface{} { + out := make(map[string]interface{}) + + if o.Filter != nil { + out["$filter"] = *o.Filter + } + + if o.Take != nil { + out["$take"] = *o.Take + } + + return out +} + +// ListByReplicationProtectionContainers ... +func (c ReplicationProtectableItemsClient) ListByReplicationProtectionContainers(ctx context.Context, id ReplicationProtectionContainerId, options ListByReplicationProtectionContainersOperationOptions) (resp ListByReplicationProtectionContainersOperationResponse, err error) { + req, err := c.preparerForListByReplicationProtectionContainers(ctx, id, options) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationprotectableitems.ReplicationProtectableItemsClient", "ListByReplicationProtectionContainers", nil, "Failure preparing request") + return + } + + resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationprotectableitems.ReplicationProtectableItemsClient", "ListByReplicationProtectionContainers", resp.HttpResponse, "Failure sending request") + return + } + + resp, err = c.responderForListByReplicationProtectionContainers(resp.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationprotectableitems.ReplicationProtectableItemsClient", "ListByReplicationProtectionContainers", resp.HttpResponse, "Failure responding to request") + return + } + return +} + +// preparerForListByReplicationProtectionContainers prepares the ListByReplicationProtectionContainers request. +func (c ReplicationProtectableItemsClient) preparerForListByReplicationProtectionContainers(ctx context.Context, id ReplicationProtectionContainerId, options ListByReplicationProtectionContainersOperationOptions) (*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/replicationProtectableItems", id.ID())), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// preparerForListByReplicationProtectionContainersWithNextLink prepares the ListByReplicationProtectionContainers request with the given nextLink token. +func (c ReplicationProtectableItemsClient) preparerForListByReplicationProtectionContainersWithNextLink(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)) +} + +// responderForListByReplicationProtectionContainers handles the response to the ListByReplicationProtectionContainers request. The method always +// closes the http.Response Body. +func (c ReplicationProtectableItemsClient) responderForListByReplicationProtectionContainers(resp *http.Response) (result ListByReplicationProtectionContainersOperationResponse, err error) { + type page struct { + Values []ProtectableItem `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 ListByReplicationProtectionContainersOperationResponse, err error) { + req, err := c.preparerForListByReplicationProtectionContainersWithNextLink(ctx, nextLink) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationprotectableitems.ReplicationProtectableItemsClient", "ListByReplicationProtectionContainers", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationprotectableitems.ReplicationProtectableItemsClient", "ListByReplicationProtectionContainers", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForListByReplicationProtectionContainers(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationprotectableitems.ReplicationProtectableItemsClient", "ListByReplicationProtectionContainers", result.HttpResponse, "Failure responding to request") + return + } + + return + } + } + return +} + +// ListByReplicationProtectionContainersComplete retrieves all of the results into a single object +func (c ReplicationProtectableItemsClient) ListByReplicationProtectionContainersComplete(ctx context.Context, id ReplicationProtectionContainerId, options ListByReplicationProtectionContainersOperationOptions) (ListByReplicationProtectionContainersCompleteResult, error) { + return c.ListByReplicationProtectionContainersCompleteMatchingPredicate(ctx, id, options, ProtectableItemOperationPredicate{}) +} + +// ListByReplicationProtectionContainersCompleteMatchingPredicate retrieves all of the results and then applied the predicate +func (c ReplicationProtectableItemsClient) ListByReplicationProtectionContainersCompleteMatchingPredicate(ctx context.Context, id ReplicationProtectionContainerId, options ListByReplicationProtectionContainersOperationOptions, predicate ProtectableItemOperationPredicate) (resp ListByReplicationProtectionContainersCompleteResult, err error) { + items := make([]ProtectableItem, 0) + + page, err := c.ListByReplicationProtectionContainers(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 := ListByReplicationProtectionContainersCompleteResult{ + Items: items, + } + return out, nil +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2022-10-01/replicationprotectableitems/model_configurationsettings.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2022-10-01/replicationprotectableitems/model_configurationsettings.go new file mode 100644 index 000000000000..4d071558c6cb --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2022-10-01/replicationprotectableitems/model_configurationsettings.go @@ -0,0 +1,64 @@ +package replicationprotectableitems + +import ( + "encoding/json" + "fmt" + "strings" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ConfigurationSettings interface { +} + +func unmarshalConfigurationSettingsImplementation(input []byte) (ConfigurationSettings, error) { + if input == nil { + return nil, nil + } + + var temp map[string]interface{} + if err := json.Unmarshal(input, &temp); err != nil { + return nil, fmt.Errorf("unmarshaling ConfigurationSettings into map[string]interface: %+v", err) + } + + value, ok := temp["instanceType"].(string) + if !ok { + return nil, nil + } + + if strings.EqualFold(value, "HyperVVirtualMachine") { + var out HyperVVirtualMachineDetails + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into HyperVVirtualMachineDetails: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "ReplicationGroupDetails") { + var out ReplicationGroupDetails + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into ReplicationGroupDetails: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "VMwareVirtualMachine") { + var out VMwareVirtualMachineDetails + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into VMwareVirtualMachineDetails: %+v", err) + } + return out, nil + } + + type RawConfigurationSettingsImpl struct { + Type string `json:"-"` + Values map[string]interface{} `json:"-"` + } + out := RawConfigurationSettingsImpl{ + Type: value, + Values: temp, + } + return out, nil + +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2022-10-01/replicationprotectableitems/model_diskdetails.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2022-10-01/replicationprotectableitems/model_diskdetails.go new file mode 100644 index 000000000000..f418a8a199ab --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2022-10-01/replicationprotectableitems/model_diskdetails.go @@ -0,0 +1,11 @@ +package replicationprotectableitems + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DiskDetails struct { + MaxSizeMB *int64 `json:"maxSizeMB,omitempty"` + VhdId *string `json:"vhdId,omitempty"` + VhdName *string `json:"vhdName,omitempty"` + VhdType *string `json:"vhdType,omitempty"` +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2022-10-01/replicationprotectableitems/model_diskvolumedetails.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2022-10-01/replicationprotectableitems/model_diskvolumedetails.go new file mode 100644 index 000000000000..a1807b2e5d90 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2022-10-01/replicationprotectableitems/model_diskvolumedetails.go @@ -0,0 +1,9 @@ +package replicationprotectableitems + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DiskVolumeDetails struct { + Label *string `json:"label,omitempty"` + Name *string `json:"name,omitempty"` +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2022-10-01/replicationprotectableitems/model_healtherror.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2022-10-01/replicationprotectableitems/model_healtherror.go new file mode 100644 index 000000000000..dd836fd7405e --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2022-10-01/replicationprotectableitems/model_healtherror.go @@ -0,0 +1,40 @@ +package replicationprotectableitems + +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 HealthError struct { + CreationTimeUtc *string `json:"creationTimeUtc,omitempty"` + CustomerResolvability *HealthErrorCustomerResolvability `json:"customerResolvability,omitempty"` + EntityId *string `json:"entityId,omitempty"` + ErrorCategory *string `json:"errorCategory,omitempty"` + ErrorCode *string `json:"errorCode,omitempty"` + ErrorId *string `json:"errorId,omitempty"` + ErrorLevel *string `json:"errorLevel,omitempty"` + ErrorMessage *string `json:"errorMessage,omitempty"` + ErrorSource *string `json:"errorSource,omitempty"` + ErrorType *string `json:"errorType,omitempty"` + InnerHealthErrors *[]InnerHealthError `json:"innerHealthErrors,omitempty"` + PossibleCauses *string `json:"possibleCauses,omitempty"` + RecommendedAction *string `json:"recommendedAction,omitempty"` + RecoveryProviderErrorMessage *string `json:"recoveryProviderErrorMessage,omitempty"` + SummaryMessage *string `json:"summaryMessage,omitempty"` +} + +func (o *HealthError) GetCreationTimeUtcAsTime() (*time.Time, error) { + if o.CreationTimeUtc == nil { + return nil, nil + } + return dates.ParseAsFormat(o.CreationTimeUtc, "2006-01-02T15:04:05Z07:00") +} + +func (o *HealthError) SetCreationTimeUtcAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.CreationTimeUtc = &formatted +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2022-10-01/replicationprotectableitems/model_hypervvirtualmachinedetails.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2022-10-01/replicationprotectableitems/model_hypervvirtualmachinedetails.go new file mode 100644 index 000000000000..73a1c26e7088 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2022-10-01/replicationprotectableitems/model_hypervvirtualmachinedetails.go @@ -0,0 +1,48 @@ +package replicationprotectableitems + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ ConfigurationSettings = HyperVVirtualMachineDetails{} + +type HyperVVirtualMachineDetails struct { + DiskDetails *[]DiskDetails `json:"diskDetails,omitempty"` + Generation *string `json:"generation,omitempty"` + HasFibreChannelAdapter *PresenceStatus `json:"hasFibreChannelAdapter,omitempty"` + HasPhysicalDisk *PresenceStatus `json:"hasPhysicalDisk,omitempty"` + HasSharedVhd *PresenceStatus `json:"hasSharedVhd,omitempty"` + HyperVHostId *string `json:"hyperVHostId,omitempty"` + OsDetails *OSDetails `json:"osDetails,omitempty"` + SourceItemId *string `json:"sourceItemId,omitempty"` + + // Fields inherited from ConfigurationSettings +} + +var _ json.Marshaler = HyperVVirtualMachineDetails{} + +func (s HyperVVirtualMachineDetails) MarshalJSON() ([]byte, error) { + type wrapper HyperVVirtualMachineDetails + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling HyperVVirtualMachineDetails: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling HyperVVirtualMachineDetails: %+v", err) + } + decoded["instanceType"] = "HyperVVirtualMachine" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling HyperVVirtualMachineDetails: %+v", err) + } + + return encoded, nil +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2022-10-01/replicationprotectableitems/model_inmagediskdetails.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2022-10-01/replicationprotectableitems/model_inmagediskdetails.go new file mode 100644 index 000000000000..a4233f281363 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2022-10-01/replicationprotectableitems/model_inmagediskdetails.go @@ -0,0 +1,13 @@ +package replicationprotectableitems + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type InMageDiskDetails struct { + DiskConfiguration *string `json:"diskConfiguration,omitempty"` + DiskId *string `json:"diskId,omitempty"` + DiskName *string `json:"diskName,omitempty"` + DiskSizeInMB *string `json:"diskSizeInMB,omitempty"` + DiskType *string `json:"diskType,omitempty"` + VolumeList *[]DiskVolumeDetails `json:"volumeList,omitempty"` +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2022-10-01/replicationprotectableitems/model_innerhealtherror.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2022-10-01/replicationprotectableitems/model_innerhealtherror.go new file mode 100644 index 000000000000..ee306e7b2305 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2022-10-01/replicationprotectableitems/model_innerhealtherror.go @@ -0,0 +1,39 @@ +package replicationprotectableitems + +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 InnerHealthError struct { + CreationTimeUtc *string `json:"creationTimeUtc,omitempty"` + CustomerResolvability *HealthErrorCustomerResolvability `json:"customerResolvability,omitempty"` + EntityId *string `json:"entityId,omitempty"` + ErrorCategory *string `json:"errorCategory,omitempty"` + ErrorCode *string `json:"errorCode,omitempty"` + ErrorId *string `json:"errorId,omitempty"` + ErrorLevel *string `json:"errorLevel,omitempty"` + ErrorMessage *string `json:"errorMessage,omitempty"` + ErrorSource *string `json:"errorSource,omitempty"` + ErrorType *string `json:"errorType,omitempty"` + PossibleCauses *string `json:"possibleCauses,omitempty"` + RecommendedAction *string `json:"recommendedAction,omitempty"` + RecoveryProviderErrorMessage *string `json:"recoveryProviderErrorMessage,omitempty"` + SummaryMessage *string `json:"summaryMessage,omitempty"` +} + +func (o *InnerHealthError) GetCreationTimeUtcAsTime() (*time.Time, error) { + if o.CreationTimeUtc == nil { + return nil, nil + } + return dates.ParseAsFormat(o.CreationTimeUtc, "2006-01-02T15:04:05Z07:00") +} + +func (o *InnerHealthError) SetCreationTimeUtcAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.CreationTimeUtc = &formatted +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2022-10-01/replicationprotectableitems/model_osdetails.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2022-10-01/replicationprotectableitems/model_osdetails.go new file mode 100644 index 000000000000..7b38e793990d --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2022-10-01/replicationprotectableitems/model_osdetails.go @@ -0,0 +1,13 @@ +package replicationprotectableitems + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type OSDetails struct { + OSMajorVersion *string `json:"oSMajorVersion,omitempty"` + OSMinorVersion *string `json:"oSMinorVersion,omitempty"` + OSVersion *string `json:"oSVersion,omitempty"` + OsEdition *string `json:"osEdition,omitempty"` + OsType *string `json:"osType,omitempty"` + ProductType *string `json:"productType,omitempty"` +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2022-10-01/replicationprotectableitems/model_protectableitem.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2022-10-01/replicationprotectableitems/model_protectableitem.go new file mode 100644 index 000000000000..f2996c6b5147 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2022-10-01/replicationprotectableitems/model_protectableitem.go @@ -0,0 +1,12 @@ +package replicationprotectableitems + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ProtectableItem struct { + Id *string `json:"id,omitempty"` + Location *string `json:"location,omitempty"` + Name *string `json:"name,omitempty"` + Properties *ProtectableItemProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2022-10-01/replicationprotectableitems/model_protectableitemproperties.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2022-10-01/replicationprotectableitems/model_protectableitemproperties.go new file mode 100644 index 000000000000..5559fc9f13c4 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2022-10-01/replicationprotectableitems/model_protectableitemproperties.go @@ -0,0 +1,50 @@ +package replicationprotectableitems + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ProtectableItemProperties struct { + CustomDetails ConfigurationSettings `json:"customDetails"` + FriendlyName *string `json:"friendlyName,omitempty"` + ProtectionReadinessErrors *[]string `json:"protectionReadinessErrors,omitempty"` + ProtectionStatus *string `json:"protectionStatus,omitempty"` + RecoveryServicesProviderId *string `json:"recoveryServicesProviderId,omitempty"` + ReplicationProtectedItemId *string `json:"replicationProtectedItemId,omitempty"` + SupportedReplicationProviders *[]string `json:"supportedReplicationProviders,omitempty"` +} + +var _ json.Unmarshaler = &ProtectableItemProperties{} + +func (s *ProtectableItemProperties) UnmarshalJSON(bytes []byte) error { + type alias ProtectableItemProperties + var decoded alias + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling into ProtectableItemProperties: %+v", err) + } + + s.FriendlyName = decoded.FriendlyName + s.ProtectionReadinessErrors = decoded.ProtectionReadinessErrors + s.ProtectionStatus = decoded.ProtectionStatus + s.RecoveryServicesProviderId = decoded.RecoveryServicesProviderId + s.ReplicationProtectedItemId = decoded.ReplicationProtectedItemId + s.SupportedReplicationProviders = decoded.SupportedReplicationProviders + + var temp map[string]json.RawMessage + if err := json.Unmarshal(bytes, &temp); err != nil { + return fmt.Errorf("unmarshaling ProtectableItemProperties into map[string]json.RawMessage: %+v", err) + } + + if v, ok := temp["customDetails"]; ok { + impl, err := unmarshalConfigurationSettingsImplementation(v) + if err != nil { + return fmt.Errorf("unmarshaling field 'CustomDetails' for 'ProtectableItemProperties': %+v", err) + } + s.CustomDetails = impl + } + return nil +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2022-10-01/replicationprotectableitems/model_replicationgroupdetails.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2022-10-01/replicationprotectableitems/model_replicationgroupdetails.go new file mode 100644 index 000000000000..2afdac69d0e6 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2022-10-01/replicationprotectableitems/model_replicationgroupdetails.go @@ -0,0 +1,40 @@ +package replicationprotectableitems + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ ConfigurationSettings = ReplicationGroupDetails{} + +type ReplicationGroupDetails struct { + + // Fields inherited from ConfigurationSettings +} + +var _ json.Marshaler = ReplicationGroupDetails{} + +func (s ReplicationGroupDetails) MarshalJSON() ([]byte, error) { + type wrapper ReplicationGroupDetails + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling ReplicationGroupDetails: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling ReplicationGroupDetails: %+v", err) + } + decoded["instanceType"] = "ReplicationGroupDetails" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling ReplicationGroupDetails: %+v", err) + } + + return encoded, nil +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2022-10-01/replicationprotectableitems/model_vmmvirtualmachinedetails.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2022-10-01/replicationprotectableitems/model_vmmvirtualmachinedetails.go new file mode 100644 index 000000000000..1ae50cf4cc7d --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2022-10-01/replicationprotectableitems/model_vmmvirtualmachinedetails.go @@ -0,0 +1,48 @@ +package replicationprotectableitems + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ ConfigurationSettings = VMmVirtualMachineDetails{} + +type VMmVirtualMachineDetails struct { + + // Fields inherited from HyperVVirtualMachineDetails + DiskDetails *[]DiskDetails `json:"diskDetails,omitempty"` + Generation *string `json:"generation,omitempty"` + HasFibreChannelAdapter *PresenceStatus `json:"hasFibreChannelAdapter,omitempty"` + HasPhysicalDisk *PresenceStatus `json:"hasPhysicalDisk,omitempty"` + HasSharedVhd *PresenceStatus `json:"hasSharedVhd,omitempty"` + HyperVHostId *string `json:"hyperVHostId,omitempty"` + OsDetails *OSDetails `json:"osDetails,omitempty"` + SourceItemId *string `json:"sourceItemId,omitempty"` +} + +var _ json.Marshaler = VMmVirtualMachineDetails{} + +func (s VMmVirtualMachineDetails) MarshalJSON() ([]byte, error) { + type wrapper VMmVirtualMachineDetails + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling VMmVirtualMachineDetails: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling VMmVirtualMachineDetails: %+v", err) + } + decoded["instanceType"] = "VmmVirtualMachine" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling VMmVirtualMachineDetails: %+v", err) + } + + return encoded, nil +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2022-10-01/replicationprotectableitems/model_vmwarevirtualmachinedetails.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2022-10-01/replicationprotectableitems/model_vmwarevirtualmachinedetails.go new file mode 100644 index 000000000000..8eb8ecdf063f --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2022-10-01/replicationprotectableitems/model_vmwarevirtualmachinedetails.go @@ -0,0 +1,50 @@ +package replicationprotectableitems + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ ConfigurationSettings = VMwareVirtualMachineDetails{} + +type VMwareVirtualMachineDetails struct { + AgentGeneratedId *string `json:"agentGeneratedId,omitempty"` + AgentInstalled *string `json:"agentInstalled,omitempty"` + AgentVersion *string `json:"agentVersion,omitempty"` + DiscoveryType *string `json:"discoveryType,omitempty"` + DiskDetails *[]InMageDiskDetails `json:"diskDetails,omitempty"` + IPAddress *string `json:"ipAddress,omitempty"` + OsType *string `json:"osType,omitempty"` + PoweredOn *string `json:"poweredOn,omitempty"` + VCenterInfrastructureId *string `json:"vCenterInfrastructureId,omitempty"` + ValidationErrors *[]HealthError `json:"validationErrors,omitempty"` + + // Fields inherited from ConfigurationSettings +} + +var _ json.Marshaler = VMwareVirtualMachineDetails{} + +func (s VMwareVirtualMachineDetails) MarshalJSON() ([]byte, error) { + type wrapper VMwareVirtualMachineDetails + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling VMwareVirtualMachineDetails: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling VMwareVirtualMachineDetails: %+v", err) + } + decoded["instanceType"] = "VMwareVirtualMachine" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling VMwareVirtualMachineDetails: %+v", err) + } + + return encoded, nil +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2022-10-01/replicationprotectableitems/predicates.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2022-10-01/replicationprotectableitems/predicates.go new file mode 100644 index 000000000000..06bc4485e632 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2022-10-01/replicationprotectableitems/predicates.go @@ -0,0 +1,32 @@ +package replicationprotectableitems + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ProtectableItemOperationPredicate struct { + Id *string + Location *string + Name *string + Type *string +} + +func (p ProtectableItemOperationPredicate) Matches(input ProtectableItem) bool { + + if p.Id != nil && (input.Id == nil && *p.Id != *input.Id) { + return false + } + + if p.Location != nil && (input.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/recoveryservicessiterecovery/2022-10-01/replicationprotectableitems/version.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2022-10-01/replicationprotectableitems/version.go new file mode 100644 index 000000000000..80b6d6b46927 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2022-10-01/replicationprotectableitems/version.go @@ -0,0 +1,12 @@ +package replicationprotectableitems + +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-10-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/replicationprotectableitems/%s", defaultApiVersion) +} diff --git a/vendor/modules.txt b/vendor/modules.txt index 913f48e6ca00..d04292dab87c 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -451,6 +451,8 @@ github.com/hashicorp/go-azure-sdk/resource-manager/media/2022-08-01/liveevents github.com/hashicorp/go-azure-sdk/resource-manager/media/2022-08-01/liveoutputs github.com/hashicorp/go-azure-sdk/resource-manager/media/2022-08-01/streamingendpoints github.com/hashicorp/go-azure-sdk/resource-manager/media/2022-08-01/streamingpoliciesandstreaminglocators +github.com/hashicorp/go-azure-sdk/resource-manager/migrate/2020-01-01/machines +github.com/hashicorp/go-azure-sdk/resource-manager/migrate/2020-01-01/runasaccounts github.com/hashicorp/go-azure-sdk/resource-manager/mixedreality/2021-01-01/resource github.com/hashicorp/go-azure-sdk/resource-manager/mobilenetwork/2022-11-01/datanetwork github.com/hashicorp/go-azure-sdk/resource-manager/mobilenetwork/2022-11-01/mobilenetwork @@ -563,6 +565,7 @@ github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/ github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2022-10-01/replicationnetworkmappings github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2022-10-01/replicationnetworks github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2022-10-01/replicationpolicies +github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2022-10-01/replicationprotectableitems github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2022-10-01/replicationprotecteditems github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2022-10-01/replicationprotectioncontainermappings github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2022-10-01/replicationprotectioncontainers diff --git a/website/docs/r/site_recovery_vmware_replicated_vm.html.markdown b/website/docs/r/site_recovery_vmware_replicated_vm.html.markdown new file mode 100644 index 000000000000..f4809129a641 --- /dev/null +++ b/website/docs/r/site_recovery_vmware_replicated_vm.html.markdown @@ -0,0 +1,217 @@ +--- +subcategory: "Recovery Services" +layout: "azurerm" +page_title: "Azure Resource Manager: azurerm_site_recovery_vmware_replicated_vm" +description: |- + Manages a VMWare VM protected with Azure Site Recovery on Azure. +--- + +# azurerm_site_recovery_vmware_replicated_vm + +Manages a VMWare VM replicated using Azure Site Recovery (VMWare to Azure only). A replicated VM keeps a copiously updated image of the VM in Azure in order to be able to start the VM in Azure in case of a disaster. + +## Example Usage + +```hcl +resource "azurerm_resource_group" "example" { + name = "example-rg" + location = "West US" +} + +resource "azurerm_recovery_services_vault" "example" { + name = "example-recovery-vault" + location = azurerm_resource_group.example.location + resource_group_name = azurerm_resource_group.example.name + sku = "Standard" +} + +resource "azurerm_site_recovery_vmware_replication_policy" "example" { + recovery_vault_id = azurerm_recovery_services_vault.example.id + name = "example-policy" + recovery_point_retention_in_minutes = 1440 + application_consistent_snapshot_frequency_in_minutes = 240 +} + +resource "azurerm_site_recovery_vmware_replication_policy_association" "test" { + name = "example-association" + recovery_vault_id = azurerm_recovery_services_vault.example.id + policy_id = azurerm_site_recovery_hyperv_replication_policy.example.id +} + +resource "azurerm_storage_account" "example" { + name = "examplestorageacc" + resource_group_name = azurerm_resource_group.example.name + location = azurerm_resource_group.example.location + account_tier = "Standard" + account_kind = "StorageV2" + account_replication_type = "LRS" +} + +resource "azurerm_virtual_network" "example" { + name = "example-net" + resource_group_name = azurerm_resource_group.example.name + address_space = ["192.168.2.0/24"] + location = azurerm_resource_group.example.location +} + +resource "azurerm_subnet" "example" { + name = "example-subnet" + resource_group_name = azurerm_resource_group.example.name + virtual_network_name = azurerm_virtual_network.example.name + address_prefixes = ["192.168.2.0/24"] +} + +resource "azurerm_storage_account" "example" { + name = "examplesa" + resource_group_name = azurerm_resource_group.example.name + location = azurerm_resource_group.example.location + account_tier = "Standard" + account_replication_type = "LRS" +} + +resource "azurerm_site_recovery_vmware_replicated_vm" "example" { + name = "example-vmware-vm" + recovery_vault_id = azurerm_recovery_services_vault.example.id + source_vm_name = "example-vm" + appliance_name = "example-appliance" + recovery_replication_policy_id = azurerm_site_recovery_hyperv_replication_policy.example.id + credential_type = "lincreds" + license_type = "NotSpecified" + target_boot_diagnostics_storage_account_id = azurerm_storage_account.example.id + target_vm_name = "example_replicated_vm" + target_resource_group_id = azurerm_resource_group.example.id + default_log_storage_account_id = azurerm_storage_account.example.id + default_recovery_disk_type = "Standard_LRS" + target_network_id = azurerm_virtual_network.example.id + + network_interface { + target_subnet_name = azurerm_subnet.example.name + is_primary = true + } + + depends_on = [azurerm_site_recovery_vmware_replication_policy_association.example] +} +``` + +## Argument Reference + +The following arguments are supported: + +* `name` - (Required) The name of the replicated VM. Changing this forces a new resource to be created. + +* `recovery_vault_id` - (Required) The ID of the Recovery Services Vault where the replicated VM is created. Changing this forces a new resource to be created. + +* `source_vm_name` - (Required) The name of the source VM in VMWare. Changing this forces a new resource to be created. + +* `appliance_name` - (Required) The name of VMWare appliance which handles the replication. Changing this forces a new resource to be created. + +* `recovery_replication_policy_id` - (Required) The ID of the policy to use for this replicated VM. Changing this forces a new resource to be created. + +* `credential_type` - (Optional) The credentials to access source VM. Possible values are `lincreds`, `v2arcmlab` and `wincreds`. Changing this forces a new resource to be created. + +**Note:** `credential_type` is required in creation. + +* `license_type` - (Optional) The license type of the VM. Possible values are `NoLicenseType`, `NotSpecified` and `WindowsServer`. Defaults to `NotSpecified`. + +* `target_resource_group_id` - (Required) The ID of resource group where the VM should be created when a failover is done. Changing this forces a new resource to be created. + +* `target_vm_name` - (Required) Name of the VM that should be created when a failover is done. Changing this forces a new resource to be created. + +* `default_log_storage_account_id` - (Optional) The ID of the stroage account that should be used for logging during replication. Changing this forces a new resource to be created. + +**Note:** Only standard types of stroage accounts are allowed. + +**Note:** At least one of `default_log_storage_account_id` and `managed_disk` must be specified. + +**Note:** Changing `default_log_storage_account_id` forces a new resource to be created. But removing it does not. + +* `default_recovery_disk_type` - (Optional) The type of storage account that should be used for recovery disks when a failover is done. Possible values are `Standard_LRS`, `Standard_LRS` and `StandardSSD_LRS`. + +**Note:** At least one of `default_recovery_disk_type` and `managed_disk` must be specified. + +**Note:** Changing `default_recovery_disk_type` forces a new resource to be created. But removing it does not. + +* `target_network_id` - (Optional) The ID of network to use when a failover is done. + +* `target_subnet_name` - (Optional) Name of the subnet to use when a failover is done. + +* `test_network_id` - (Optional) The ID of network to use when a test failover is done. + +* `test_subnet_name` - (Optional) Name of the subnet to use when a failover is done. + +* `multi_vm_group_name` - (Optional) Name of group in which all machines will replicate together and have shared crash consistent and app-consistent recovery points when failed over. Changing this forces a new resource to be created. + +* `target_proximity_placement_group_id` - (Optional) The ID of Proximity Placement Group the new VM should belong to when a failover is done. + +* `target_availability_set_id` - (Optional) The ID of availability set that the new VM should belong to when a failover is done. Changing this forces a new resource to be created. + +**Note:** Only one of `target_availability_set_id` or `target_zone` can be specified. + +* `target_vm_size` - (Optional) Size of the VM that should be created when a failover is done, such as `Standard_F2`. If it's not specified, it will automatically be set by detecting the source VM size. + +* `target_zone` - (Optional) Specifies the Availability Zone where the Failover VM should exist. + +* `default_target_disk_encryption_set_id` - (Optional) The ID of the default Disk Encryption Set that should be used for the disks when a failover is done. Changing this forces a new resource to be created. + +**Note:** Only one `default_target_disk_encryption_set_id` or `managed_disk` can be specified. + +**Note:** Changing `default_target_disk_encryption_set_id` forces a new resource to be created. But removing it does not. + +* `target_boot_diagnostics_storage_account_id` - (Optional) The ID of the storage account that should be used for boot diagnostics when a failover is done. + +* `managed_disk` - (Optional) One or more `managed_disk` block as defined below. It's avaiable only if mobility service is already installed on the source VM. + +**Note:** a replicated VM could be created without `managed_disk` block, once it has been specified, changing it forces a new resource to be created. + +* `network_interface` - (Required) One or more `network_interface` block as defined below. + +--- + +A `managed_disk` block supports the following: + +* `disk_id` - (Required) The ID of the disk to be replicated. Changing this forces a new resource to be created. + +* `target_disk_type` - (Required) The disk type of the disk to be created when a failover is done. Possible values are `Standard_LRS`, `Standard_LRS` and `StandardSSD_LRS`. + +* `log_storage_account_id` - (Required) The ID of the storage account that should be used for logging during replication. + +* `target_disk_encryption_set_id` - (Optional) The ID of the Disk Encryption Set that should be used for the disks when a failover is done. + +--- + +A `network_interface` block supports the following: + +* `source_mac_address` - (Optional) Mac address of the network interface of source VM. + +-> **NOTE:** `source_mac_address` could be left blank in creation only if there is exactly one network interface on the source VM. + +* `target_static_ip` - (Optional) Static IP to assign when a failover is done. + +* `target_subnet_name` - (Optional) Name of the subnet to use when a failover is done. + +* `test_subnet_name` - (Optional) Name of the subnet to use when a test failover is done. + +* `is_primary` - (Required) Whether this `network_interface` is primary for the replicated VM. + +## Attributes Reference + +In addition to the arguments above, the following attributes are exported: + +* `id` - The ID of the Site Recovery Replicated VM. + +## Timeouts + +The `timeouts` block allows you to specify [timeouts](https://www.terraform.io/language/resources/syntax#operation-timeouts) for certain actions: + +* `create` - (Defaults to 5 hours) Used when creating the Site Recovery HyperV Replicated VM. +* `update` - (Defaults to 90 minutes) Used when updating the Site Recovery HyperV Replicated VM. +* `read` - (Defaults to 5 minutes) Used when retrieving the Site Recovery HyperV Replicated VM. +* `delete` - (Defaults to 90 minutes) Used when deleting the Site Recovery HyperV Replicated VM. + +## Import + +Site Recovery VMWare Replicated VM's can be imported using the `resource id`, e.g. + +```shell +terraform import azurerm_site_recovery_vmware_replicated_vm.vmreplication /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resource-group-name/providers/Microsoft.RecoveryServices/vaults/recovery-vault-name/replicationFabrics/fabric-name/replicationProtectionContainers/protection-container-name/replicationProtectedItems/vm-replication-name +``` From 9de39a4ce6407c0fd4cd1ee8fa7ce6ba966d01cc Mon Sep 17 00:00:00 2001 From: ziyeqf <51212351+ziyeqf@users.noreply.github.com> Date: Mon, 10 Jul 2023 17:51:43 +0800 Subject: [PATCH 02/15] update test case Signed-off-by: ziyeqf <51212351+ziyeqf@users.noreply.github.com> --- .../site_recovery_vmware_replicated_vm_resource_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/services/recoveryservices/site_recovery_vmware_replicated_vm_resource_test.go b/internal/services/recoveryservices/site_recovery_vmware_replicated_vm_resource_test.go index 87566f69f55b..64890c38f0ee 100644 --- a/internal/services/recoveryservices/site_recovery_vmware_replicated_vm_resource_test.go +++ b/internal/services/recoveryservices/site_recovery_vmware_replicated_vm_resource_test.go @@ -113,7 +113,7 @@ resource "azurerm_site_recovery_vmware_replicated_vm" "test" { recovery_vault_id = "%[1]s" source_vm_name = "%[5]s" appliance_name = "%[6]s" - recovery_replication_policy_id = azurerm_site_recovery_vmware_replication_policy.test.id + recovery_replication_policy_id = azurerm_site_recovery_vmware_replication_policy_association.test.policy_id credential_type = "lincreds" license_type = "NotSpecified" target_boot_diagnostics_storage_account_id = azurerm_storage_account.target.id From b5314561ea279473ed1f9b0f110f790f3597218c Mon Sep 17 00:00:00 2001 From: ziyeqf <51212351+ziyeqf@users.noreply.github.com> Date: Tue, 11 Jul 2023 13:13:05 +0800 Subject: [PATCH 03/15] update `physical_server_credential_name` Signed-off-by: ziyeqf <51212351+ziyeqf@users.noreply.github.com> --- ..._recovery_vmware_replicated_vm_resource.go | 75 ++++++++++++------- ...very_vmware_replicated_vm_resource_test.go | 14 ++-- ...ecovery_vmware_replicated_vm.html.markdown | 21 +++--- 3 files changed, 66 insertions(+), 44 deletions(-) diff --git a/internal/services/recoveryservices/site_recovery_vmware_replicated_vm_resource.go b/internal/services/recoveryservices/site_recovery_vmware_replicated_vm_resource.go index 0d474785f24c..61156579494f 100644 --- a/internal/services/recoveryservices/site_recovery_vmware_replicated_vm_resource.go +++ b/internal/services/recoveryservices/site_recovery_vmware_replicated_vm_resource.go @@ -36,12 +36,6 @@ import ( "github.com/hashicorp/terraform-provider-azurerm/utils" ) -type installAccountType string - -const lincreds installAccountType = "lincreds" -const v2arcmlab installAccountType = "v2arcmlab" -const wincreds installAccountType = "wincreds" - type IncludedDiskModel struct { DiskId string `tfschema:"disk_id"` LogStorageAccountId string `tfschema:"log_storage_account_id"` @@ -63,6 +57,7 @@ type SiteRecoveryReplicatedVmVMwareModel struct { SourceVmName string `tfschema:"source_vm_name"` ApplianceName string `tfschema:"appliance_name"` RecoveryReplicationPolicyId string `tfschema:"recovery_replication_policy_id"` + PhysicalServerCredentialName string `tfschema:"physical_server_credential_name"` LicenseType string `tfschema:"license_type"` TargetResourceGroupId string `tfschema:"target_resource_group_id"` TargetVmName string `tfschema:"target_vm_name"` @@ -76,7 +71,6 @@ type SiteRecoveryReplicatedVmVMwareModel struct { TargetBootDiagnosticsStorageAccountId string `tfschema:"target_boot_diagnostics_storage_account_id"` DiskToInclude []IncludedDiskModel `tfschema:"managed_disk"` NetworkInterface []NetworkInterfaceModel `tfschema:"network_interface"` - CredentialType string `tfschema:"credential_type"` DefaultLogStorageAccountId string `tfschema:"default_log_storage_account_id"` DefaultRecoveryDiskType string `tfschema:"default_recovery_disk_type"` DefaultTargetDiskEncryptionSetId string `tfschema:"default_target_disk_encryption_set_id"` @@ -137,14 +131,11 @@ func (s VMWareReplicatedVmResource) Arguments() map[string]*pluginsdk.Schema { DiffSuppressFunc: suppress.CaseDifference, }, - "credential_type": { - Type: pluginsdk.TypeString, - Optional: true, - ValidateFunc: validation.StringInSlice([]string{ - string(lincreds), - string(v2arcmlab), - string(wincreds), - }, false), + "physical_server_credential_name": { + Type: pluginsdk.TypeString, + Required: true, + ForceNew: true, + ValidateFunc: validation.StringIsNotEmpty, }, "license_type": { @@ -382,8 +373,7 @@ func (k VMWareReplicatedVmResource) CustomizeDiff() sdk.ResourceFunc { func (s VMWareReplicatedVmResource) Create() sdk.ResourceFunc { return sdk.ResourceFunc{ - // waiting for fully protected cost very long time. - Timeout: 300 * time.Minute, + Timeout: 120 * time.Minute, Func: func(ctx context.Context, metadata sdk.ResourceMetaData) error { client := metadata.Client.RecoveryServices.ReplicationProtectedItemsClient fabricClient := metadata.Client.RecoveryServices.FabricClient @@ -397,10 +387,6 @@ func (s VMWareReplicatedVmResource) Create() sdk.ResourceFunc { return fmt.Errorf("decoding %+v", err) } - if model.CredentialType == "" { - return fmt.Errorf("`credential_type` must be specified in creation") - } - vaultId, err := replicationprotecteditems.ParseVaultID(model.RecoveryVaultId) if err != nil { return fmt.Errorf("parsing vault id %q: %+v", model.RecoveryVaultId, err) @@ -434,9 +420,9 @@ func (s VMWareReplicatedVmResource) Create() sdk.ResourceFunc { return fmt.Errorf("fetch discovery machine id %s: %+v", model.SourceVmName, err) } - runAsAccountId, err := fetchRunAsAccountsIdBySite(ctx, runAsAccountsClient, siteID, model.CredentialType, model.ApplianceName) + runAsAccountId, err := fetchRunAsAccountsIdBySite(ctx, runAsAccountsClient, siteID, model.PhysicalServerCredentialName, model.ApplianceName) if err != nil { - return fmt.Errorf("fetch run as account id %s: %+v", model.CredentialType, err) + return fmt.Errorf("fetch run as account id %s: %+v", model.PhysicalServerCredentialName, err) } existing, err := client.Get(ctx, id) @@ -578,6 +564,7 @@ func (s VMWareReplicatedVmResource) Read() sdk.ResourceFunc { } client := metadata.Client.RecoveryServices.ReplicationProtectedItemsClient + runAsAccountId := metadata.Client.RecoveryServices.VMWareRunAsAccountsClient resp, err := client.Get(ctx, *id) if err != nil { @@ -634,6 +621,15 @@ func (s VMWareReplicatedVmResource) Read() sdk.ResourceFunc { state.TargetBootDiagnosticsStorageAccountId = pointer.From(inMageRcm.TargetBootDiagnosticsStorageAccountId) + credential := "" + if inMageRcm.RunAsAccountId != nil && *inMageRcm.RunAsAccountId != "" { + credential, err = fetchCredentialByRunAsAccountId(ctx, runAsAccountId, *inMageRcm.RunAsAccountId) + if err != nil { + return fmt.Errorf("retireving credential by run as account id %q: %+v", *inMageRcm.RunAsAccountId, err) + } + } + state.PhysicalServerCredentialName = credential + if inMageRcm.ProtectedDisks != nil { diskOutputs := make([]IncludedDiskModel, 0) for _, diskRaw := range *inMageRcm.ProtectedDisks { @@ -1011,13 +1007,14 @@ func fetchSiteRecoveryReplicatedVmVMWareContainerId(ctx context.Context, contain return parsedID.ID(), nil } -func fetchRunAsAccountsIdBySite(ctx context.Context, runAsAccountClient *vmwarerunasaccounts.RunAsAccountsClient, siteId string, accountType string, applianceName string) (string, error) { +func fetchRunAsAccountsIdBySite(ctx context.Context, runAsAccountClient *vmwarerunasaccounts.RunAsAccountsClient, siteId string, displayName string, applianceName string) (string, error) { parsedSiteId, err := vmwarerunasaccounts.ParseVMwareSiteIDInsensitively(siteId) if err != nil { return "", fmt.Errorf("parse %s: %+v", siteId, err) } hackedClinet := azuresdkhacks.RunAsAccountsClient{Client: runAsAccountClient.Client} + // GET on Site is not working, tracked on https://github.com/Azure/azure-rest-api-specs/issues/24711 resp, err := hackedClinet.GetAllRunAsAccountsInSiteComplete(ctx, *parsedSiteId) if err != nil { return "", err @@ -1037,12 +1034,12 @@ func fetchRunAsAccountsIdBySite(ctx context.Context, runAsAccountClient *vmwarer if account.Properties.ApplianceName == nil { continue } - if strings.EqualFold(*account.Properties.DisplayName, accountType) && strings.EqualFold(*account.Properties.ApplianceName, applianceName) { + if strings.EqualFold(*account.Properties.DisplayName, displayName) && strings.EqualFold(*account.Properties.ApplianceName, applianceName) { return *account.Id, nil } } - return "", fmt.Errorf("retiring %q: run as account %s not found", siteId, accountType) + return "", fmt.Errorf("retiring %q: run as account %s not found", siteId, displayName) } func fetchProcessServerIdByName(ctx context.Context, fabricClient *replicationfabrics.ReplicationFabricsClient, fabricId replicationfabrics.ReplicationFabricId, processServerName string) (string, error) { @@ -1105,6 +1102,32 @@ func fetchDiscoveryMachineIdBySite(ctx context.Context, machinesClient *vmwarema return "", fmt.Errorf("retiring %q: machine %s not found", siteId, machineName) } +func fetchCredentialByRunAsAccountId(ctx context.Context, client *vmwarerunasaccounts.RunAsAccountsClient, id string) (string, error) { + parsedRunAsAccountId, err := commonids.ParseVMwareSiteRunAsAccountIDInsensitively(id) + if err != nil { + return "", fmt.Errorf("parse %s: %+v", id, err) + } + + resp, err := client.GetRunAsAccount(ctx, *parsedRunAsAccountId) + if err != nil { + return "", err + } + + if resp.Model == nil { + return "", fmt.Errorf("retiring %q: Model was nil", id) + } + + if resp.Model.Properties == nil { + return "", fmt.Errorf("retiring %q: Properties was nil", id) + } + + if resp.Model.Properties.DisplayName == nil { + return "", fmt.Errorf("retiring %q: DisplayName was nil", id) + } + + return *resp.Model.Properties.DisplayName, nil +} + // workaround for https://github.com/hashicorp/go-azure-sdk/issues/492 func getAllVMWareMachinesInSite(ctx context.Context, c *vmwaremachines.MachinesClient, id vmwaremachines.VMwareSiteId, options vmwaremachines.GetAllMachinesInSiteOperationOptions) (result vmwaremachines.GetAllMachinesInSiteOperationResponse, err error) { opts := client.RequestOptions{ diff --git a/internal/services/recoveryservices/site_recovery_vmware_replicated_vm_resource_test.go b/internal/services/recoveryservices/site_recovery_vmware_replicated_vm_resource_test.go index 64890c38f0ee..f202f89a4b25 100644 --- a/internal/services/recoveryservices/site_recovery_vmware_replicated_vm_resource_test.go +++ b/internal/services/recoveryservices/site_recovery_vmware_replicated_vm_resource_test.go @@ -38,9 +38,10 @@ func TestAccSiteVMWareRecoveryReplicatedVM_basic(t *testing.T) { sourceVMName := os.Getenv("ARM_TEST_VMWARE_SOURCE_VM_NAME") applianceName := os.Getenv("ARM_TEST_VMWARE_APPLIANCE_NAME") location := os.Getenv("ARM_TEST_VMWARE_VAULT_LOCATION") + credential := os.Getenv("ARM_TEST_VMWARE_CREDENTIAL_NAME") - if vaultId == "" || sourceVMName == "" || applianceName == "" || location == "" { - t.Skip("Skipping since ARM_TEST_VMWARE_VAULT_ID, ARM_TEST_VMWARE_SOURCE_VM_NAME, ARM_TEST_VMWARE_LOCATION and ARM_TEST_VMWARE_APPLIANCE_NAME are not specified") + if vaultId == "" || sourceVMName == "" || applianceName == "" || location == "" || credential == "" { + t.Skip("Skipping since ARM_TEST_VMWARE_VAULT_ID, ARM_TEST_VMWARE_SOURCE_VM_NAME, ARM_TEST_VMWARE_LOCATION, ARM_TEST_VMWARE_CREDENTIAL_NAME and ARM_TEST_VMWARE_APPLIANCE_NAME are not specified") return } @@ -48,7 +49,7 @@ func TestAccSiteVMWareRecoveryReplicatedVM_basic(t *testing.T) { data.ResourceTest(t, r, []acceptance.TestStep{ { - Config: r.basic(data, vaultId, sourceVMName, applianceName), + Config: r.basic(data, vaultId, sourceVMName, applianceName, credential), Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), ), @@ -57,7 +58,7 @@ func TestAccSiteVMWareRecoveryReplicatedVM_basic(t *testing.T) { }) } -func (SiteRecoveryVMWareReplicatedVmResource) basic(data acceptance.TestData, vaultId, sourceVMName, applianceName string) string { +func (SiteRecoveryVMWareReplicatedVmResource) basic(data acceptance.TestData, vaultId, sourceVMName, applianceName, credential string) string { return fmt.Sprintf(` provider "azurerm" { features { @@ -114,7 +115,7 @@ resource "azurerm_site_recovery_vmware_replicated_vm" "test" { source_vm_name = "%[5]s" appliance_name = "%[6]s" recovery_replication_policy_id = azurerm_site_recovery_vmware_replication_policy_association.test.policy_id - credential_type = "lincreds" + physical_server_credential_name = "%[7]s" license_type = "NotSpecified" target_boot_diagnostics_storage_account_id = azurerm_storage_account.target.id target_vm_name = "%[5]s" @@ -135,7 +136,6 @@ resource "azurerm_site_recovery_vmware_replicated_vm" "test" { lifecycle { ignore_changes = [ target_vm_size, - credential_type, default_log_storage_account_id, default_recovery_disk_type, managed_disk, @@ -143,5 +143,5 @@ resource "azurerm_site_recovery_vmware_replicated_vm" "test" { ] } } -`, vaultId, data.RandomInteger, data.RandomString, data.Locations.Primary, sourceVMName, applianceName) +`, vaultId, data.RandomInteger, data.RandomString, data.Locations.Primary, sourceVMName, applianceName, credential) } diff --git a/website/docs/r/site_recovery_vmware_replicated_vm.html.markdown b/website/docs/r/site_recovery_vmware_replicated_vm.html.markdown index f4809129a641..1d19995aa269 100644 --- a/website/docs/r/site_recovery_vmware_replicated_vm.html.markdown +++ b/website/docs/r/site_recovery_vmware_replicated_vm.html.markdown @@ -74,8 +74,8 @@ resource "azurerm_site_recovery_vmware_replicated_vm" "example" { recovery_vault_id = azurerm_recovery_services_vault.example.id source_vm_name = "example-vm" appliance_name = "example-appliance" - recovery_replication_policy_id = azurerm_site_recovery_hyperv_replication_policy.example.id - credential_type = "lincreds" + recovery_replication_policy_id = azurerm_site_recovery_vmware_replication_policy_association.example.policy_id + physical_server_credential_name = "example-creds" license_type = "NotSpecified" target_boot_diagnostics_storage_account_id = azurerm_storage_account.example.id target_vm_name = "example_replicated_vm" @@ -85,6 +85,7 @@ resource "azurerm_site_recovery_vmware_replicated_vm" "example" { target_network_id = azurerm_virtual_network.example.id network_interface { + source_mac_address = "00:00:00:00:00:00" target_subnet_name = azurerm_subnet.example.name is_primary = true } @@ -107,9 +108,7 @@ The following arguments are supported: * `recovery_replication_policy_id` - (Required) The ID of the policy to use for this replicated VM. Changing this forces a new resource to be created. -* `credential_type` - (Optional) The credentials to access source VM. Possible values are `lincreds`, `v2arcmlab` and `wincreds`. Changing this forces a new resource to be created. - -**Note:** `credential_type` is required in creation. +* `physical_server_credential_name` - (Required) The name of credential to access source VM. Changing this forces a new resource to be created. More information about the credentials could be found [here](https://learn.microsoft.com/en-us/azure/site-recovery/deploy-vmware-azure-replication-appliance-modernized). * `license_type` - (Optional) The license type of the VM. Possible values are `NoLicenseType`, `NotSpecified` and `WindowsServer`. Defaults to `NotSpecified`. @@ -117,17 +116,17 @@ The following arguments are supported: * `target_vm_name` - (Required) Name of the VM that should be created when a failover is done. Changing this forces a new resource to be created. -* `default_log_storage_account_id` - (Optional) The ID of the stroage account that should be used for logging during replication. Changing this forces a new resource to be created. +* `default_log_storage_account_id` - (Optional) The ID of the stroage account that should be used for logging during replication. **Note:** Only standard types of stroage accounts are allowed. -**Note:** At least one of `default_log_storage_account_id` and `managed_disk` must be specified. +**Note:** At least one of `default_log_storage_account_id` or `managed_disk` must be specified. **Note:** Changing `default_log_storage_account_id` forces a new resource to be created. But removing it does not. * `default_recovery_disk_type` - (Optional) The type of storage account that should be used for recovery disks when a failover is done. Possible values are `Standard_LRS`, `Standard_LRS` and `StandardSSD_LRS`. -**Note:** At least one of `default_recovery_disk_type` and `managed_disk` must be specified. +**Note:** At least one of `default_recovery_disk_type` or `managed_disk` must be specified. **Note:** Changing `default_recovery_disk_type` forces a new resource to be created. But removing it does not. @@ -151,9 +150,9 @@ The following arguments are supported: * `target_zone` - (Optional) Specifies the Availability Zone where the Failover VM should exist. -* `default_target_disk_encryption_set_id` - (Optional) The ID of the default Disk Encryption Set that should be used for the disks when a failover is done. Changing this forces a new resource to be created. +* `default_target_disk_encryption_set_id` - (Optional) The ID of the default Disk Encryption Set that should be used for the disks when a failover is done. -**Note:** Only one `default_target_disk_encryption_set_id` or `managed_disk` can be specified. +**Note:** Only one of `default_target_disk_encryption_set_id` or `managed_disk` can be specified. **Note:** Changing `default_target_disk_encryption_set_id` forces a new resource to be created. But removing it does not. @@ -203,7 +202,7 @@ In addition to the arguments above, the following attributes are exported: The `timeouts` block allows you to specify [timeouts](https://www.terraform.io/language/resources/syntax#operation-timeouts) for certain actions: -* `create` - (Defaults to 5 hours) Used when creating the Site Recovery HyperV Replicated VM. +* `create` - (Defaults to 2 hours) Used when creating the Site Recovery HyperV Replicated VM. * `update` - (Defaults to 90 minutes) Used when updating the Site Recovery HyperV Replicated VM. * `read` - (Defaults to 5 minutes) Used when retrieving the Site Recovery HyperV Replicated VM. * `delete` - (Defaults to 90 minutes) Used when deleting the Site Recovery HyperV Replicated VM. From 6574b3a8dfeed646bdc3042c7b01fd2cc90e9ff4 Mon Sep 17 00:00:00 2001 From: ziyeqf <51212351+ziyeqf@users.noreply.github.com> Date: Wed, 12 Jul 2023 12:58:07 +0800 Subject: [PATCH 04/15] refresh /vendor Signed-off-by: ziyeqf <51212351+ziyeqf@users.noreply.github.com> --- .../replicationprotectableitems/README.md | 53 ----- .../replicationprotectableitems/client.go | 18 -- .../replicationprotectableitems/constants.go | 65 ------ .../id_replicationprotectableitem.go | 166 ------------- .../id_replicationprotectioncontainer.go | 153 ------------ .../method_get_autorest.go | 68 ------ ...eplicationprotectioncontainers_autorest.go | 220 ------------------ .../model_configurationsettings.go | 64 ----- .../model_diskdetails.go | 11 - .../model_diskvolumedetails.go | 9 - .../model_healtherror.go | 40 ---- .../model_hypervvirtualmachinedetails.go | 48 ---- .../model_inmagediskdetails.go | 13 -- .../model_innerhealtherror.go | 39 ---- .../model_osdetails.go | 13 -- .../model_protectableitem.go | 12 - .../model_protectableitemproperties.go | 50 ---- .../model_replicationgroupdetails.go | 40 ---- .../model_vmmvirtualmachinedetails.go | 48 ---- .../model_vmwarevirtualmachinedetails.go | 50 ---- .../replicationprotectableitems/predicates.go | 32 --- .../replicationprotectableitems/version.go | 12 - vendor/modules.txt | 1 - 23 files changed, 1225 deletions(-) delete mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2022-10-01/replicationprotectableitems/README.md delete mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2022-10-01/replicationprotectableitems/client.go delete mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2022-10-01/replicationprotectableitems/constants.go delete mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2022-10-01/replicationprotectableitems/id_replicationprotectableitem.go delete mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2022-10-01/replicationprotectableitems/id_replicationprotectioncontainer.go delete mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2022-10-01/replicationprotectableitems/method_get_autorest.go delete mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2022-10-01/replicationprotectableitems/method_listbyreplicationprotectioncontainers_autorest.go delete mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2022-10-01/replicationprotectableitems/model_configurationsettings.go delete mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2022-10-01/replicationprotectableitems/model_diskdetails.go delete mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2022-10-01/replicationprotectableitems/model_diskvolumedetails.go delete mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2022-10-01/replicationprotectableitems/model_healtherror.go delete mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2022-10-01/replicationprotectableitems/model_hypervvirtualmachinedetails.go delete mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2022-10-01/replicationprotectableitems/model_inmagediskdetails.go delete mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2022-10-01/replicationprotectableitems/model_innerhealtherror.go delete mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2022-10-01/replicationprotectableitems/model_osdetails.go delete mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2022-10-01/replicationprotectableitems/model_protectableitem.go delete mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2022-10-01/replicationprotectableitems/model_protectableitemproperties.go delete mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2022-10-01/replicationprotectableitems/model_replicationgroupdetails.go delete mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2022-10-01/replicationprotectableitems/model_vmmvirtualmachinedetails.go delete mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2022-10-01/replicationprotectableitems/model_vmwarevirtualmachinedetails.go delete mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2022-10-01/replicationprotectableitems/predicates.go delete mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2022-10-01/replicationprotectableitems/version.go diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2022-10-01/replicationprotectableitems/README.md b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2022-10-01/replicationprotectableitems/README.md deleted file mode 100644 index cb5b55687b0b..000000000000 --- a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2022-10-01/replicationprotectableitems/README.md +++ /dev/null @@ -1,53 +0,0 @@ - -## `github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2022-10-01/replicationprotectableitems` Documentation - -The `replicationprotectableitems` SDK allows for interaction with the Azure Resource Manager Service `recoveryservicessiterecovery` (API Version `2022-10-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/recoveryservicessiterecovery/2022-10-01/replicationprotectableitems" -``` - - -### Client Initialization - -```go -client := replicationprotectableitems.NewReplicationProtectableItemsClientWithBaseURI("https://management.azure.com") -client.Client.Authorizer = authorizer -``` - - -### Example Usage: `ReplicationProtectableItemsClient.Get` - -```go -ctx := context.TODO() -id := replicationprotectableitems.NewReplicationProtectableItemID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue", "replicationFabricValue", "replicationProtectionContainerValue", "replicationProtectableItemValue") - -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: `ReplicationProtectableItemsClient.ListByReplicationProtectionContainers` - -```go -ctx := context.TODO() -id := replicationprotectableitems.NewReplicationProtectionContainerID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue", "replicationFabricValue", "replicationProtectionContainerValue") - -// alternatively `client.ListByReplicationProtectionContainers(ctx, id, replicationprotectableitems.DefaultListByReplicationProtectionContainersOperationOptions())` can be used to do batched pagination -items, err := client.ListByReplicationProtectionContainersComplete(ctx, id, replicationprotectableitems.DefaultListByReplicationProtectionContainersOperationOptions()) -if err != nil { - // handle the error -} -for _, item := range items { - // do something -} -``` diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2022-10-01/replicationprotectableitems/client.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2022-10-01/replicationprotectableitems/client.go deleted file mode 100644 index cd1356d41c0a..000000000000 --- a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2022-10-01/replicationprotectableitems/client.go +++ /dev/null @@ -1,18 +0,0 @@ -package replicationprotectableitems - -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 ReplicationProtectableItemsClient struct { - Client autorest.Client - baseUri string -} - -func NewReplicationProtectableItemsClientWithBaseURI(endpoint string) ReplicationProtectableItemsClient { - return ReplicationProtectableItemsClient{ - Client: autorest.NewClientWithUserAgent(userAgent()), - baseUri: endpoint, - } -} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2022-10-01/replicationprotectableitems/constants.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2022-10-01/replicationprotectableitems/constants.go deleted file mode 100644 index 7ae2eaa30c8b..000000000000 --- a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2022-10-01/replicationprotectableitems/constants.go +++ /dev/null @@ -1,65 +0,0 @@ -package replicationprotectableitems - -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 HealthErrorCustomerResolvability string - -const ( - HealthErrorCustomerResolvabilityAllowed HealthErrorCustomerResolvability = "Allowed" - HealthErrorCustomerResolvabilityNotAllowed HealthErrorCustomerResolvability = "NotAllowed" -) - -func PossibleValuesForHealthErrorCustomerResolvability() []string { - return []string{ - string(HealthErrorCustomerResolvabilityAllowed), - string(HealthErrorCustomerResolvabilityNotAllowed), - } -} - -func parseHealthErrorCustomerResolvability(input string) (*HealthErrorCustomerResolvability, error) { - vals := map[string]HealthErrorCustomerResolvability{ - "allowed": HealthErrorCustomerResolvabilityAllowed, - "notallowed": HealthErrorCustomerResolvabilityNotAllowed, - } - if v, ok := vals[strings.ToLower(input)]; ok { - return &v, nil - } - - // otherwise presume it's an undefined value and best-effort it - out := HealthErrorCustomerResolvability(input) - return &out, nil -} - -type PresenceStatus string - -const ( - PresenceStatusNotPresent PresenceStatus = "NotPresent" - PresenceStatusPresent PresenceStatus = "Present" - PresenceStatusUnknown PresenceStatus = "Unknown" -) - -func PossibleValuesForPresenceStatus() []string { - return []string{ - string(PresenceStatusNotPresent), - string(PresenceStatusPresent), - string(PresenceStatusUnknown), - } -} - -func parsePresenceStatus(input string) (*PresenceStatus, error) { - vals := map[string]PresenceStatus{ - "notpresent": PresenceStatusNotPresent, - "present": PresenceStatusPresent, - "unknown": PresenceStatusUnknown, - } - if v, ok := vals[strings.ToLower(input)]; ok { - return &v, nil - } - - // otherwise presume it's an undefined value and best-effort it - out := PresenceStatus(input) - return &out, nil -} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2022-10-01/replicationprotectableitems/id_replicationprotectableitem.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2022-10-01/replicationprotectableitems/id_replicationprotectableitem.go deleted file mode 100644 index f7f0b3936cee..000000000000 --- a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2022-10-01/replicationprotectableitems/id_replicationprotectableitem.go +++ /dev/null @@ -1,166 +0,0 @@ -package replicationprotectableitems - -import ( - "fmt" - "strings" - - "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -var _ resourceids.ResourceId = ReplicationProtectableItemId{} - -// ReplicationProtectableItemId is a struct representing the Resource ID for a Replication Protectable Item -type ReplicationProtectableItemId struct { - SubscriptionId string - ResourceGroupName string - VaultName string - ReplicationFabricName string - ReplicationProtectionContainerName string - ReplicationProtectableItemName string -} - -// NewReplicationProtectableItemID returns a new ReplicationProtectableItemId struct -func NewReplicationProtectableItemID(subscriptionId string, resourceGroupName string, vaultName string, replicationFabricName string, replicationProtectionContainerName string, replicationProtectableItemName string) ReplicationProtectableItemId { - return ReplicationProtectableItemId{ - SubscriptionId: subscriptionId, - ResourceGroupName: resourceGroupName, - VaultName: vaultName, - ReplicationFabricName: replicationFabricName, - ReplicationProtectionContainerName: replicationProtectionContainerName, - ReplicationProtectableItemName: replicationProtectableItemName, - } -} - -// ParseReplicationProtectableItemID parses 'input' into a ReplicationProtectableItemId -func ParseReplicationProtectableItemID(input string) (*ReplicationProtectableItemId, error) { - parser := resourceids.NewParserFromResourceIdType(ReplicationProtectableItemId{}) - parsed, err := parser.Parse(input, false) - if err != nil { - return nil, fmt.Errorf("parsing %q: %+v", input, err) - } - - var ok bool - id := ReplicationProtectableItemId{} - - if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { - return nil, resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", *parsed) - } - - if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { - return nil, resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", *parsed) - } - - if id.VaultName, ok = parsed.Parsed["vaultName"]; !ok { - return nil, resourceids.NewSegmentNotSpecifiedError(id, "vaultName", *parsed) - } - - if id.ReplicationFabricName, ok = parsed.Parsed["replicationFabricName"]; !ok { - return nil, resourceids.NewSegmentNotSpecifiedError(id, "replicationFabricName", *parsed) - } - - if id.ReplicationProtectionContainerName, ok = parsed.Parsed["replicationProtectionContainerName"]; !ok { - return nil, resourceids.NewSegmentNotSpecifiedError(id, "replicationProtectionContainerName", *parsed) - } - - if id.ReplicationProtectableItemName, ok = parsed.Parsed["replicationProtectableItemName"]; !ok { - return nil, resourceids.NewSegmentNotSpecifiedError(id, "replicationProtectableItemName", *parsed) - } - - return &id, nil -} - -// ParseReplicationProtectableItemIDInsensitively parses 'input' case-insensitively into a ReplicationProtectableItemId -// note: this method should only be used for API response data and not user input -func ParseReplicationProtectableItemIDInsensitively(input string) (*ReplicationProtectableItemId, error) { - parser := resourceids.NewParserFromResourceIdType(ReplicationProtectableItemId{}) - parsed, err := parser.Parse(input, true) - if err != nil { - return nil, fmt.Errorf("parsing %q: %+v", input, err) - } - - var ok bool - id := ReplicationProtectableItemId{} - - if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { - return nil, resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", *parsed) - } - - if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { - return nil, resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", *parsed) - } - - if id.VaultName, ok = parsed.Parsed["vaultName"]; !ok { - return nil, resourceids.NewSegmentNotSpecifiedError(id, "vaultName", *parsed) - } - - if id.ReplicationFabricName, ok = parsed.Parsed["replicationFabricName"]; !ok { - return nil, resourceids.NewSegmentNotSpecifiedError(id, "replicationFabricName", *parsed) - } - - if id.ReplicationProtectionContainerName, ok = parsed.Parsed["replicationProtectionContainerName"]; !ok { - return nil, resourceids.NewSegmentNotSpecifiedError(id, "replicationProtectionContainerName", *parsed) - } - - if id.ReplicationProtectableItemName, ok = parsed.Parsed["replicationProtectableItemName"]; !ok { - return nil, resourceids.NewSegmentNotSpecifiedError(id, "replicationProtectableItemName", *parsed) - } - - return &id, nil -} - -// ValidateReplicationProtectableItemID checks that 'input' can be parsed as a Replication Protectable Item ID -func ValidateReplicationProtectableItemID(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 := ParseReplicationProtectableItemID(v); err != nil { - errors = append(errors, err) - } - - return -} - -// ID returns the formatted Replication Protectable Item ID -func (id ReplicationProtectableItemId) ID() string { - fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.RecoveryServices/vaults/%s/replicationFabrics/%s/replicationProtectionContainers/%s/replicationProtectableItems/%s" - return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.VaultName, id.ReplicationFabricName, id.ReplicationProtectionContainerName, id.ReplicationProtectableItemName) -} - -// Segments returns a slice of Resource ID Segments which comprise this Replication Protectable Item ID -func (id ReplicationProtectableItemId) 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("staticMicrosoftRecoveryServices", "Microsoft.RecoveryServices", "Microsoft.RecoveryServices"), - resourceids.StaticSegment("staticVaults", "vaults", "vaults"), - resourceids.UserSpecifiedSegment("vaultName", "vaultValue"), - resourceids.StaticSegment("staticReplicationFabrics", "replicationFabrics", "replicationFabrics"), - resourceids.UserSpecifiedSegment("replicationFabricName", "replicationFabricValue"), - resourceids.StaticSegment("staticReplicationProtectionContainers", "replicationProtectionContainers", "replicationProtectionContainers"), - resourceids.UserSpecifiedSegment("replicationProtectionContainerName", "replicationProtectionContainerValue"), - resourceids.StaticSegment("staticReplicationProtectableItems", "replicationProtectableItems", "replicationProtectableItems"), - resourceids.UserSpecifiedSegment("replicationProtectableItemName", "replicationProtectableItemValue"), - } -} - -// String returns a human-readable description of this Replication Protectable Item ID -func (id ReplicationProtectableItemId) String() string { - components := []string{ - fmt.Sprintf("Subscription: %q", id.SubscriptionId), - fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), - fmt.Sprintf("Vault Name: %q", id.VaultName), - fmt.Sprintf("Replication Fabric Name: %q", id.ReplicationFabricName), - fmt.Sprintf("Replication Protection Container Name: %q", id.ReplicationProtectionContainerName), - fmt.Sprintf("Replication Protectable Item Name: %q", id.ReplicationProtectableItemName), - } - return fmt.Sprintf("Replication Protectable Item (%s)", strings.Join(components, "\n")) -} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2022-10-01/replicationprotectableitems/id_replicationprotectioncontainer.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2022-10-01/replicationprotectableitems/id_replicationprotectioncontainer.go deleted file mode 100644 index 927a68eca8c3..000000000000 --- a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2022-10-01/replicationprotectableitems/id_replicationprotectioncontainer.go +++ /dev/null @@ -1,153 +0,0 @@ -package replicationprotectableitems - -import ( - "fmt" - "strings" - - "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -var _ resourceids.ResourceId = ReplicationProtectionContainerId{} - -// ReplicationProtectionContainerId is a struct representing the Resource ID for a Replication Protection Container -type ReplicationProtectionContainerId struct { - SubscriptionId string - ResourceGroupName string - VaultName string - ReplicationFabricName string - ReplicationProtectionContainerName string -} - -// NewReplicationProtectionContainerID returns a new ReplicationProtectionContainerId struct -func NewReplicationProtectionContainerID(subscriptionId string, resourceGroupName string, vaultName string, replicationFabricName string, replicationProtectionContainerName string) ReplicationProtectionContainerId { - return ReplicationProtectionContainerId{ - SubscriptionId: subscriptionId, - ResourceGroupName: resourceGroupName, - VaultName: vaultName, - ReplicationFabricName: replicationFabricName, - ReplicationProtectionContainerName: replicationProtectionContainerName, - } -} - -// ParseReplicationProtectionContainerID parses 'input' into a ReplicationProtectionContainerId -func ParseReplicationProtectionContainerID(input string) (*ReplicationProtectionContainerId, error) { - parser := resourceids.NewParserFromResourceIdType(ReplicationProtectionContainerId{}) - parsed, err := parser.Parse(input, false) - if err != nil { - return nil, fmt.Errorf("parsing %q: %+v", input, err) - } - - var ok bool - id := ReplicationProtectionContainerId{} - - if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { - return nil, resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", *parsed) - } - - if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { - return nil, resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", *parsed) - } - - if id.VaultName, ok = parsed.Parsed["vaultName"]; !ok { - return nil, resourceids.NewSegmentNotSpecifiedError(id, "vaultName", *parsed) - } - - if id.ReplicationFabricName, ok = parsed.Parsed["replicationFabricName"]; !ok { - return nil, resourceids.NewSegmentNotSpecifiedError(id, "replicationFabricName", *parsed) - } - - if id.ReplicationProtectionContainerName, ok = parsed.Parsed["replicationProtectionContainerName"]; !ok { - return nil, resourceids.NewSegmentNotSpecifiedError(id, "replicationProtectionContainerName", *parsed) - } - - return &id, nil -} - -// ParseReplicationProtectionContainerIDInsensitively parses 'input' case-insensitively into a ReplicationProtectionContainerId -// note: this method should only be used for API response data and not user input -func ParseReplicationProtectionContainerIDInsensitively(input string) (*ReplicationProtectionContainerId, error) { - parser := resourceids.NewParserFromResourceIdType(ReplicationProtectionContainerId{}) - parsed, err := parser.Parse(input, true) - if err != nil { - return nil, fmt.Errorf("parsing %q: %+v", input, err) - } - - var ok bool - id := ReplicationProtectionContainerId{} - - if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { - return nil, resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", *parsed) - } - - if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { - return nil, resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", *parsed) - } - - if id.VaultName, ok = parsed.Parsed["vaultName"]; !ok { - return nil, resourceids.NewSegmentNotSpecifiedError(id, "vaultName", *parsed) - } - - if id.ReplicationFabricName, ok = parsed.Parsed["replicationFabricName"]; !ok { - return nil, resourceids.NewSegmentNotSpecifiedError(id, "replicationFabricName", *parsed) - } - - if id.ReplicationProtectionContainerName, ok = parsed.Parsed["replicationProtectionContainerName"]; !ok { - return nil, resourceids.NewSegmentNotSpecifiedError(id, "replicationProtectionContainerName", *parsed) - } - - return &id, nil -} - -// ValidateReplicationProtectionContainerID checks that 'input' can be parsed as a Replication Protection Container ID -func ValidateReplicationProtectionContainerID(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 := ParseReplicationProtectionContainerID(v); err != nil { - errors = append(errors, err) - } - - return -} - -// ID returns the formatted Replication Protection Container ID -func (id ReplicationProtectionContainerId) ID() string { - fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.RecoveryServices/vaults/%s/replicationFabrics/%s/replicationProtectionContainers/%s" - return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.VaultName, id.ReplicationFabricName, id.ReplicationProtectionContainerName) -} - -// Segments returns a slice of Resource ID Segments which comprise this Replication Protection Container ID -func (id ReplicationProtectionContainerId) 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("staticMicrosoftRecoveryServices", "Microsoft.RecoveryServices", "Microsoft.RecoveryServices"), - resourceids.StaticSegment("staticVaults", "vaults", "vaults"), - resourceids.UserSpecifiedSegment("vaultName", "vaultValue"), - resourceids.StaticSegment("staticReplicationFabrics", "replicationFabrics", "replicationFabrics"), - resourceids.UserSpecifiedSegment("replicationFabricName", "replicationFabricValue"), - resourceids.StaticSegment("staticReplicationProtectionContainers", "replicationProtectionContainers", "replicationProtectionContainers"), - resourceids.UserSpecifiedSegment("replicationProtectionContainerName", "replicationProtectionContainerValue"), - } -} - -// String returns a human-readable description of this Replication Protection Container ID -func (id ReplicationProtectionContainerId) String() string { - components := []string{ - fmt.Sprintf("Subscription: %q", id.SubscriptionId), - fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), - fmt.Sprintf("Vault Name: %q", id.VaultName), - fmt.Sprintf("Replication Fabric Name: %q", id.ReplicationFabricName), - fmt.Sprintf("Replication Protection Container Name: %q", id.ReplicationProtectionContainerName), - } - return fmt.Sprintf("Replication Protection Container (%s)", strings.Join(components, "\n")) -} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2022-10-01/replicationprotectableitems/method_get_autorest.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2022-10-01/replicationprotectableitems/method_get_autorest.go deleted file mode 100644 index 5f174d7a1ccf..000000000000 --- a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2022-10-01/replicationprotectableitems/method_get_autorest.go +++ /dev/null @@ -1,68 +0,0 @@ -package replicationprotectableitems - -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 *ProtectableItem -} - -// Get ... -func (c ReplicationProtectableItemsClient) Get(ctx context.Context, id ReplicationProtectableItemId) (result GetOperationResponse, err error) { - req, err := c.preparerForGet(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "replicationprotectableitems.ReplicationProtectableItemsClient", "Get", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "replicationprotectableitems.ReplicationProtectableItemsClient", "Get", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForGet(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "replicationprotectableitems.ReplicationProtectableItemsClient", "Get", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForGet prepares the Get request. -func (c ReplicationProtectableItemsClient) preparerForGet(ctx context.Context, id ReplicationProtectableItemId) (*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 ReplicationProtectableItemsClient) 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/recoveryservicessiterecovery/2022-10-01/replicationprotectableitems/method_listbyreplicationprotectioncontainers_autorest.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2022-10-01/replicationprotectableitems/method_listbyreplicationprotectioncontainers_autorest.go deleted file mode 100644 index 5c77821d594b..000000000000 --- a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2022-10-01/replicationprotectableitems/method_listbyreplicationprotectioncontainers_autorest.go +++ /dev/null @@ -1,220 +0,0 @@ -package replicationprotectableitems - -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 ListByReplicationProtectionContainersOperationResponse struct { - HttpResponse *http.Response - Model *[]ProtectableItem - - nextLink *string - nextPageFunc func(ctx context.Context, nextLink string) (ListByReplicationProtectionContainersOperationResponse, error) -} - -type ListByReplicationProtectionContainersCompleteResult struct { - Items []ProtectableItem -} - -func (r ListByReplicationProtectionContainersOperationResponse) HasMore() bool { - return r.nextLink != nil -} - -func (r ListByReplicationProtectionContainersOperationResponse) LoadMore(ctx context.Context) (resp ListByReplicationProtectionContainersOperationResponse, err error) { - if !r.HasMore() { - err = fmt.Errorf("no more pages returned") - return - } - return r.nextPageFunc(ctx, *r.nextLink) -} - -type ListByReplicationProtectionContainersOperationOptions struct { - Filter *string - Take *string -} - -func DefaultListByReplicationProtectionContainersOperationOptions() ListByReplicationProtectionContainersOperationOptions { - return ListByReplicationProtectionContainersOperationOptions{} -} - -func (o ListByReplicationProtectionContainersOperationOptions) toHeaders() map[string]interface{} { - out := make(map[string]interface{}) - - return out -} - -func (o ListByReplicationProtectionContainersOperationOptions) toQueryString() map[string]interface{} { - out := make(map[string]interface{}) - - if o.Filter != nil { - out["$filter"] = *o.Filter - } - - if o.Take != nil { - out["$take"] = *o.Take - } - - return out -} - -// ListByReplicationProtectionContainers ... -func (c ReplicationProtectableItemsClient) ListByReplicationProtectionContainers(ctx context.Context, id ReplicationProtectionContainerId, options ListByReplicationProtectionContainersOperationOptions) (resp ListByReplicationProtectionContainersOperationResponse, err error) { - req, err := c.preparerForListByReplicationProtectionContainers(ctx, id, options) - if err != nil { - err = autorest.NewErrorWithError(err, "replicationprotectableitems.ReplicationProtectableItemsClient", "ListByReplicationProtectionContainers", nil, "Failure preparing request") - return - } - - resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "replicationprotectableitems.ReplicationProtectableItemsClient", "ListByReplicationProtectionContainers", resp.HttpResponse, "Failure sending request") - return - } - - resp, err = c.responderForListByReplicationProtectionContainers(resp.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "replicationprotectableitems.ReplicationProtectableItemsClient", "ListByReplicationProtectionContainers", resp.HttpResponse, "Failure responding to request") - return - } - return -} - -// preparerForListByReplicationProtectionContainers prepares the ListByReplicationProtectionContainers request. -func (c ReplicationProtectableItemsClient) preparerForListByReplicationProtectionContainers(ctx context.Context, id ReplicationProtectionContainerId, options ListByReplicationProtectionContainersOperationOptions) (*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/replicationProtectableItems", id.ID())), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// preparerForListByReplicationProtectionContainersWithNextLink prepares the ListByReplicationProtectionContainers request with the given nextLink token. -func (c ReplicationProtectableItemsClient) preparerForListByReplicationProtectionContainersWithNextLink(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)) -} - -// responderForListByReplicationProtectionContainers handles the response to the ListByReplicationProtectionContainers request. The method always -// closes the http.Response Body. -func (c ReplicationProtectableItemsClient) responderForListByReplicationProtectionContainers(resp *http.Response) (result ListByReplicationProtectionContainersOperationResponse, err error) { - type page struct { - Values []ProtectableItem `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 ListByReplicationProtectionContainersOperationResponse, err error) { - req, err := c.preparerForListByReplicationProtectionContainersWithNextLink(ctx, nextLink) - if err != nil { - err = autorest.NewErrorWithError(err, "replicationprotectableitems.ReplicationProtectableItemsClient", "ListByReplicationProtectionContainers", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "replicationprotectableitems.ReplicationProtectableItemsClient", "ListByReplicationProtectionContainers", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForListByReplicationProtectionContainers(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "replicationprotectableitems.ReplicationProtectableItemsClient", "ListByReplicationProtectionContainers", result.HttpResponse, "Failure responding to request") - return - } - - return - } - } - return -} - -// ListByReplicationProtectionContainersComplete retrieves all of the results into a single object -func (c ReplicationProtectableItemsClient) ListByReplicationProtectionContainersComplete(ctx context.Context, id ReplicationProtectionContainerId, options ListByReplicationProtectionContainersOperationOptions) (ListByReplicationProtectionContainersCompleteResult, error) { - return c.ListByReplicationProtectionContainersCompleteMatchingPredicate(ctx, id, options, ProtectableItemOperationPredicate{}) -} - -// ListByReplicationProtectionContainersCompleteMatchingPredicate retrieves all of the results and then applied the predicate -func (c ReplicationProtectableItemsClient) ListByReplicationProtectionContainersCompleteMatchingPredicate(ctx context.Context, id ReplicationProtectionContainerId, options ListByReplicationProtectionContainersOperationOptions, predicate ProtectableItemOperationPredicate) (resp ListByReplicationProtectionContainersCompleteResult, err error) { - items := make([]ProtectableItem, 0) - - page, err := c.ListByReplicationProtectionContainers(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 := ListByReplicationProtectionContainersCompleteResult{ - Items: items, - } - return out, nil -} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2022-10-01/replicationprotectableitems/model_configurationsettings.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2022-10-01/replicationprotectableitems/model_configurationsettings.go deleted file mode 100644 index 4d071558c6cb..000000000000 --- a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2022-10-01/replicationprotectableitems/model_configurationsettings.go +++ /dev/null @@ -1,64 +0,0 @@ -package replicationprotectableitems - -import ( - "encoding/json" - "fmt" - "strings" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type ConfigurationSettings interface { -} - -func unmarshalConfigurationSettingsImplementation(input []byte) (ConfigurationSettings, error) { - if input == nil { - return nil, nil - } - - var temp map[string]interface{} - if err := json.Unmarshal(input, &temp); err != nil { - return nil, fmt.Errorf("unmarshaling ConfigurationSettings into map[string]interface: %+v", err) - } - - value, ok := temp["instanceType"].(string) - if !ok { - return nil, nil - } - - if strings.EqualFold(value, "HyperVVirtualMachine") { - var out HyperVVirtualMachineDetails - if err := json.Unmarshal(input, &out); err != nil { - return nil, fmt.Errorf("unmarshaling into HyperVVirtualMachineDetails: %+v", err) - } - return out, nil - } - - if strings.EqualFold(value, "ReplicationGroupDetails") { - var out ReplicationGroupDetails - if err := json.Unmarshal(input, &out); err != nil { - return nil, fmt.Errorf("unmarshaling into ReplicationGroupDetails: %+v", err) - } - return out, nil - } - - if strings.EqualFold(value, "VMwareVirtualMachine") { - var out VMwareVirtualMachineDetails - if err := json.Unmarshal(input, &out); err != nil { - return nil, fmt.Errorf("unmarshaling into VMwareVirtualMachineDetails: %+v", err) - } - return out, nil - } - - type RawConfigurationSettingsImpl struct { - Type string `json:"-"` - Values map[string]interface{} `json:"-"` - } - out := RawConfigurationSettingsImpl{ - Type: value, - Values: temp, - } - return out, nil - -} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2022-10-01/replicationprotectableitems/model_diskdetails.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2022-10-01/replicationprotectableitems/model_diskdetails.go deleted file mode 100644 index f418a8a199ab..000000000000 --- a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2022-10-01/replicationprotectableitems/model_diskdetails.go +++ /dev/null @@ -1,11 +0,0 @@ -package replicationprotectableitems - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type DiskDetails struct { - MaxSizeMB *int64 `json:"maxSizeMB,omitempty"` - VhdId *string `json:"vhdId,omitempty"` - VhdName *string `json:"vhdName,omitempty"` - VhdType *string `json:"vhdType,omitempty"` -} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2022-10-01/replicationprotectableitems/model_diskvolumedetails.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2022-10-01/replicationprotectableitems/model_diskvolumedetails.go deleted file mode 100644 index a1807b2e5d90..000000000000 --- a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2022-10-01/replicationprotectableitems/model_diskvolumedetails.go +++ /dev/null @@ -1,9 +0,0 @@ -package replicationprotectableitems - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type DiskVolumeDetails struct { - Label *string `json:"label,omitempty"` - Name *string `json:"name,omitempty"` -} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2022-10-01/replicationprotectableitems/model_healtherror.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2022-10-01/replicationprotectableitems/model_healtherror.go deleted file mode 100644 index dd836fd7405e..000000000000 --- a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2022-10-01/replicationprotectableitems/model_healtherror.go +++ /dev/null @@ -1,40 +0,0 @@ -package replicationprotectableitems - -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 HealthError struct { - CreationTimeUtc *string `json:"creationTimeUtc,omitempty"` - CustomerResolvability *HealthErrorCustomerResolvability `json:"customerResolvability,omitempty"` - EntityId *string `json:"entityId,omitempty"` - ErrorCategory *string `json:"errorCategory,omitempty"` - ErrorCode *string `json:"errorCode,omitempty"` - ErrorId *string `json:"errorId,omitempty"` - ErrorLevel *string `json:"errorLevel,omitempty"` - ErrorMessage *string `json:"errorMessage,omitempty"` - ErrorSource *string `json:"errorSource,omitempty"` - ErrorType *string `json:"errorType,omitempty"` - InnerHealthErrors *[]InnerHealthError `json:"innerHealthErrors,omitempty"` - PossibleCauses *string `json:"possibleCauses,omitempty"` - RecommendedAction *string `json:"recommendedAction,omitempty"` - RecoveryProviderErrorMessage *string `json:"recoveryProviderErrorMessage,omitempty"` - SummaryMessage *string `json:"summaryMessage,omitempty"` -} - -func (o *HealthError) GetCreationTimeUtcAsTime() (*time.Time, error) { - if o.CreationTimeUtc == nil { - return nil, nil - } - return dates.ParseAsFormat(o.CreationTimeUtc, "2006-01-02T15:04:05Z07:00") -} - -func (o *HealthError) SetCreationTimeUtcAsTime(input time.Time) { - formatted := input.Format("2006-01-02T15:04:05Z07:00") - o.CreationTimeUtc = &formatted -} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2022-10-01/replicationprotectableitems/model_hypervvirtualmachinedetails.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2022-10-01/replicationprotectableitems/model_hypervvirtualmachinedetails.go deleted file mode 100644 index 73a1c26e7088..000000000000 --- a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2022-10-01/replicationprotectableitems/model_hypervvirtualmachinedetails.go +++ /dev/null @@ -1,48 +0,0 @@ -package replicationprotectableitems - -import ( - "encoding/json" - "fmt" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -var _ ConfigurationSettings = HyperVVirtualMachineDetails{} - -type HyperVVirtualMachineDetails struct { - DiskDetails *[]DiskDetails `json:"diskDetails,omitempty"` - Generation *string `json:"generation,omitempty"` - HasFibreChannelAdapter *PresenceStatus `json:"hasFibreChannelAdapter,omitempty"` - HasPhysicalDisk *PresenceStatus `json:"hasPhysicalDisk,omitempty"` - HasSharedVhd *PresenceStatus `json:"hasSharedVhd,omitempty"` - HyperVHostId *string `json:"hyperVHostId,omitempty"` - OsDetails *OSDetails `json:"osDetails,omitempty"` - SourceItemId *string `json:"sourceItemId,omitempty"` - - // Fields inherited from ConfigurationSettings -} - -var _ json.Marshaler = HyperVVirtualMachineDetails{} - -func (s HyperVVirtualMachineDetails) MarshalJSON() ([]byte, error) { - type wrapper HyperVVirtualMachineDetails - wrapped := wrapper(s) - encoded, err := json.Marshal(wrapped) - if err != nil { - return nil, fmt.Errorf("marshaling HyperVVirtualMachineDetails: %+v", err) - } - - var decoded map[string]interface{} - if err := json.Unmarshal(encoded, &decoded); err != nil { - return nil, fmt.Errorf("unmarshaling HyperVVirtualMachineDetails: %+v", err) - } - decoded["instanceType"] = "HyperVVirtualMachine" - - encoded, err = json.Marshal(decoded) - if err != nil { - return nil, fmt.Errorf("re-marshaling HyperVVirtualMachineDetails: %+v", err) - } - - return encoded, nil -} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2022-10-01/replicationprotectableitems/model_inmagediskdetails.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2022-10-01/replicationprotectableitems/model_inmagediskdetails.go deleted file mode 100644 index a4233f281363..000000000000 --- a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2022-10-01/replicationprotectableitems/model_inmagediskdetails.go +++ /dev/null @@ -1,13 +0,0 @@ -package replicationprotectableitems - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type InMageDiskDetails struct { - DiskConfiguration *string `json:"diskConfiguration,omitempty"` - DiskId *string `json:"diskId,omitempty"` - DiskName *string `json:"diskName,omitempty"` - DiskSizeInMB *string `json:"diskSizeInMB,omitempty"` - DiskType *string `json:"diskType,omitempty"` - VolumeList *[]DiskVolumeDetails `json:"volumeList,omitempty"` -} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2022-10-01/replicationprotectableitems/model_innerhealtherror.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2022-10-01/replicationprotectableitems/model_innerhealtherror.go deleted file mode 100644 index ee306e7b2305..000000000000 --- a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2022-10-01/replicationprotectableitems/model_innerhealtherror.go +++ /dev/null @@ -1,39 +0,0 @@ -package replicationprotectableitems - -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 InnerHealthError struct { - CreationTimeUtc *string `json:"creationTimeUtc,omitempty"` - CustomerResolvability *HealthErrorCustomerResolvability `json:"customerResolvability,omitempty"` - EntityId *string `json:"entityId,omitempty"` - ErrorCategory *string `json:"errorCategory,omitempty"` - ErrorCode *string `json:"errorCode,omitempty"` - ErrorId *string `json:"errorId,omitempty"` - ErrorLevel *string `json:"errorLevel,omitempty"` - ErrorMessage *string `json:"errorMessage,omitempty"` - ErrorSource *string `json:"errorSource,omitempty"` - ErrorType *string `json:"errorType,omitempty"` - PossibleCauses *string `json:"possibleCauses,omitempty"` - RecommendedAction *string `json:"recommendedAction,omitempty"` - RecoveryProviderErrorMessage *string `json:"recoveryProviderErrorMessage,omitempty"` - SummaryMessage *string `json:"summaryMessage,omitempty"` -} - -func (o *InnerHealthError) GetCreationTimeUtcAsTime() (*time.Time, error) { - if o.CreationTimeUtc == nil { - return nil, nil - } - return dates.ParseAsFormat(o.CreationTimeUtc, "2006-01-02T15:04:05Z07:00") -} - -func (o *InnerHealthError) SetCreationTimeUtcAsTime(input time.Time) { - formatted := input.Format("2006-01-02T15:04:05Z07:00") - o.CreationTimeUtc = &formatted -} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2022-10-01/replicationprotectableitems/model_osdetails.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2022-10-01/replicationprotectableitems/model_osdetails.go deleted file mode 100644 index 7b38e793990d..000000000000 --- a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2022-10-01/replicationprotectableitems/model_osdetails.go +++ /dev/null @@ -1,13 +0,0 @@ -package replicationprotectableitems - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type OSDetails struct { - OSMajorVersion *string `json:"oSMajorVersion,omitempty"` - OSMinorVersion *string `json:"oSMinorVersion,omitempty"` - OSVersion *string `json:"oSVersion,omitempty"` - OsEdition *string `json:"osEdition,omitempty"` - OsType *string `json:"osType,omitempty"` - ProductType *string `json:"productType,omitempty"` -} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2022-10-01/replicationprotectableitems/model_protectableitem.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2022-10-01/replicationprotectableitems/model_protectableitem.go deleted file mode 100644 index f2996c6b5147..000000000000 --- a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2022-10-01/replicationprotectableitems/model_protectableitem.go +++ /dev/null @@ -1,12 +0,0 @@ -package replicationprotectableitems - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type ProtectableItem struct { - Id *string `json:"id,omitempty"` - Location *string `json:"location,omitempty"` - Name *string `json:"name,omitempty"` - Properties *ProtectableItemProperties `json:"properties,omitempty"` - Type *string `json:"type,omitempty"` -} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2022-10-01/replicationprotectableitems/model_protectableitemproperties.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2022-10-01/replicationprotectableitems/model_protectableitemproperties.go deleted file mode 100644 index 5559fc9f13c4..000000000000 --- a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2022-10-01/replicationprotectableitems/model_protectableitemproperties.go +++ /dev/null @@ -1,50 +0,0 @@ -package replicationprotectableitems - -import ( - "encoding/json" - "fmt" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type ProtectableItemProperties struct { - CustomDetails ConfigurationSettings `json:"customDetails"` - FriendlyName *string `json:"friendlyName,omitempty"` - ProtectionReadinessErrors *[]string `json:"protectionReadinessErrors,omitempty"` - ProtectionStatus *string `json:"protectionStatus,omitempty"` - RecoveryServicesProviderId *string `json:"recoveryServicesProviderId,omitempty"` - ReplicationProtectedItemId *string `json:"replicationProtectedItemId,omitempty"` - SupportedReplicationProviders *[]string `json:"supportedReplicationProviders,omitempty"` -} - -var _ json.Unmarshaler = &ProtectableItemProperties{} - -func (s *ProtectableItemProperties) UnmarshalJSON(bytes []byte) error { - type alias ProtectableItemProperties - var decoded alias - if err := json.Unmarshal(bytes, &decoded); err != nil { - return fmt.Errorf("unmarshaling into ProtectableItemProperties: %+v", err) - } - - s.FriendlyName = decoded.FriendlyName - s.ProtectionReadinessErrors = decoded.ProtectionReadinessErrors - s.ProtectionStatus = decoded.ProtectionStatus - s.RecoveryServicesProviderId = decoded.RecoveryServicesProviderId - s.ReplicationProtectedItemId = decoded.ReplicationProtectedItemId - s.SupportedReplicationProviders = decoded.SupportedReplicationProviders - - var temp map[string]json.RawMessage - if err := json.Unmarshal(bytes, &temp); err != nil { - return fmt.Errorf("unmarshaling ProtectableItemProperties into map[string]json.RawMessage: %+v", err) - } - - if v, ok := temp["customDetails"]; ok { - impl, err := unmarshalConfigurationSettingsImplementation(v) - if err != nil { - return fmt.Errorf("unmarshaling field 'CustomDetails' for 'ProtectableItemProperties': %+v", err) - } - s.CustomDetails = impl - } - return nil -} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2022-10-01/replicationprotectableitems/model_replicationgroupdetails.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2022-10-01/replicationprotectableitems/model_replicationgroupdetails.go deleted file mode 100644 index 2afdac69d0e6..000000000000 --- a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2022-10-01/replicationprotectableitems/model_replicationgroupdetails.go +++ /dev/null @@ -1,40 +0,0 @@ -package replicationprotectableitems - -import ( - "encoding/json" - "fmt" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -var _ ConfigurationSettings = ReplicationGroupDetails{} - -type ReplicationGroupDetails struct { - - // Fields inherited from ConfigurationSettings -} - -var _ json.Marshaler = ReplicationGroupDetails{} - -func (s ReplicationGroupDetails) MarshalJSON() ([]byte, error) { - type wrapper ReplicationGroupDetails - wrapped := wrapper(s) - encoded, err := json.Marshal(wrapped) - if err != nil { - return nil, fmt.Errorf("marshaling ReplicationGroupDetails: %+v", err) - } - - var decoded map[string]interface{} - if err := json.Unmarshal(encoded, &decoded); err != nil { - return nil, fmt.Errorf("unmarshaling ReplicationGroupDetails: %+v", err) - } - decoded["instanceType"] = "ReplicationGroupDetails" - - encoded, err = json.Marshal(decoded) - if err != nil { - return nil, fmt.Errorf("re-marshaling ReplicationGroupDetails: %+v", err) - } - - return encoded, nil -} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2022-10-01/replicationprotectableitems/model_vmmvirtualmachinedetails.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2022-10-01/replicationprotectableitems/model_vmmvirtualmachinedetails.go deleted file mode 100644 index 1ae50cf4cc7d..000000000000 --- a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2022-10-01/replicationprotectableitems/model_vmmvirtualmachinedetails.go +++ /dev/null @@ -1,48 +0,0 @@ -package replicationprotectableitems - -import ( - "encoding/json" - "fmt" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -var _ ConfigurationSettings = VMmVirtualMachineDetails{} - -type VMmVirtualMachineDetails struct { - - // Fields inherited from HyperVVirtualMachineDetails - DiskDetails *[]DiskDetails `json:"diskDetails,omitempty"` - Generation *string `json:"generation,omitempty"` - HasFibreChannelAdapter *PresenceStatus `json:"hasFibreChannelAdapter,omitempty"` - HasPhysicalDisk *PresenceStatus `json:"hasPhysicalDisk,omitempty"` - HasSharedVhd *PresenceStatus `json:"hasSharedVhd,omitempty"` - HyperVHostId *string `json:"hyperVHostId,omitempty"` - OsDetails *OSDetails `json:"osDetails,omitempty"` - SourceItemId *string `json:"sourceItemId,omitempty"` -} - -var _ json.Marshaler = VMmVirtualMachineDetails{} - -func (s VMmVirtualMachineDetails) MarshalJSON() ([]byte, error) { - type wrapper VMmVirtualMachineDetails - wrapped := wrapper(s) - encoded, err := json.Marshal(wrapped) - if err != nil { - return nil, fmt.Errorf("marshaling VMmVirtualMachineDetails: %+v", err) - } - - var decoded map[string]interface{} - if err := json.Unmarshal(encoded, &decoded); err != nil { - return nil, fmt.Errorf("unmarshaling VMmVirtualMachineDetails: %+v", err) - } - decoded["instanceType"] = "VmmVirtualMachine" - - encoded, err = json.Marshal(decoded) - if err != nil { - return nil, fmt.Errorf("re-marshaling VMmVirtualMachineDetails: %+v", err) - } - - return encoded, nil -} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2022-10-01/replicationprotectableitems/model_vmwarevirtualmachinedetails.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2022-10-01/replicationprotectableitems/model_vmwarevirtualmachinedetails.go deleted file mode 100644 index 8eb8ecdf063f..000000000000 --- a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2022-10-01/replicationprotectableitems/model_vmwarevirtualmachinedetails.go +++ /dev/null @@ -1,50 +0,0 @@ -package replicationprotectableitems - -import ( - "encoding/json" - "fmt" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -var _ ConfigurationSettings = VMwareVirtualMachineDetails{} - -type VMwareVirtualMachineDetails struct { - AgentGeneratedId *string `json:"agentGeneratedId,omitempty"` - AgentInstalled *string `json:"agentInstalled,omitempty"` - AgentVersion *string `json:"agentVersion,omitempty"` - DiscoveryType *string `json:"discoveryType,omitempty"` - DiskDetails *[]InMageDiskDetails `json:"diskDetails,omitempty"` - IPAddress *string `json:"ipAddress,omitempty"` - OsType *string `json:"osType,omitempty"` - PoweredOn *string `json:"poweredOn,omitempty"` - VCenterInfrastructureId *string `json:"vCenterInfrastructureId,omitempty"` - ValidationErrors *[]HealthError `json:"validationErrors,omitempty"` - - // Fields inherited from ConfigurationSettings -} - -var _ json.Marshaler = VMwareVirtualMachineDetails{} - -func (s VMwareVirtualMachineDetails) MarshalJSON() ([]byte, error) { - type wrapper VMwareVirtualMachineDetails - wrapped := wrapper(s) - encoded, err := json.Marshal(wrapped) - if err != nil { - return nil, fmt.Errorf("marshaling VMwareVirtualMachineDetails: %+v", err) - } - - var decoded map[string]interface{} - if err := json.Unmarshal(encoded, &decoded); err != nil { - return nil, fmt.Errorf("unmarshaling VMwareVirtualMachineDetails: %+v", err) - } - decoded["instanceType"] = "VMwareVirtualMachine" - - encoded, err = json.Marshal(decoded) - if err != nil { - return nil, fmt.Errorf("re-marshaling VMwareVirtualMachineDetails: %+v", err) - } - - return encoded, nil -} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2022-10-01/replicationprotectableitems/predicates.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2022-10-01/replicationprotectableitems/predicates.go deleted file mode 100644 index 06bc4485e632..000000000000 --- a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2022-10-01/replicationprotectableitems/predicates.go +++ /dev/null @@ -1,32 +0,0 @@ -package replicationprotectableitems - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type ProtectableItemOperationPredicate struct { - Id *string - Location *string - Name *string - Type *string -} - -func (p ProtectableItemOperationPredicate) Matches(input ProtectableItem) bool { - - if p.Id != nil && (input.Id == nil && *p.Id != *input.Id) { - return false - } - - if p.Location != nil && (input.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/recoveryservicessiterecovery/2022-10-01/replicationprotectableitems/version.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2022-10-01/replicationprotectableitems/version.go deleted file mode 100644 index 80b6d6b46927..000000000000 --- a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2022-10-01/replicationprotectableitems/version.go +++ /dev/null @@ -1,12 +0,0 @@ -package replicationprotectableitems - -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-10-01" - -func userAgent() string { - return fmt.Sprintf("hashicorp/go-azure-sdk/replicationprotectableitems/%s", defaultApiVersion) -} diff --git a/vendor/modules.txt b/vendor/modules.txt index d04292dab87c..88077464d075 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -565,7 +565,6 @@ github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/ github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2022-10-01/replicationnetworkmappings github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2022-10-01/replicationnetworks github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2022-10-01/replicationpolicies -github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2022-10-01/replicationprotectableitems github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2022-10-01/replicationprotecteditems github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2022-10-01/replicationprotectioncontainermappings github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2022-10-01/replicationprotectioncontainers From 5285a6292ac5dbbe7557fe2791de17e7b5b51f07 Mon Sep 17 00:00:00 2001 From: ziyeqf <51212351+ziyeqf@users.noreply.github.com> Date: Wed, 12 Jul 2023 13:04:59 +0800 Subject: [PATCH 05/15] website typo Signed-off-by: ziyeqf <51212351+ziyeqf@users.noreply.github.com> --- website/docs/r/site_recovery_vmware_replicated_vm.html.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/website/docs/r/site_recovery_vmware_replicated_vm.html.markdown b/website/docs/r/site_recovery_vmware_replicated_vm.html.markdown index 1d19995aa269..3cf687af6813 100644 --- a/website/docs/r/site_recovery_vmware_replicated_vm.html.markdown +++ b/website/docs/r/site_recovery_vmware_replicated_vm.html.markdown @@ -158,7 +158,7 @@ The following arguments are supported: * `target_boot_diagnostics_storage_account_id` - (Optional) The ID of the storage account that should be used for boot diagnostics when a failover is done. -* `managed_disk` - (Optional) One or more `managed_disk` block as defined below. It's avaiable only if mobility service is already installed on the source VM. +* `managed_disk` - (Optional) One or more `managed_disk` block as defined below. It's available only if mobility service is already installed on the source VM. **Note:** a replicated VM could be created without `managed_disk` block, once it has been specified, changing it forces a new resource to be created. From 07365480203f8f898f4b47176b959ab7a471849d Mon Sep 17 00:00:00 2001 From: ziyeqf <51212351+ziyeqf@users.noreply.github.com> Date: Wed, 12 Jul 2023 13:16:59 +0800 Subject: [PATCH 06/15] golint Signed-off-by: ziyeqf <51212351+ziyeqf@users.noreply.github.com> --- .../azuresdkhacks/method_getallrunasaccountsinsite.go | 4 +--- .../site_recovery_vmware_replicated_vm_resource.go | 10 +++------- 2 files changed, 4 insertions(+), 10 deletions(-) diff --git a/internal/services/recoveryservices/azuresdkhacks/method_getallrunasaccountsinsite.go b/internal/services/recoveryservices/azuresdkhacks/method_getallrunasaccountsinsite.go index 6e3ba99c97ea..a7116b0f477d 100644 --- a/internal/services/recoveryservices/azuresdkhacks/method_getallrunasaccountsinsite.go +++ b/internal/services/recoveryservices/azuresdkhacks/method_getallrunasaccountsinsite.go @@ -76,9 +76,7 @@ func (c RunAsAccountsClient) GetAllRunAsAccountsInSiteComplete(ctx context.Conte return GetAllRunAsAccountsInSiteCompleteResult{}, err } if resp.Model != nil { - for _, v := range *resp.Model { - items = append(items, v) - } + items = append(items, *resp.Model...) } return GetAllRunAsAccountsInSiteCompleteResult{Items: items}, nil diff --git a/internal/services/recoveryservices/site_recovery_vmware_replicated_vm_resource.go b/internal/services/recoveryservices/site_recovery_vmware_replicated_vm_resource.go index 61156579494f..24e9ddef0ab1 100644 --- a/internal/services/recoveryservices/site_recovery_vmware_replicated_vm_resource.go +++ b/internal/services/recoveryservices/site_recovery_vmware_replicated_vm_resource.go @@ -548,9 +548,7 @@ func (s VMWareReplicatedVmResource) Create() sdk.ResourceFunc { func (s VMWareReplicatedVmResource) Update() sdk.ResourceFunc { return sdk.ResourceFunc{ Timeout: 90 * time.Minute, - Func: func(ctx context.Context, metadata sdk.ResourceMetaData) error { - return resourceSiteRecoveryReplicatedVmVMWareClassicUpdateInternal(ctx, metadata) - }, + Func: resourceSiteRecoveryReplicatedVmVMWareClassicUpdateInternal, } } @@ -836,10 +834,8 @@ func resourceSiteRecoveryReplicatedVmVMWareClassicUpdateInternal(ctx context.Con if metadata.ResourceData.HasChange("license_type") { updateInput.LicenseType = pointer.To(replicationprotecteditems.LicenseType(model.LicenseType)) - } else { - if existingDetails.LicenseType != nil { - updateInput.LicenseType = pointer.To(replicationprotecteditems.LicenseType(*existingDetails.LicenseType)) - } + } else if existingDetails.LicenseType != nil { + updateInput.LicenseType = pointer.To(replicationprotecteditems.LicenseType(*existingDetails.LicenseType)) } if metadata.ResourceData.HasChange("target_vm_name") { From 0632f64fb879cf3bcaa3607aba433b9012eb28b9 Mon Sep 17 00:00:00 2001 From: ziyeqf <51212351+ziyeqf@users.noreply.github.com> Date: Mon, 17 Jul 2023 17:20:16 +0800 Subject: [PATCH 07/15] update per comments Signed-off-by: ziyeqf <51212351+ziyeqf@users.noreply.github.com> --- .../method_getallmachinesinsite.go | 81 ++ .../method_getallrunasaccountsinsite.go | 1 + .../azuresdkhacks/model_vmwarerunasaccount.go | 3 +- .../recoveryservices/client/client.go | 2 +- .../vmware_replicated_vm_poller.go | 50 ++ ..._recovery_vmware_replicated_vm_resource.go | 714 +++++++----------- ...very_vmware_replicated_vm_resource_test.go | 111 ++- ...ecovery_vmware_replicated_vm.html.markdown | 70 +- 8 files changed, 540 insertions(+), 492 deletions(-) create mode 100644 internal/services/recoveryservices/azuresdkhacks/method_getallmachinesinsite.go create mode 100644 internal/services/recoveryservices/custompollers/vmware_replicated_vm_poller.go diff --git a/internal/services/recoveryservices/azuresdkhacks/method_getallmachinesinsite.go b/internal/services/recoveryservices/azuresdkhacks/method_getallmachinesinsite.go new file mode 100644 index 000000000000..1b7f1425b822 --- /dev/null +++ b/internal/services/recoveryservices/azuresdkhacks/method_getallmachinesinsite.go @@ -0,0 +1,81 @@ +package azuresdkhacks + +import ( + "context" + "fmt" + "net/http" + "net/url" + + "github.com/hashicorp/go-azure-helpers/lang/pointer" + vmwaremachines "github.com/hashicorp/go-azure-sdk/resource-manager/migrate/2020-01-01/machines" + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" +) + +// workaround for https://github.com/hashicorp/go-azure-sdk/issues/492 +// TODO4.0: check if this could be removed. +// the method has been re-written to read `nextLink` + +type MachinesClient struct { + Client *resourcemanager.Client +} + +type Values struct { + Values *[]vmwaremachines.VMwareMachine `json:"value"` + NextLink *string `json:"nextLink"` +} + +func (c MachinesClient) GetAllVMWareMachinesInSite(ctx context.Context, id vmwaremachines.VMwareSiteId, options vmwaremachines.GetAllMachinesInSiteOperationOptions) (result vmwaremachines.GetAllMachinesInSiteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/machines", id.ID()), + OptionsObject: options, + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + return wrapExecutePaged(ctx, req) +} + +func wrapExecutePaged(ctx context.Context, req *client.Request) (result vmwaremachines.GetAllMachinesInSiteOperationResponse, err error) { + resp, err := req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values Values + + if err = resp.Unmarshal(&values); err != nil { + return + } + result.Model = values.Values + + if values.NextLink != nil { + nextReq := req + u, err := url.Parse(*values.NextLink) + if err != nil { + return result, err + } + nextReq.URL = u + nextResp, err := wrapExecutePaged(ctx, nextReq) + if err != nil { + return result, err + } + if nextResp.Model != nil { + result.Model = pointer.To(append(*result.Model, *nextResp.Model...)) + } + } + + return +} diff --git a/internal/services/recoveryservices/azuresdkhacks/method_getallrunasaccountsinsite.go b/internal/services/recoveryservices/azuresdkhacks/method_getallrunasaccountsinsite.go index a7116b0f477d..2587a74442e6 100644 --- a/internal/services/recoveryservices/azuresdkhacks/method_getallrunasaccountsinsite.go +++ b/internal/services/recoveryservices/azuresdkhacks/method_getallrunasaccountsinsite.go @@ -12,6 +12,7 @@ import ( ) // workaround for https://github.com/Azure/azure-rest-api-specs/issues/24712 +// the difference is in the struct `RunAsAccountProperties` // TODO 4.0: check if this could be removed type RunAsAccountsClient struct { diff --git a/internal/services/recoveryservices/azuresdkhacks/model_vmwarerunasaccount.go b/internal/services/recoveryservices/azuresdkhacks/model_vmwarerunasaccount.go index e919962cbb07..a97c94a9a47b 100644 --- a/internal/services/recoveryservices/azuresdkhacks/model_vmwarerunasaccount.go +++ b/internal/services/recoveryservices/azuresdkhacks/model_vmwarerunasaccount.go @@ -14,5 +14,6 @@ type RunAsAccountProperties struct { CredentialType *runasaccounts.CredentialType `json:"credentialType,omitempty"` DisplayName *string `json:"displayName,omitempty"` UpdatedTimestamp *string `json:"updatedTimestamp,omitempty"` - ApplianceName *string `json:"applianceName,omitempty"` + // ApplianceName was not defined in the original code. This is the only change. + ApplianceName *string `json:"applianceName,omitempty"` } diff --git a/internal/services/recoveryservices/client/client.go b/internal/services/recoveryservices/client/client.go index a01afe58a70f..0ceacf4de88b 100644 --- a/internal/services/recoveryservices/client/client.go +++ b/internal/services/recoveryservices/client/client.go @@ -140,7 +140,7 @@ func NewClient(o *common.ClientOptions) (*Client, error) { vmwareRunAsAccountsClient, err := vmwarerunasaccounts.NewRunAsAccountsClientWithBaseURI(o.Environment.ResourceManager) if err != nil { - return nil, fmt.Errorf("building VMWare Machine client: %+v", err) + return nil, fmt.Errorf("building VMWare Run As Accounts client: %+v", err) } o.Configure(vmwareRunAsAccountsClient.Client, o.Authorizers.ResourceManager) diff --git a/internal/services/recoveryservices/custompollers/vmware_replicated_vm_poller.go b/internal/services/recoveryservices/custompollers/vmware_replicated_vm_poller.go new file mode 100644 index 000000000000..edb83bdf79fe --- /dev/null +++ b/internal/services/recoveryservices/custompollers/vmware_replicated_vm_poller.go @@ -0,0 +1,50 @@ +package custompollers + +import ( + "context" + "fmt" + "strings" + "time" + + "github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2022-10-01/replicationprotecteditems" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" +) + +var _ pollers.PollerType = &VMWareReplicatedVMPoller{} + +func NewVMWareReplicatedVMPoller(client *replicationprotecteditems.ReplicationProtectedItemsClient, id replicationprotecteditems.ReplicationProtectedItemId) *VMWareReplicatedVMPoller { + return &VMWareReplicatedVMPoller{ + client: client, + id: id, + } +} + +type VMWareReplicatedVMPoller struct { + client *replicationprotecteditems.ReplicationProtectedItemsClient + id replicationprotecteditems.ReplicationProtectedItemId +} + +func (p VMWareReplicatedVMPoller) Poll(ctx context.Context) (*pollers.PollResult, error) { + resp, err := p.client.Get(ctx, p.id) + if err != nil { + return nil, fmt.Errorf("retrieving %s: %+v", p.id, err) + } + + protectionState := "" + if model := resp.Model; model != nil && model.Properties != nil && resp.Model.Properties.ProtectionState != nil { + protectionState = *model.Properties.ProtectionState + } + + if strings.EqualFold(protectionState, "Protected") || strings.EqualFold(protectionState, "normal") { + return &pollers.PollResult{ + Status: pollers.PollingStatusSucceeded, + PollInterval: 1 * time.Minute, + }, nil + } + + // Processing + return &pollers.PollResult{ + Status: pollers.PollingStatusInProgress, + PollInterval: 1 * time.Minute, + }, nil +} diff --git a/internal/services/recoveryservices/site_recovery_vmware_replicated_vm_resource.go b/internal/services/recoveryservices/site_recovery_vmware_replicated_vm_resource.go index 24e9ddef0ab1..3b2db587db2a 100644 --- a/internal/services/recoveryservices/site_recovery_vmware_replicated_vm_resource.go +++ b/internal/services/recoveryservices/site_recovery_vmware_replicated_vm_resource.go @@ -3,8 +3,8 @@ package recoveryservices import ( "context" "fmt" - "net/http" - "net/url" + "log" + "regexp" "strconv" "strings" "time" @@ -23,12 +23,12 @@ import ( "github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2022-10-01/replicationprotecteditems" "github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2022-10-01/replicationprotectioncontainers" "github.com/hashicorp/go-azure-sdk/resource-manager/storage/2022-05-01/storageaccounts" - "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" - "github.com/hashicorp/terraform-provider-azurerm/helpers/azure" "github.com/hashicorp/terraform-provider-azurerm/helpers/tf" "github.com/hashicorp/terraform-provider-azurerm/internal/sdk" "github.com/hashicorp/terraform-provider-azurerm/internal/services/recoveryservices/azuresdkhacks" + "github.com/hashicorp/terraform-provider-azurerm/internal/services/recoveryservices/custompollers" validateResourceGroup "github.com/hashicorp/terraform-provider-azurerm/internal/services/resource/validate" "github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk" "github.com/hashicorp/terraform-provider-azurerm/internal/tf/suppress" @@ -124,11 +124,10 @@ func (s VMWareReplicatedVmResource) Arguments() map[string]*pluginsdk.Schema { }, "recovery_replication_policy_id": { - Type: pluginsdk.TypeString, - Required: true, - ForceNew: true, - ValidateFunc: azure.ValidateResourceID, - DiffSuppressFunc: suppress.CaseDifference, + Type: pluginsdk.TypeString, + Required: true, + ForceNew: true, + ValidateFunc: replicationpolicies.ValidateReplicationPolicyID, }, "physical_server_credential_name": { @@ -146,11 +145,10 @@ func (s VMWareReplicatedVmResource) Arguments() map[string]*pluginsdk.Schema { }, "target_resource_group_id": { - Type: pluginsdk.TypeString, - Required: true, - ForceNew: true, - ValidateFunc: validateResourceGroup.ResourceGroupID, - DiffSuppressFunc: suppress.CaseDifference, + Type: pluginsdk.TypeString, + Required: true, + ForceNew: true, + ValidateFunc: validateResourceGroup.ResourceGroupID, }, "target_vm_name": { @@ -164,13 +162,13 @@ func (s VMWareReplicatedVmResource) Arguments() map[string]*pluginsdk.Schema { Type: pluginsdk.TypeString, Optional: true, ValidateFunc: storageaccounts.ValidateStorageAccountID, - AtLeastOneOf: []string{"managed_disk", "default_log_storage_account_id"}, + ExactlyOneOf: []string{"managed_disk", "default_log_storage_account_id"}, }, - "default_recovery_disk_type": { // only works in creation and will not be returned from service + "default_recovery_disk_type": { Type: pluginsdk.TypeString, Optional: true, - AtLeastOneOf: []string{"managed_disk", "default_recovery_disk_type"}, + ExactlyOneOf: []string{"managed_disk", "default_recovery_disk_type"}, ValidateFunc: validation.StringInSlice(replicationprotecteditems.PossibleValuesForDiskAccountType(), false), }, @@ -200,10 +198,9 @@ func (s VMWareReplicatedVmResource) Arguments() map[string]*pluginsdk.Schema { }, "target_availability_set_id": { - Type: pluginsdk.TypeString, - Optional: true, - ValidateFunc: availabilitysets.ValidateAvailabilitySetID, - DiffSuppressFunc: suppress.CaseDifference, + Type: pluginsdk.TypeString, + Optional: true, + ValidateFunc: availabilitysets.ValidateAvailabilitySetID, ConflictsWith: []string{ "target_zone", }, @@ -222,12 +219,9 @@ func (s VMWareReplicatedVmResource) Arguments() map[string]*pluginsdk.Schema { Type: pluginsdk.TypeString, Optional: true, ValidateFunc: commonids.ValidateVirtualNetworkID, - }, - - "target_subnet_name": { - Type: pluginsdk.TypeString, - Optional: true, - ValidateFunc: validation.StringIsNotEmpty, + RequiredWith: []string{ + "network_interface", + }, }, "test_network_id": { @@ -236,12 +230,6 @@ func (s VMWareReplicatedVmResource) Arguments() map[string]*pluginsdk.Schema { ValidateFunc: commonids.ValidateVirtualNetworkID, }, - "test_subnet_name": { - Type: pluginsdk.TypeString, - Optional: true, - ValidateFunc: validation.StringIsNotEmpty, - }, - "target_boot_diagnostics_storage_account_id": { Type: pluginsdk.TypeString, Optional: true, @@ -250,13 +238,13 @@ func (s VMWareReplicatedVmResource) Arguments() map[string]*pluginsdk.Schema { // managed disk is enabled only if mobility service is already installed. (in most cases, it's not installed) "managed_disk": { - Type: pluginsdk.TypeSet, + Type: pluginsdk.TypeList, Optional: true, Elem: resourceSiteRecoveryVMWareReplicatedVMManagedDiskSchema(), }, "network_interface": { - Type: pluginsdk.TypeSet, + Type: pluginsdk.TypeList, Required: true, Elem: resourceSiteRecoveryVMWareReplicatedVMNetworkInterfaceSchema(), }, @@ -280,16 +268,15 @@ func resourceSiteRecoveryVMWareReplicatedVMManagedDiskSchema() *pluginsdk.Resour }, "target_disk_encryption_set_id": { - Type: pluginsdk.TypeString, - Optional: true, - ValidateFunc: diskencryptionsets.ValidateDiskEncryptionSetID, - DiffSuppressFunc: suppress.CaseDifference, + Type: pluginsdk.TypeString, + Optional: true, + ValidateFunc: diskencryptionsets.ValidateDiskEncryptionSetID, }, "log_storage_account_id": { Type: pluginsdk.TypeString, Required: true, - ValidateFunc: azure.ValidateResourceID, + ValidateFunc: storageaccounts.ValidateStorageAccountID, }, }, } @@ -298,16 +285,16 @@ func resourceSiteRecoveryVMWareReplicatedVMManagedDiskSchema() *pluginsdk.Resour func resourceSiteRecoveryVMWareReplicatedVMNetworkInterfaceSchema() *pluginsdk.Resource { return &pluginsdk.Resource{ Schema: map[string]*pluginsdk.Schema{ - "source_mac_address": { // if it was left blank, we can use the only one NIC id as the source mac address + "source_mac_address": { Type: pluginsdk.TypeString, - Optional: true, - ValidateFunc: azure.ValidateResourceID, + Required: true, + ValidateFunc: validation.StringMatch(regexp.MustCompile(`^[a-fA-F0-9]{2}(:[a-fA-F0-9]{2}){5}$`), "The `source_mac_address` must be in format `00:00:00:00:00:00`"), }, "target_static_ip": { Type: pluginsdk.TypeString, Optional: true, - ValidateFunc: validation.StringIsNotEmpty, + ValidateFunc: validation.IsIPv4Address, }, "target_subnet_name": { @@ -343,8 +330,8 @@ func (k VMWareReplicatedVmResource) CustomizeDiff() sdk.ResourceFunc { _, newStorageAcc := diff.GetChange("default_log_storage_account_id") _, newDiskType := diff.GetChange("default_recovery_disk_type") _, newDes := diff.GetChange("default_target_disk_encryption_set_id") - _, newDisks := diff.GetChange("managed_disk") - for _, disk := range newDisks.(*schema.Set).List() { + oldDisks, newDisks := diff.GetChange("managed_disk") + for _, disk := range oldDisks.([]interface{}) { disk := disk.(map[string]interface{}) if newStorageAcc.(string) != "" && disk["log_storage_account_id"] != newStorageAcc.(string) { metadata.ResourceDiff.ForceNew("default_log_storage_account_id") @@ -358,9 +345,9 @@ func (k VMWareReplicatedVmResource) CustomizeDiff() sdk.ResourceFunc { } if diff.HasChanges("managed_disk") { - // if user has specified `managed_disk`, it's force new. + // if user has specified `managed_disk`, it forces new. // or it acts as an optional field. - if len(newDisks.(*schema.Set).List()) != 1 { + if len(newDisks.([]interface{})) != 0 { metadata.ResourceDiff.ForceNew("managed_disk") } } @@ -392,7 +379,7 @@ func (s VMWareReplicatedVmResource) Create() sdk.ResourceFunc { return fmt.Errorf("parsing vault id %q: %+v", model.RecoveryVaultId, err) } - containerId, err := fetchSiteRecoveryReplicatedVmVMWareContainerId(ctx, containerClient, vaultId.ID()) + containerId, err := fetchSiteRecoveryContainerId(ctx, containerClient, vaultId.ID()) if err != nil { return fmt.Errorf("fetch Replication Container from vault %q: %+v", vaultId, err) } @@ -405,6 +392,13 @@ func (s VMWareReplicatedVmResource) Create() sdk.ResourceFunc { id := replicationprotecteditems.NewReplicationProtectedItemID(parsedContainerId.SubscriptionId, parsedContainerId.ResourceGroupName, parsedContainerId.VaultName, parsedContainerId.ReplicationFabricName, parsedContainerId.ReplicationProtectionContainerName, model.Name) fabricId := replicationfabrics.NewReplicationFabricID(parsedContainerId.SubscriptionId, parsedContainerId.ResourceGroupName, parsedContainerId.VaultName, parsedContainerId.ReplicationFabricName) + existing, err := client.Get(ctx, id) + if err != nil { + if !response.WasNotFound(existing.HttpResponse) { + return fmt.Errorf("checking for presence of existing site recovery vmware replicated vm %q: %+v", id, err) + } + } + processServerId, err := fetchProcessServerIdByName(ctx, fabricClient, fabricId, model.ApplianceName) if err != nil { return fmt.Errorf("fetch process server id: %+v", err) @@ -425,13 +419,6 @@ func (s VMWareReplicatedVmResource) Create() sdk.ResourceFunc { return fmt.Errorf("fetch run as account id %s: %+v", model.PhysicalServerCredentialName, err) } - existing, err := client.Get(ctx, id) - if err != nil { - if !response.WasNotFound(existing.HttpResponse) { - return fmt.Errorf("checking for presence of existing site recovery vmware replicated vm %q: %+v", id, err) - } - } - if existing.Model != nil { return tf.ImportAsExistsError("azurerm_site_recovery_vmware_replicated_vm", *existing.Model.Id) } @@ -444,10 +431,6 @@ func (s VMWareReplicatedVmResource) Create() sdk.ResourceFunc { RunAsAccountId: &runAsAccountId, } - if model.TargetVmSize != "" { - providerSpecificDetail.TargetVMSize = &model.TargetVmSize - } - diskDefaultValueSet := false diskDefaultValue := replicationprotecteditems.InMageRcmDisksDefaultInput{} @@ -470,6 +453,18 @@ func (s VMWareReplicatedVmResource) Create() sdk.ResourceFunc { providerSpecificDetail.DisksDefault = &diskDefaultValue } + if model.MultiVmGroupName != "" { + providerSpecificDetail.MultiVMGroupName = &model.MultiVmGroupName + } + + if model.ApplianceName != "" { + providerSpecificDetail.ProcessServerId = processServerId + } + + if model.TargetVmSize != "" { + providerSpecificDetail.TargetVMSize = &model.TargetVmSize + } + if model.TargetAvailabilitySetId != "" { providerSpecificDetail.TargetAvailabilitySetId = pointer.To(model.TargetAvailabilitySetId) } @@ -482,19 +477,10 @@ func (s VMWareReplicatedVmResource) Create() sdk.ResourceFunc { providerSpecificDetail.TargetBootDiagnosticsStorageAccountId = pointer.To(model.TargetBootDiagnosticsStorageAccountId) } - if model.MultiVmGroupName != "" { - providerSpecificDetail.MultiVMGroupName = &model.MultiVmGroupName - } - if model.TargetProximityPlacementGroupId != "" { providerSpecificDetail.TargetProximityPlacementGroupId = &model.TargetProximityPlacementGroupId } - if model.ApplianceName != "" { - providerSpecificDetail.ProcessServerId = processServerId - } - - // split test network and subnet into isolated parameters if model.TargetNetworkId != "" { providerSpecificDetail.TargetNetworkId = &model.TargetNetworkId } @@ -535,7 +521,38 @@ func (s VMWareReplicatedVmResource) Create() sdk.ResourceFunc { return fmt.Errorf("polling %q: %+v", id, err) } - err = resourceSiteRecoveryReplicatedVmVMWareClassicUpdateInternal(ctx, metadata) + log.Printf("[DEBUG] Waiting for %s to be fully protected..", id) + pollerType := custompollers.NewVMWareReplicatedVMPoller(client, id) + + protectPoller := pollers.NewPoller(pollerType, 1*time.Minute, pollers.DefaultNumberOfDroppedConnectionsToAllow) + if err := protectPoller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("waiting for %s to be fully protected: %s", id, err) + } + + updateInput := replicationprotecteditems.UpdateReplicationProtectedItemInput{ + Properties: &replicationprotecteditems.UpdateReplicationProtectedItemInputProperties{ + RecoveryAvailabilitySetId: providerSpecificDetail.TargetAvailabilitySetId, + RecoveryAzureVMName: providerSpecificDetail.TargetVMName, + RecoveryAzureVMSize: providerSpecificDetail.TargetVMSize, + SelectedRecoveryAzureNetworkId: providerSpecificDetail.TargetNetworkId, + SelectedTfoAzureNetworkId: providerSpecificDetail.TestNetworkId, + ProviderSpecificDetails: replicationprotecteditems.InMageRcmUpdateReplicationProtectedItemInput{ + LicenseType: providerSpecificDetail.LicenseType, + TargetAvailabilityZone: providerSpecificDetail.TargetAvailabilityZone, + TargetAvailabilitySetId: providerSpecificDetail.TargetAvailabilitySetId, + TargetBootDiagnosticsStorageAccountId: providerSpecificDetail.TargetBootDiagnosticsStorageAccountId, + TargetNetworkId: providerSpecificDetail.TargetNetworkId, + TargetProximityPlacementGroupId: providerSpecificDetail.TargetProximityPlacementGroupId, + TargetResourceGroupId: &providerSpecificDetail.TargetResourceGroupId, + TargetVMName: providerSpecificDetail.TargetVMName, + TargetVMSize: providerSpecificDetail.TargetVMSize, + TestNetworkId: providerSpecificDetail.TestNetworkId, + VMNics: pointer.To(expandVMWareReplicatedVMNics(model.NetworkInterface)), + }, + }, + } + + err = client.UpdateThenPoll(ctx, id, updateInput) if err != nil { return fmt.Errorf("creating %q: %+v", id, err) } @@ -548,7 +565,164 @@ func (s VMWareReplicatedVmResource) Create() sdk.ResourceFunc { func (s VMWareReplicatedVmResource) Update() sdk.ResourceFunc { return sdk.ResourceFunc{ Timeout: 90 * time.Minute, - Func: resourceSiteRecoveryReplicatedVmVMWareClassicUpdateInternal, + Func: func(ctx context.Context, metadata sdk.ResourceMetaData) error { + client := metadata.Client.RecoveryServices.ReplicationProtectedItemsClient + + var model SiteRecoveryReplicatedVmVMwareModel + err := metadata.Decode(&model) + if err != nil { + return fmt.Errorf("decoding %+v", err) + } + + id, err := replicationprotecteditems.ParseReplicationProtectedItemID(metadata.ResourceData.Id()) + if err != nil { + return fmt.Errorf("parsing %q: %+v", metadata.ResourceData.Id(), err) + } + + existing, err := client.Get(ctx, *id) + if err != nil { + return fmt.Errorf("retrieving %s: %+v", id, err) + } + + if existing.Model == nil { + return fmt.Errorf("retrieving %s: Model was nil", id) + } + if existing.Model.Properties == nil { + return fmt.Errorf("retrieving %s: Properties was nil", id) + } + if existing.Model.Properties.ProviderSpecificDetails == nil { + return fmt.Errorf("retrieving %s: ProviderSpecificDetails was nil", id) + } + if _, ok := existing.Model.Properties.ProviderSpecificDetails.(replicationprotecteditems.InMageRcmReplicationDetails); !ok { + return fmt.Errorf("retrieving %s: ProviderSpecificDetails was not InMageRcmProtectedItemDetails", id) + } + + existingProps := *existing.Model.Properties + existingDetails := existingProps.ProviderSpecificDetails.(replicationprotecteditems.InMageRcmReplicationDetails) + + vmNics := make([]replicationprotecteditems.InMageRcmNicInput, 0) + if metadata.ResourceData.HasChange("network_interface") { + if model.TargetNetworkId == "" && len(model.NetworkInterface) > 0 { + return fmt.Errorf("`target_network_id` must be set when a `network_interface` is configured") + } + vmNics = expandVMWareReplicatedVMNics(model.NetworkInterface) + } else { + if existingDetails.VMNics == nil { + return fmt.Errorf("retrieving `network_interface`: VMNics was nil.") + } else { + for _, respNic := range *existingDetails.VMNics { + vmNics = append(vmNics, replicationprotecteditems.InMageRcmNicInput{ + IsPrimaryNic: pointer.From(respNic.IsPrimaryNic), + IsSelectedForFailover: respNic.IsSelectedForFailover, + NicId: pointer.From(respNic.NicId), + TargetStaticIPAddress: respNic.TargetIPAddress, + TargetSubnetName: respNic.TargetSubnetName, + TestStaticIPAddress: respNic.TestIPAddress, + TestSubnetName: respNic.TestSubnetName, + }) + } + } + } + + updateInput := replicationprotecteditems.InMageRcmUpdateReplicationProtectedItemInput{ + VMNics: &vmNics, + } + + if metadata.ResourceData.HasChange("license_type") { + updateInput.LicenseType = pointer.To(replicationprotecteditems.LicenseType(model.LicenseType)) + } else if existingDetails.LicenseType != nil { + updateInput.LicenseType = pointer.To(replicationprotecteditems.LicenseType(*existingDetails.LicenseType)) + } + + if metadata.ResourceData.HasChange("target_vm_name") { + updateInput.TargetVMName = &model.TargetVmName + } else { + updateInput.TargetVMName = existingDetails.TargetVMName + } + + if metadata.ResourceData.HasChange("target_resource_group_id") { + updateInput.TargetResourceGroupId = &model.TargetResourceGroupId + } else { + updateInput.TargetResourceGroupId = existingDetails.TargetResourceGroupId + } + + if metadata.ResourceData.HasChange("target_availability_set_id") { + if model.TargetAvailabilitySetId != "" { + updateInput.TargetAvailabilitySetId = &model.TargetAvailabilitySetId + } else { + updateInput.TargetAvailabilitySetId = nil + } + } else { + updateInput.TargetAvailabilitySetId = existingDetails.TargetAvailabilitySetId + } + + if metadata.ResourceData.HasChange("target_zone") { + if model.TargetZone != "" { + updateInput.TargetAvailabilityZone = &model.TargetZone + } else { + updateInput.TargetAvailabilityZone = nil + } + } else { + updateInput.TargetAvailabilityZone = existingDetails.TargetAvailabilityZone + } + + if metadata.ResourceData.HasChange("target_network_id") { + updateInput.TargetNetworkId = &model.TargetNetworkId + } else { + updateInput.TargetNetworkId = existingDetails.TargetNetworkId + } + + if metadata.ResourceData.HasChange("target_proximity_placement_group_id") { + updateInput.TargetProximityPlacementGroupId = &model.TargetProximityPlacementGroupId + } else { + updateInput.TargetProximityPlacementGroupId = existingDetails.TargetProximityPlacementGroupId + } + + if metadata.ResourceData.HasChange("target_boot_diagnostics_storage_account_id") { + updateInput.TargetBootDiagnosticsStorageAccountId = &model.TargetBootDiagnosticsStorageAccountId + } else { + updateInput.TargetBootDiagnosticsStorageAccountId = existingDetails.TargetBootDiagnosticsStorageAccountId + } + + props := replicationprotecteditems.UpdateReplicationProtectedItemInputProperties{ + ProviderSpecificDetails: updateInput, + } + + if metadata.ResourceData.HasChange("target_availability_set_id") { + props.RecoveryAvailabilitySetId = updateInput.TargetAvailabilitySetId + } else { + props.RecoveryAvailabilitySetId = existingDetails.TargetAvailabilitySetId + } + + if metadata.ResourceData.HasChange("target_vm_name") { + props.RecoveryAzureVMName = &model.TargetVmName + } else { + props.RecoveryAzureVMName = existingDetails.TargetVMName + } + + if metadata.ResourceData.HasChange("target_network_id") { + props.SelectedRecoveryAzureNetworkId = &model.TargetNetworkId + } else { + props.SelectedRecoveryAzureNetworkId = existingDetails.TargetNetworkId + } + + if metadata.ResourceData.HasChange("target_vm_size") { + props.RecoveryAzureVMSize = &model.TargetVmSize + } else { + props.RecoveryAzureVMSize = existingDetails.TargetVMSize + } + + parameters := replicationprotecteditems.UpdateReplicationProtectedItemInput{ + Properties: &props, + } + + err = client.UpdateThenPoll(ctx, *id, parameters) + if err != nil { + return fmt.Errorf("updating %q: %+v", id, err) + } + + return nil + }, } } @@ -706,281 +880,7 @@ func (s VMWareReplicatedVmResource) Delete() sdk.ResourceFunc { } } -func resourceSiteRecoveryReplicatedVmVMWareClassicUpdateInternal(ctx context.Context, metadata sdk.ResourceMetaData) error { - client := metadata.Client.RecoveryServices.ReplicationProtectedItemsClient - containerClient := metadata.Client.RecoveryServices.ProtectionContainerClient - // We are only allowed to update the configuration once the VM is fully protected - state, err := waitForVmwareReplicationToBeHealthy(ctx, metadata) - if err != nil { - return err - } - - var model SiteRecoveryReplicatedVmVMwareModel - err = metadata.Decode(&model) - if err != nil { - return fmt.Errorf("decoding %+v", err) - } - - containerId, err := fetchSiteRecoveryReplicatedVmVMWareContainerId(ctx, containerClient, model.RecoveryVaultId) - if err != nil { - return fmt.Errorf("fetch Replication Container from vault %q: %+v", model.RecoveryVaultId, err) - } - parsedContainerId, err := replicationprotectioncontainers.ParseReplicationProtectionContainerID(containerId) - if err != nil { - return fmt.Errorf("parsing %q: %+v", containerId, err) - } - - id := replicationprotecteditems.NewReplicationProtectedItemID(parsedContainerId.SubscriptionId, parsedContainerId.ResourceGroupName, parsedContainerId.VaultName, parsedContainerId.ReplicationFabricName, parsedContainerId.ReplicationProtectionContainerName, model.Name) - - existing, err := client.Get(ctx, id) - if err != nil { - return fmt.Errorf("retrieving %s: %+v", id, err) - } - - if existing.Model == nil { - return fmt.Errorf("retrieving %s: Model was nil", id) - } - if existing.Model.Properties == nil { - return fmt.Errorf("retrieving %s: Properties was nil", id) - } - if existing.Model.Properties.ProviderSpecificDetails == nil { - return fmt.Errorf("retrieving %s: ProviderSpecificDetails was nil", id) - } - if _, ok := existing.Model.Properties.ProviderSpecificDetails.(replicationprotecteditems.InMageRcmReplicationDetails); !ok { - return fmt.Errorf("retrieving %s: ProviderSpecificDetails was not InMageRcmProtectedItemDetails", id) - } - - existingProps := *existing.Model.Properties - existingDetails := existingProps.ProviderSpecificDetails.(replicationprotecteditems.InMageRcmReplicationDetails) - - var targetAvailabilitySetID *string - if model.TargetAvailabilitySetId != "" { - targetAvailabilitySetID = &model.TargetAvailabilitySetId - } else { - targetAvailabilitySetID = nil - } - - var targetAvailabilityZone *string - if model.TargetZone != "" { - targetAvailabilityZone = &model.TargetZone - } else { - targetAvailabilityZone = nil - } - - vmNics := make([]replicationprotecteditems.InMageRcmNicInput, 0) - if metadata.ResourceData.HasChange("network_interface") { - for _, nic := range model.NetworkInterface { - vmNic := replicationprotecteditems.InMageRcmNicInput{ - TargetSubnetName: &nic.TargetSubnetName, - } - if nic.SourceMacAddress != "" { - vmNic.NicId = nic.SourceMacAddress - } else { - if len(model.NetworkInterface) > 1 { - return fmt.Errorf("when `source_mac_address` is not set, there must be exactly one `network_interface` block") - } - if state == nil || state.Properties == nil || state.Properties.ProviderSpecificDetails == nil { - return fmt.Errorf("failed to get nic id from state") - } - - if detail, ok := state.Properties.ProviderSpecificDetails.(replicationprotecteditems.InMageRcmReplicationDetails); ok { - if detail.VMNics != nil && len(*detail.VMNics) == 1 && (*detail.VMNics)[0].NicId != nil { - vmNic.NicId = *(*detail.VMNics)[0].NicId - } else { - return fmt.Errorf("when `source_mac_address` is not set, there must be exactly one Network Adapter on the source VM") - } - } else { - return fmt.Errorf("unexpected provider specific details type: %T", state.Properties.ProviderSpecificDetails) - } - } - - if nic.TargetStaticIp != "" { - vmNic.TargetStaticIPAddress = &nic.TargetStaticIp - } - if nic.IsPrimary { - vmNic.IsPrimaryNic = strconv.FormatBool(true) - vmNic.IsSelectedForFailover = utils.String("true") - } else { - vmNic.IsPrimaryNic = strconv.FormatBool(false) - vmNic.IsSelectedForFailover = utils.String("false") - } - vmNics = append(vmNics, vmNic) - } - - if model.TargetNetworkId == "" && len(vmNics) > 0 { - return fmt.Errorf("`target_network_id` must be set when a `network_interface` is configured") - } - } else { - if existingDetails.VMNics == nil { - return fmt.Errorf("retrieving `network_interface`: VMNics was nil.") - } else { - for _, respNic := range *existingDetails.VMNics { - vmNics = append(vmNics, replicationprotecteditems.InMageRcmNicInput{ - IsPrimaryNic: pointer.From(respNic.IsPrimaryNic), - IsSelectedForFailover: respNic.IsSelectedForFailover, - NicId: pointer.From(respNic.NicId), - TargetStaticIPAddress: respNic.TargetIPAddress, - TargetSubnetName: respNic.TargetSubnetName, - TestStaticIPAddress: respNic.TestIPAddress, - TestSubnetName: respNic.TestSubnetName, - }) - } - } - } - - updateInput := replicationprotecteditems.InMageRcmUpdateReplicationProtectedItemInput{ - VMNics: &vmNics, - } - - if metadata.ResourceData.HasChange("license_type") { - updateInput.LicenseType = pointer.To(replicationprotecteditems.LicenseType(model.LicenseType)) - } else if existingDetails.LicenseType != nil { - updateInput.LicenseType = pointer.To(replicationprotecteditems.LicenseType(*existingDetails.LicenseType)) - } - - if metadata.ResourceData.HasChange("target_vm_name") { - updateInput.TargetVMName = &model.TargetVmName - } else { - updateInput.TargetVMName = existingDetails.TargetVMName - } - - if metadata.ResourceData.HasChange("target_resource_group_id") { - updateInput.TargetResourceGroupId = &model.TargetResourceGroupId - } else { - updateInput.TargetResourceGroupId = existingDetails.TargetResourceGroupId - } - - if metadata.ResourceData.HasChange("target_availability_set_id") { - updateInput.TargetAvailabilitySetId = targetAvailabilitySetID - } else { - updateInput.TargetAvailabilitySetId = existingDetails.TargetAvailabilitySetId - } - - if metadata.ResourceData.HasChange("target_zone") { - updateInput.TargetAvailabilityZone = targetAvailabilityZone - } else { - updateInput.TargetAvailabilityZone = existingDetails.TargetAvailabilityZone - } - - if metadata.ResourceData.HasChange("target_network_id") { - updateInput.TargetNetworkId = &model.TargetNetworkId - } else { - updateInput.TargetNetworkId = existingDetails.TargetNetworkId - } - - if metadata.ResourceData.HasChange("target_proximity_placement_group_id") { - updateInput.TargetProximityPlacementGroupId = &model.TargetProximityPlacementGroupId - } else { - updateInput.TargetProximityPlacementGroupId = existingDetails.TargetProximityPlacementGroupId - } - - if metadata.ResourceData.HasChange("target_boot_diagnostics_storage_account_id") { - updateInput.TargetBootDiagnosticsStorageAccountId = &model.TargetBootDiagnosticsStorageAccountId - } else { - updateInput.TargetBootDiagnosticsStorageAccountId = existingDetails.TargetBootDiagnosticsStorageAccountId - } - - props := replicationprotecteditems.UpdateReplicationProtectedItemInputProperties{ - ProviderSpecificDetails: updateInput, - } - - if metadata.ResourceData.HasChange("target_vm_name") { - props.RecoveryAzureVMName = &model.TargetVmName - } else { - props.RecoveryAzureVMName = existingDetails.TargetVMName - } - - if metadata.ResourceData.HasChange("target_network_id") { - props.SelectedRecoveryAzureNetworkId = &model.TargetNetworkId - } else { - props.SelectedRecoveryAzureNetworkId = existingDetails.TargetNetworkId - } - - if metadata.ResourceData.HasChange("target_availability_set_id") { - props.RecoveryAvailabilitySetId = targetAvailabilitySetID - } else { - props.RecoveryAvailabilitySetId = existingDetails.TargetAvailabilitySetId - } - - if metadata.ResourceData.HasChange("target_vm_size") { - props.RecoveryAzureVMSize = &model.TargetVmSize - } else { - props.RecoveryAzureVMSize = existingDetails.TargetVMSize - } - - parameters := replicationprotecteditems.UpdateReplicationProtectedItemInput{ - Properties: &props, - } - - err = client.UpdateThenPoll(ctx, id, parameters) - if err != nil { - return fmt.Errorf("updating %q: %+v", id, err) - } - - return nil -} - -func waitForVmwareReplicationToBeHealthy(ctx context.Context, metadata sdk.ResourceMetaData) (*replicationprotecteditems.ReplicationProtectedItem, error) { - stateConf := &pluginsdk.StateChangeConf{ - Target: []string{"Protected", "normal"}, - Refresh: waitForVmwareClassicReplicationToBeHealthyRefreshFunc(ctx, metadata), - PollInterval: time.Minute, - } - - deadline, ok := ctx.Deadline() - if !ok { - return nil, fmt.Errorf("context had no deadline") - } - stateConf.Timeout = time.Until(deadline) - - result, err := stateConf.WaitForStateContext(ctx) - if err != nil { - return nil, fmt.Errorf("waiting for site recovery to replicate vm: %+v", err) - } - - protectedItem, ok := result.(replicationprotecteditems.ReplicationProtectedItem) - if ok { - return &protectedItem, nil - } else { - return nil, fmt.Errorf("waiting for site recovery return incompatible type") - } -} - -func waitForVmwareClassicReplicationToBeHealthyRefreshFunc(ctx context.Context, metadata sdk.ResourceMetaData) pluginsdk.StateRefreshFunc { - return func() (interface{}, string, error) { - id, err := replicationprotecteditems.ParseReplicationProtectedItemID(metadata.ResourceData.Id()) - if err != nil { - return nil, "", err - } - - client := metadata.Client.RecoveryServices.ReplicationProtectedItemsClient - - resp, err := client.Get(ctx, *id) - if err != nil { - return nil, "", fmt.Errorf("making Read request on site recovery replicated vm Vmware Classic %s : %+v", id.String(), err) - } - - if resp.Model == nil { - return nil, "", fmt.Errorf("Missing Model in response when making Read request on site recovery replicated vm Vmware Classic %s %+v", id.String(), err) - } - - if resp.Model.Properties == nil { - return nil, "", fmt.Errorf("Missing Properties in response when making Read request on site recovery replicated vm Vmware Classic %s %+v", id.String(), err) - } - - if resp.Model.Properties.ProviderSpecificDetails == nil { - return nil, "", fmt.Errorf("missing Properties.ProviderSpecificDetails in response when making Read request on site recovery replicated vm Vmware Classic %s : %+v", id.String(), err) - } - - // Find first disk that is not fully replicated yet - if resp.Model.Properties.ProtectionState == nil { - return nil, "", fmt.Errorf("missing ProtectionState in response when making Read request on site recovery replicated vm Vmware Classic %s : %+v", id.String(), err) - } - return *resp.Model, *resp.Model.Properties.ProtectionState, nil - } -} - -func fetchSiteRecoveryReplicatedVmVMWareContainerId(ctx context.Context, containerClient *replicationprotectioncontainers.ReplicationProtectionContainersClient, vaultId string) (string, error) { +func fetchSiteRecoveryContainerId(ctx context.Context, containerClient *replicationprotectioncontainers.ReplicationProtectionContainersClient, vaultId string) (string, error) { vId, err := replicationprotectioncontainers.ParseVaultID(vaultId) if err != nil { return "", fmt.Errorf("parse %s: %+v", vaultId, err) @@ -1035,7 +935,7 @@ func fetchRunAsAccountsIdBySite(ctx context.Context, runAsAccountClient *vmwarer } } - return "", fmt.Errorf("retiring %q: run as account %s not found", siteId, displayName) + return "", fmt.Errorf("retrieving %q: run as account %s not found", siteId, displayName) } func fetchProcessServerIdByName(ctx context.Context, fabricClient *replicationfabrics.ReplicationFabricsClient, fabricId replicationfabrics.ReplicationFabricId, processServerName string) (string, error) { @@ -1045,29 +945,29 @@ func fetchProcessServerIdByName(ctx context.Context, fabricClient *replicationfa } if resp.Model == nil { - return "", fmt.Errorf("retiring %q: Model is nil", fabricId) + return "", fmt.Errorf("retrieving %q: Model is nil", fabricId) } if resp.Model.Properties == nil { - return "", fmt.Errorf("retiring %q: Properties is nil", fabricId) + return "", fmt.Errorf("retrieving %q: Properties is nil", fabricId) } if resp.Model.Properties.CustomDetails == nil { - return "", fmt.Errorf("retiring %q: CustomDetails is nil", fabricId) + return "", fmt.Errorf("retrieving %q: CustomDetails is nil", fabricId) } if detail, ok := resp.Model.Properties.CustomDetails.(replicationfabrics.InMageRcmFabricSpecificDetails); ok { - if detail.ProcessServers == nil || len(*detail.ProcessServers) < 1 { - return "", fmt.Errorf("retiring %q: count of Process Servers is 0", fabricId) + if detail.ProcessServers == nil { + return "", fmt.Errorf("retrieving %q: ProcessServers is nil", fabricId) } for _, server := range *detail.ProcessServers { if strings.EqualFold(*server.Name, processServerName) { return *server.Id, nil } } - return "", fmt.Errorf("retiring %q: process server %s not found", fabricId, processServerName) + return "", fmt.Errorf("retrieving %q: process server %s not found", fabricId, processServerName) } - return "", fmt.Errorf("retiring %q: Detail Type mismatch", fabricId) + return "", fmt.Errorf("retrieving %q: Detail Type mismatch", fabricId) } func fetchDiscoveryMachineIdBySite(ctx context.Context, machinesClient *vmwaremachines.MachinesClient, siteId string, machineName string) (string, error) { @@ -1076,7 +976,8 @@ func fetchDiscoveryMachineIdBySite(ctx context.Context, machinesClient *vmwarema return "", fmt.Errorf("parse %s: %+v", siteId, err) } - resp, err := getAllVMWareMachinesInSite(ctx, machinesClient, *parsedSiteId, vmwaremachines.DefaultGetAllMachinesInSiteOperationOptions()) + hackedClient := azuresdkhacks.MachinesClient{Client: machinesClient.Client} + resp, err := hackedClient.GetAllVMWareMachinesInSite(ctx, *parsedSiteId, vmwaremachines.DefaultGetAllMachinesInSiteOperationOptions()) if err != nil { return "", err } @@ -1090,12 +991,16 @@ func fetchDiscoveryMachineIdBySite(ctx context.Context, machinesClient *vmwarema continue } if strings.EqualFold(*machine.Properties.DisplayName, machineName) { - return handleAzureSdkForGoBug2824(*machine.Id), nil + parsedMachineId, err := vmwaremachines.ParseVMwareSiteIDInsensitively(*machine.Id) + if err != nil { + return "", fmt.Errorf("parse %s: %+v", *machine.Id, err) + } + return parsedMachineId.ID(), nil } } } - return "", fmt.Errorf("retiring %q: machine %s not found", siteId, machineName) + return "", fmt.Errorf("retrieving %q: machine %s not found", siteId, machineName) } func fetchCredentialByRunAsAccountId(ctx context.Context, client *vmwarerunasaccounts.RunAsAccountsClient, id string) (string, error) { @@ -1110,95 +1015,58 @@ func fetchCredentialByRunAsAccountId(ctx context.Context, client *vmwarerunasacc } if resp.Model == nil { - return "", fmt.Errorf("retiring %q: Model was nil", id) + return "", fmt.Errorf("retrieving %q: Model was nil", id) } if resp.Model.Properties == nil { - return "", fmt.Errorf("retiring %q: Properties was nil", id) + return "", fmt.Errorf("retrieving %q: Properties was nil", id) } if resp.Model.Properties.DisplayName == nil { - return "", fmt.Errorf("retiring %q: DisplayName was nil", id) + return "", fmt.Errorf("retrieving %q: DisplayName was nil", id) } return *resp.Model.Properties.DisplayName, nil } -// workaround for https://github.com/hashicorp/go-azure-sdk/issues/492 -func getAllVMWareMachinesInSite(ctx context.Context, c *vmwaremachines.MachinesClient, id vmwaremachines.VMwareSiteId, options vmwaremachines.GetAllMachinesInSiteOperationOptions) (result vmwaremachines.GetAllMachinesInSiteOperationResponse, err error) { - opts := client.RequestOptions{ - ContentType: "application/json", - ExpectedStatusCodes: []int{ - http.StatusOK, - }, - HttpMethod: http.MethodGet, - Path: fmt.Sprintf("%s/machines", id.ID()), - OptionsObject: options, - } - - req, err := c.Client.NewRequest(ctx, opts) - if err != nil { - return - } - - return warpedExecutePaged(ctx, req) -} - -func warpedExecutePaged(ctx context.Context, req *client.Request) (result vmwaremachines.GetAllMachinesInSiteOperationResponse, err error) { - resp, err := req.ExecutePaged(ctx) - if resp != nil { - result.OData = resp.OData - result.HttpResponse = resp.Response - } - if err != nil { - return - } - - var values struct { - Values *[]vmwaremachines.VMwareMachine `json:"value"` - NextLink *string `json:"nextLink"` - } - - if err = resp.Unmarshal(&values); err != nil { - return - } - result.Model = values.Values - - if values.NextLink != nil { - nextReq := req - u, err := url.Parse(*values.NextLink) - if err != nil { - return result, err - } - nextReq.URL = u - nextResp, err := warpedExecutePaged(ctx, nextReq) - if err != nil { - return result, err - } - if nextResp.Model != nil { - result.Model = pointer.To(append(*result.Model, *nextResp.Model...)) - } - } - - return -} - func fetchVmwareSiteIdByFabric(ctx context.Context, fabricClient *replicationfabrics.ReplicationFabricsClient, fabricId replicationfabrics.ReplicationFabricId) (string, error) { resp, err := fabricClient.Get(ctx, fabricId, replicationfabrics.DefaultGetOperationOptions()) if err != nil { return "", err } if resp.Model == nil { - return "", fmt.Errorf("retiring %q: Model is nil", fabricId) + return "", fmt.Errorf("retrieving %q: Model is nil", fabricId) } if resp.Model.Properties == nil { - return "", fmt.Errorf("retiring %q: Properties is nil", fabricId) + return "", fmt.Errorf("retrieving %q: Properties is nil", fabricId) } if v, ok := resp.Model.Properties.CustomDetails.(replicationfabrics.InMageRcmFabricSpecificDetails); ok { if v.VMwareSiteId == nil { - return "", fmt.Errorf("retiring %q: VMwareSiteId is nil", fabricId) + return "", fmt.Errorf("retrieving %q: VMwareSiteId is nil", fabricId) } return *v.VMwareSiteId, nil } - return "", fmt.Errorf("retiring %q: Detail Type mismatch", fabricId) + return "", fmt.Errorf("retrieving %q: Detail Type mismatch", fabricId) +} + +func expandVMWareReplicatedVMNics(input []NetworkInterfaceModel) []replicationprotecteditems.InMageRcmNicInput { + vmNics := make([]replicationprotecteditems.InMageRcmNicInput, 0) + for _, nic := range input { + vmNic := replicationprotecteditems.InMageRcmNicInput{ + NicId: nic.SourceMacAddress, + TargetSubnetName: &nic.TargetSubnetName, + } + if nic.TargetStaticIp != "" { + vmNic.TargetStaticIPAddress = &nic.TargetStaticIp + } + if nic.IsPrimary { + vmNic.IsPrimaryNic = strconv.FormatBool(true) + vmNic.IsSelectedForFailover = utils.String("true") + } else { + vmNic.IsPrimaryNic = strconv.FormatBool(false) + vmNic.IsSelectedForFailover = utils.String("false") + } + vmNics = append(vmNics, vmNic) + } + return vmNics } diff --git a/internal/services/recoveryservices/site_recovery_vmware_replicated_vm_resource_test.go b/internal/services/recoveryservices/site_recovery_vmware_replicated_vm_resource_test.go index f202f89a4b25..d3d8e709275b 100644 --- a/internal/services/recoveryservices/site_recovery_vmware_replicated_vm_resource_test.go +++ b/internal/services/recoveryservices/site_recovery_vmware_replicated_vm_resource_test.go @@ -6,6 +6,7 @@ import ( "os" "testing" + "github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservices/2022-10-01/vaults" "github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2022-10-01/replicationprotecteditems" "github.com/hashicorp/terraform-provider-azurerm/internal/acceptance" "github.com/hashicorp/terraform-provider-azurerm/internal/acceptance/check" @@ -14,8 +15,53 @@ import ( "github.com/hashicorp/terraform-provider-azurerm/utils" ) -type SiteRecoveryVMWareReplicatedVmResource struct{} +type SiteRecoveryVMWareReplicatedVmResource struct { + VaultName string + VaultRgName string + SourceVMName string + ApplianceName string + Location string + Credential string + SourceMacAddress string +} + +func (r SiteRecoveryVMWareReplicatedVmResource) preCheck(t *testing.T) { + if r.VaultRgName == "" || r.VaultName == "" { + t.Skipf("`ARM_TEST_VMWARE_VAULT_ID` must be set for acceptance tests!") + } + if r.SourceVMName == "" { + t.Skipf("`ARM_TEST_VMWARE_SOURCE_VM_NAME` must be set for acceptance tests!") + } + if r.ApplianceName == "" { + t.Skipf("`ARM_TEST_VMWARE_APPLIANCE_NAME` must be set for acceptance tests!") + } + if r.Location == "" { + t.Skipf("`ARM_TEST_VMWARE_VAULT_LOCATION` must be set for acceptance tests!") + } + if r.Credential == "" { + t.Skipf("`ARM_TEST_VMWARE_CREDENTIAL_NAME` must be set for acceptance tests!") + } + if r.SourceMacAddress == "" { + t.Skipf("`ARM_TEST_VMWARE_SOURCE_MAC_ADDRESS` must be set for acceptance tests!") + } +} +func newSiteRecoveryVMWareReplicatedVMResource(vaultId, sourceVMName, applianceName, location, credential, sourceMacAddress string) (SiteRecoveryVMWareReplicatedVmResource, error) { + parsedVaultId, err := vaults.ParseVaultID(vaultId) + if err != nil { + return SiteRecoveryVMWareReplicatedVmResource{}, fmt.Errorf("parse vault id: %+v", err) + } + return SiteRecoveryVMWareReplicatedVmResource{ + VaultName: parsedVaultId.VaultName, + VaultRgName: parsedVaultId.ResourceGroupName, + SourceVMName: sourceVMName, + ApplianceName: applianceName, + Location: location, + Credential: credential, + SourceMacAddress: sourceMacAddress, + }, nil + +} func (r SiteRecoveryVMWareReplicatedVmResource) Exists(ctx context.Context, clients *clients.Client, state *pluginsdk.InstanceState) (*bool, error) { id, err := replicationprotecteditems.ParseReplicationProtectedItemID(state.ID) if err != nil { @@ -32,24 +78,22 @@ func (r SiteRecoveryVMWareReplicatedVmResource) Exists(ctx context.Context, clie func TestAccSiteVMWareRecoveryReplicatedVM_basic(t *testing.T) { data := acceptance.BuildTestData(t, "azurerm_site_recovery_vmware_replicated_vm", "test") - r := SiteRecoveryVMWareReplicatedVmResource{} - - vaultId := os.Getenv("ARM_TEST_VMWARE_VAULT_ID") - sourceVMName := os.Getenv("ARM_TEST_VMWARE_SOURCE_VM_NAME") - applianceName := os.Getenv("ARM_TEST_VMWARE_APPLIANCE_NAME") - location := os.Getenv("ARM_TEST_VMWARE_VAULT_LOCATION") - credential := os.Getenv("ARM_TEST_VMWARE_CREDENTIAL_NAME") - - if vaultId == "" || sourceVMName == "" || applianceName == "" || location == "" || credential == "" { - t.Skip("Skipping since ARM_TEST_VMWARE_VAULT_ID, ARM_TEST_VMWARE_SOURCE_VM_NAME, ARM_TEST_VMWARE_LOCATION, ARM_TEST_VMWARE_CREDENTIAL_NAME and ARM_TEST_VMWARE_APPLIANCE_NAME are not specified") - return + r, err := newSiteRecoveryVMWareReplicatedVMResource( + os.Getenv("ARM_TEST_VMWARE_VAULT_ID"), + os.Getenv("ARM_TEST_VMWARE_SOURCE_VM_NAME"), + os.Getenv("ARM_TEST_VMWARE_APPLIANCE_NAME"), + os.Getenv("ARM_TEST_VMWARE_VAULT_LOCATION"), + os.Getenv("ARM_TEST_VMWARE_CREDENTIAL_NAME"), + os.Getenv("ARM_TEST_VMWARE_SOURCE_MAC_ADDRESS"), + ) + if err != nil { + t.Fatal(fmt.Errorf("build SiteRecoveryVMWareReplicatedVmResource: %+v", err)) } - - data.Locations.Primary = location + r.preCheck(t) data.ResourceTest(t, r, []acceptance.TestStep{ { - Config: r.basic(data, vaultId, sourceVMName, applianceName, credential), + Config: r.basic(data), Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), ), @@ -58,7 +102,7 @@ func TestAccSiteVMWareRecoveryReplicatedVM_basic(t *testing.T) { }) } -func (SiteRecoveryVMWareReplicatedVmResource) basic(data acceptance.TestData, vaultId, sourceVMName, applianceName, credential string) string { +func (r SiteRecoveryVMWareReplicatedVmResource) basic(data acceptance.TestData) string { return fmt.Sprintf(` provider "azurerm" { features { @@ -68,26 +112,31 @@ provider "azurerm" { } } +data "azurerm_recovery_services_vault" "vault" { + name = "%[1]s" + resource_group_name = "%[2]s" +} + resource "azurerm_site_recovery_vmware_replication_policy" "test" { - recovery_vault_id = "%[1]s" - name = "acctest-policy-%[2]d" + recovery_vault_id = data.azurerm_recovery_services_vault.vault.id + name = "acctest-policy-%[3]d" recovery_point_retention_in_minutes = 1440 application_consistent_snapshot_frequency_in_minutes = 240 } resource "azurerm_site_recovery_vmware_replication_policy_association" "test" { - name = "acctest-%[2]d" - recovery_vault_id = "%[1]s" + name = "acctest-%[3]d" + recovery_vault_id = data.azurerm_recovery_services_vault.vault.id policy_id = azurerm_site_recovery_vmware_replication_policy.test.id } resource "azurerm_resource_group" "target" { - name = "acctestRG-%[2]d" - location = "%[4]s" + name = "acctestRG-%[3]d" + location = "%[5]s" } resource "azurerm_storage_account" "target" { - name = "acct%[3]s" + name = "acct%[4]s" resource_group_name = azurerm_resource_group.target.name location = azurerm_resource_group.target.location account_tier = "Standard" @@ -95,7 +144,7 @@ resource "azurerm_storage_account" "target" { } resource "azurerm_virtual_network" "target" { - name = "acctestvn-%[2]d" + name = "acctestvn-%[3]d" address_space = ["10.0.0.0/16"] location = azurerm_resource_group.target.location resource_group_name = azurerm_resource_group.target.name @@ -110,15 +159,15 @@ resource "azurerm_subnet" "target" { resource "azurerm_site_recovery_vmware_replicated_vm" "test" { - name = "acct%[2]d" - recovery_vault_id = "%[1]s" - source_vm_name = "%[5]s" - appliance_name = "%[6]s" + name = "acct%[3]d" + recovery_vault_id = data.azurerm_recovery_services_vault.vault.id + source_vm_name = "%[6]s" + appliance_name = "%[7]s" recovery_replication_policy_id = azurerm_site_recovery_vmware_replication_policy_association.test.policy_id - physical_server_credential_name = "%[7]s" + physical_server_credential_name = "%[8]s" license_type = "NotSpecified" target_boot_diagnostics_storage_account_id = azurerm_storage_account.target.id - target_vm_name = "%[5]s" + target_vm_name = "%[6]s" target_resource_group_id = azurerm_resource_group.target.id default_log_storage_account_id = azurerm_storage_account.target.id default_recovery_disk_type = "Standard_LRS" @@ -143,5 +192,5 @@ resource "azurerm_site_recovery_vmware_replicated_vm" "test" { ] } } -`, vaultId, data.RandomInteger, data.RandomString, data.Locations.Primary, sourceVMName, applianceName, credential) +`, r.VaultName, r.VaultRgName, data.RandomInteger, data.RandomString, r.Location, r.SourceVMName, r.ApplianceName, r.Credential) } diff --git a/website/docs/r/site_recovery_vmware_replicated_vm.html.markdown b/website/docs/r/site_recovery_vmware_replicated_vm.html.markdown index 3cf687af6813..c3ab9249a300 100644 --- a/website/docs/r/site_recovery_vmware_replicated_vm.html.markdown +++ b/website/docs/r/site_recovery_vmware_replicated_vm.html.markdown @@ -3,12 +3,12 @@ subcategory: "Recovery Services" layout: "azurerm" page_title: "Azure Resource Manager: azurerm_site_recovery_vmware_replicated_vm" description: |- - Manages a VMWare VM protected with Azure Site Recovery on Azure. + Manages a VMWare replicated VM protected with Azure Site Recovery on Azure. --- # azurerm_site_recovery_vmware_replicated_vm -Manages a VMWare VM replicated using Azure Site Recovery (VMWare to Azure only). A replicated VM keeps a copiously updated image of the VM in Azure in order to be able to start the VM in Azure in case of a disaster. +Manages a VMWare replicated VM using Azure Site Recovery (VMWare to Azure only). A replicated VM keeps a copiously updated image of the VM in Azure in order to be able to start the VM in Azure in case of a disaster. ## Example Usage @@ -35,7 +35,7 @@ resource "azurerm_site_recovery_vmware_replication_policy" "example" { resource "azurerm_site_recovery_vmware_replication_policy_association" "test" { name = "example-association" recovery_vault_id = azurerm_recovery_services_vault.example.id - policy_id = azurerm_site_recovery_hyperv_replication_policy.example.id + policy_id = azurerm_site_recovery_vmware_replication_policy.example.id } resource "azurerm_storage_account" "example" { @@ -89,8 +89,6 @@ resource "azurerm_site_recovery_vmware_replicated_vm" "example" { target_subnet_name = azurerm_subnet.example.name is_primary = true } - - depends_on = [azurerm_site_recovery_vmware_replication_policy_association.example] } ``` @@ -98,19 +96,19 @@ resource "azurerm_site_recovery_vmware_replicated_vm" "example" { The following arguments are supported: +* `appliance_name` - (Required) The name of VMWare appliance which handles the replication. Changing this forces a new resource to be created. + * `name` - (Required) The name of the replicated VM. Changing this forces a new resource to be created. * `recovery_vault_id` - (Required) The ID of the Recovery Services Vault where the replicated VM is created. Changing this forces a new resource to be created. -* `source_vm_name` - (Required) The name of the source VM in VMWare. Changing this forces a new resource to be created. +* `network_interface` - (Required) One or more `network_interface` block as defined below. -* `appliance_name` - (Required) The name of VMWare appliance which handles the replication. Changing this forces a new resource to be created. +* `physical_server_credential_name` - (Required) The name of the credential to access the source VM. Changing this forces a new resource to be created. More information about the credentials could be found [here](https://learn.microsoft.com/en-us/azure/site-recovery/deploy-vmware-azure-replication-appliance-modernized). * `recovery_replication_policy_id` - (Required) The ID of the policy to use for this replicated VM. Changing this forces a new resource to be created. -* `physical_server_credential_name` - (Required) The name of credential to access source VM. Changing this forces a new resource to be created. More information about the credentials could be found [here](https://learn.microsoft.com/en-us/azure/site-recovery/deploy-vmware-azure-replication-appliance-modernized). - -* `license_type` - (Optional) The license type of the VM. Possible values are `NoLicenseType`, `NotSpecified` and `WindowsServer`. Defaults to `NotSpecified`. +* `source_vm_name` - (Required) The name of the source VM in VMWare. Changing this forces a new resource to be created. * `target_resource_group_id` - (Required) The ID of resource group where the VM should be created when a failover is done. Changing this forces a new resource to be created. @@ -118,51 +116,53 @@ The following arguments are supported: * `default_log_storage_account_id` - (Optional) The ID of the stroage account that should be used for logging during replication. -**Note:** Only standard types of stroage accounts are allowed. +**Note:** Only standard types of storage accounts are allowed. -**Note:** At least one of `default_log_storage_account_id` or `managed_disk` must be specified. +**Note:** Only one of `default_log_storage_account_id` or `managed_disk` must be specified. **Note:** Changing `default_log_storage_account_id` forces a new resource to be created. But removing it does not. -* `default_recovery_disk_type` - (Optional) The type of storage account that should be used for recovery disks when a failover is done. Possible values are `Standard_LRS`, `Standard_LRS` and `StandardSSD_LRS`. +**Note:** When `default_log_storage_account_id` co-exist with `managed_disk`, the value of `default_log_storage_account_id` must be as same as `log_storage_account_id` of every `managed_disk` or it forces a new resource to be created. -**Note:** At least one of `default_recovery_disk_type` or `managed_disk` must be specified. +* `default_target_disk_encryption_set_id` - (Optional) The ID of the default Disk Encryption Set that should be used for the disks when a failover is done. -**Note:** Changing `default_recovery_disk_type` forces a new resource to be created. But removing it does not. +**Note:** Only one of `default_target_disk_encryption_set_id` or `managed_disk` can be specified. -* `target_network_id` - (Optional) The ID of network to use when a failover is done. +**Note:** Changing `default_target_disk_encryption_set_id` forces a new resource to be created. But removing it does not. -* `target_subnet_name` - (Optional) Name of the subnet to use when a failover is done. +**Note:** When `default_target_disk_encryption_set_id` co-exist with `managed_disk`, the value of `default_target_disk_encryption_set_id` must be as same as `target_disk_encryption_set_id` of every `managed_disk` or it forces a new resource to be created. -* `test_network_id` - (Optional) The ID of network to use when a test failover is done. +* `default_recovery_disk_type` - (Optional) The type of storage account that should be used for recovery disks when a failover is done. Possible values are `Standard_LRS`, `Standard_LRS` and `StandardSSD_LRS`. -* `test_subnet_name` - (Optional) Name of the subnet to use when a failover is done. +**Note:** Only one of `default_recovery_disk_type` or `managed_disk` must be specified. -* `multi_vm_group_name` - (Optional) Name of group in which all machines will replicate together and have shared crash consistent and app-consistent recovery points when failed over. Changing this forces a new resource to be created. +**Note:** Changing `default_recovery_disk_type` forces a new resource to be created. But removing it does not. -* `target_proximity_placement_group_id` - (Optional) The ID of Proximity Placement Group the new VM should belong to when a failover is done. +**Note:** When `default_recovery_disk_type` co-exist with `managed_disk`, the value of `default_recovery_disk_type` must be as same as `target_disk_type` of every `managed_disk` or it forces a new resource to be created. -* `target_availability_set_id` - (Optional) The ID of availability set that the new VM should belong to when a failover is done. Changing this forces a new resource to be created. +* `license_type` - (Optional) The license type of the VM. Possible values are `NoLicenseType`, `NotSpecified` and `WindowsServer`. Defaults to `NotSpecified`. -**Note:** Only one of `target_availability_set_id` or `target_zone` can be specified. +* `multi_vm_group_name` - (Optional) Name of group in which all machines will replicate together and have shared crash consistent and app-consistent recovery points when failed over. Changing this forces a new resource to be created. -* `target_vm_size` - (Optional) Size of the VM that should be created when a failover is done, such as `Standard_F2`. If it's not specified, it will automatically be set by detecting the source VM size. +* `managed_disk` - (Optional) One or more `managed_disk` block as defined below. It's available only if mobility service is already installed on the source VM. -* `target_zone` - (Optional) Specifies the Availability Zone where the Failover VM should exist. +**Note:** a replicated VM could be created without `managed_disk` block, once it has been specified, changing it forces a new resource to be created. -* `default_target_disk_encryption_set_id` - (Optional) The ID of the default Disk Encryption Set that should be used for the disks when a failover is done. +* `target_boot_diagnostics_storage_account_id` - (Optional) The ID of the storage account that should be used for boot diagnostics when a failover is done. -**Note:** Only one of `default_target_disk_encryption_set_id` or `managed_disk` can be specified. +* `target_network_id` - (Optional) The ID of network to use when a failover is done. -**Note:** Changing `default_target_disk_encryption_set_id` forces a new resource to be created. But removing it does not. +* `test_network_id` - (Optional) The ID of network to use when a test failover is done. -* `target_boot_diagnostics_storage_account_id` - (Optional) The ID of the storage account that should be used for boot diagnostics when a failover is done. +* `target_proximity_placement_group_id` - (Optional) The ID of Proximity Placement Group the new VM should belong to when a failover is done. -* `managed_disk` - (Optional) One or more `managed_disk` block as defined below. It's available only if mobility service is already installed on the source VM. +* `target_availability_set_id` - (Optional) The ID of availability set that the new VM should belong to when a failover is done. Changing this forces a new resource to be created. -**Note:** a replicated VM could be created without `managed_disk` block, once it has been specified, changing it forces a new resource to be created. +**Note:** Only one of `target_availability_set_id` or `target_zone` can be specified. -* `network_interface` - (Required) One or more `network_interface` block as defined below. +* `target_zone` - (Optional) Specifies the Availability Zone where the Failover VM should exist. + +* `target_vm_size` - (Optional) Size of the VM that should be created when a failover is done, such as `Standard_F2`. If it's not specified, it will automatically be set by detecting the source VM size. --- @@ -180,9 +180,9 @@ A `managed_disk` block supports the following: A `network_interface` block supports the following: -* `source_mac_address` - (Optional) Mac address of the network interface of source VM. +* `source_mac_address` - (Required) Mac address of the network interface of source VM. --> **NOTE:** `source_mac_address` could be left blank in creation only if there is exactly one network interface on the source VM. +* `is_primary` - (Required) Whether this `network_interface` is primary for the replicated VM. * `target_static_ip` - (Optional) Static IP to assign when a failover is done. @@ -190,8 +190,6 @@ A `network_interface` block supports the following: * `test_subnet_name` - (Optional) Name of the subnet to use when a test failover is done. -* `is_primary` - (Required) Whether this `network_interface` is primary for the replicated VM. - ## Attributes Reference In addition to the arguments above, the following attributes are exported: From a4d591703c57269754d11da6f2e0960b6d2ce058 Mon Sep 17 00:00:00 2001 From: ziyeqf <51212351+ziyeqf@users.noreply.github.com> Date: Mon, 17 Jul 2023 17:24:44 +0800 Subject: [PATCH 08/15] add comments Signed-off-by: ziyeqf <51212351+ziyeqf@users.noreply.github.com> --- .../site_recovery_vmware_replicated_vm_resource.go | 4 +++- .../docs/r/site_recovery_vmware_replicated_vm.html.markdown | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/internal/services/recoveryservices/site_recovery_vmware_replicated_vm_resource.go b/internal/services/recoveryservices/site_recovery_vmware_replicated_vm_resource.go index 3b2db587db2a..ca17819ff8be 100644 --- a/internal/services/recoveryservices/site_recovery_vmware_replicated_vm_resource.go +++ b/internal/services/recoveryservices/site_recovery_vmware_replicated_vm_resource.go @@ -514,7 +514,8 @@ func (s VMWareReplicatedVmResource) Create() sdk.ResourceFunc { if err != nil { return fmt.Errorf("creating %q: %+v", id, err) } - metadata.SetID(id) // once the PUT request returned successfully, an item has been created, even if it may fail in the poll process. + // once the PUT request returned successfully, an item has been created, even if it may fail in the poll process. + metadata.SetID(id) err = poller.Poller.PollUntilDone() if err != nil { @@ -529,6 +530,7 @@ func (s VMWareReplicatedVmResource) Create() sdk.ResourceFunc { return fmt.Errorf("waiting for %s to be fully protected: %s", id, err) } + // it needs an additional update to set the network interface. updateInput := replicationprotecteditems.UpdateReplicationProtectedItemInput{ Properties: &replicationprotecteditems.UpdateReplicationProtectedItemInputProperties{ RecoveryAvailabilitySetId: providerSpecificDetail.TargetAvailabilitySetId, diff --git a/website/docs/r/site_recovery_vmware_replicated_vm.html.markdown b/website/docs/r/site_recovery_vmware_replicated_vm.html.markdown index c3ab9249a300..c2d54542e593 100644 --- a/website/docs/r/site_recovery_vmware_replicated_vm.html.markdown +++ b/website/docs/r/site_recovery_vmware_replicated_vm.html.markdown @@ -146,7 +146,7 @@ The following arguments are supported: * `managed_disk` - (Optional) One or more `managed_disk` block as defined below. It's available only if mobility service is already installed on the source VM. -**Note:** a replicated VM could be created without `managed_disk` block, once it has been specified, changing it forces a new resource to be created. +**Note:** a replicated VM could be created without `managed_disk` block, once the block has been specified, changing it expect removing it forces a new resource to be created.. * `target_boot_diagnostics_storage_account_id` - (Optional) The ID of the storage account that should be used for boot diagnostics when a failover is done. From 50d0d376d569a064c3e2bb2a62a2853c970ad31e Mon Sep 17 00:00:00 2001 From: ziyeqf <51212351+ziyeqf@users.noreply.github.com> Date: Mon, 17 Jul 2023 17:25:57 +0800 Subject: [PATCH 09/15] replace `utils.String` to `pointer.To` Signed-off-by: ziyeqf <51212351+ziyeqf@users.noreply.github.com> --- .../site_recovery_vmware_replicated_vm_resource.go | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/internal/services/recoveryservices/site_recovery_vmware_replicated_vm_resource.go b/internal/services/recoveryservices/site_recovery_vmware_replicated_vm_resource.go index ca17819ff8be..a32390c1ae2f 100644 --- a/internal/services/recoveryservices/site_recovery_vmware_replicated_vm_resource.go +++ b/internal/services/recoveryservices/site_recovery_vmware_replicated_vm_resource.go @@ -33,7 +33,6 @@ 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 IncludedDiskModel struct { @@ -1063,10 +1062,10 @@ func expandVMWareReplicatedVMNics(input []NetworkInterfaceModel) []replicationpr } if nic.IsPrimary { vmNic.IsPrimaryNic = strconv.FormatBool(true) - vmNic.IsSelectedForFailover = utils.String("true") + vmNic.IsSelectedForFailover = pointer.To("true") } else { vmNic.IsPrimaryNic = strconv.FormatBool(false) - vmNic.IsSelectedForFailover = utils.String("false") + vmNic.IsSelectedForFailover = pointer.To("false") } vmNics = append(vmNics, vmNic) } From 66daad31adac273acfba892db03dcfe9f6d5e305 Mon Sep 17 00:00:00 2001 From: ziyeqf <51212351+ziyeqf@users.noreply.github.com> Date: Mon, 17 Jul 2023 22:40:18 +0800 Subject: [PATCH 10/15] schema lint Signed-off-by: ziyeqf <51212351+ziyeqf@users.noreply.github.com> --- .../site_recovery_vmware_replicated_vm_resource.go | 5 +---- .../docs/r/site_recovery_vmware_replicated_vm.html.markdown | 4 ++-- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/internal/services/recoveryservices/site_recovery_vmware_replicated_vm_resource.go b/internal/services/recoveryservices/site_recovery_vmware_replicated_vm_resource.go index a32390c1ae2f..bf3e0b31f39e 100644 --- a/internal/services/recoveryservices/site_recovery_vmware_replicated_vm_resource.go +++ b/internal/services/recoveryservices/site_recovery_vmware_replicated_vm_resource.go @@ -216,11 +216,8 @@ func (s VMWareReplicatedVmResource) Arguments() map[string]*pluginsdk.Schema { "target_network_id": { Type: pluginsdk.TypeString, - Optional: true, + Required: true, ValidateFunc: commonids.ValidateVirtualNetworkID, - RequiredWith: []string{ - "network_interface", - }, }, "test_network_id": { diff --git a/website/docs/r/site_recovery_vmware_replicated_vm.html.markdown b/website/docs/r/site_recovery_vmware_replicated_vm.html.markdown index c2d54542e593..58978f2bff5a 100644 --- a/website/docs/r/site_recovery_vmware_replicated_vm.html.markdown +++ b/website/docs/r/site_recovery_vmware_replicated_vm.html.markdown @@ -114,6 +114,8 @@ The following arguments are supported: * `target_vm_name` - (Required) Name of the VM that should be created when a failover is done. Changing this forces a new resource to be created. +* `target_network_id` - (Required) The ID of network to use when a failover is done. + * `default_log_storage_account_id` - (Optional) The ID of the stroage account that should be used for logging during replication. **Note:** Only standard types of storage accounts are allowed. @@ -150,8 +152,6 @@ The following arguments are supported: * `target_boot_diagnostics_storage_account_id` - (Optional) The ID of the storage account that should be used for boot diagnostics when a failover is done. -* `target_network_id` - (Optional) The ID of network to use when a failover is done. - * `test_network_id` - (Optional) The ID of network to use when a test failover is done. * `target_proximity_placement_group_id` - (Optional) The ID of Proximity Placement Group the new VM should belong to when a failover is done. From 3efd51385fb38fee9690bf6f290573991bafef95 Mon Sep 17 00:00:00 2001 From: ziyeqf <51212351+ziyeqf@users.noreply.github.com> Date: Tue, 18 Jul 2023 14:20:48 +0800 Subject: [PATCH 11/15] update test case Signed-off-by: ziyeqf <51212351+ziyeqf@users.noreply.github.com> --- ..._recovery_vmware_replicated_vm_resource.go | 10 ++-- ...very_vmware_replicated_vm_resource_test.go | 50 +++++++++++-------- ...ecovery_vmware_replicated_vm.html.markdown | 8 +-- 3 files changed, 39 insertions(+), 29 deletions(-) diff --git a/internal/services/recoveryservices/site_recovery_vmware_replicated_vm_resource.go b/internal/services/recoveryservices/site_recovery_vmware_replicated_vm_resource.go index bf3e0b31f39e..6e6052ebd0d2 100644 --- a/internal/services/recoveryservices/site_recovery_vmware_replicated_vm_resource.go +++ b/internal/services/recoveryservices/site_recovery_vmware_replicated_vm_resource.go @@ -216,8 +216,9 @@ func (s VMWareReplicatedVmResource) Arguments() map[string]*pluginsdk.Schema { "target_network_id": { Type: pluginsdk.TypeString, - Required: true, + Optional: true, ValidateFunc: commonids.ValidateVirtualNetworkID, + RequiredWith: []string{"network_interface"}, }, "test_network_id": { @@ -241,7 +242,7 @@ func (s VMWareReplicatedVmResource) Arguments() map[string]*pluginsdk.Schema { "network_interface": { Type: pluginsdk.TypeList, - Required: true, + Optional: true, Elem: resourceSiteRecoveryVMWareReplicatedVMNetworkInterfaceSchema(), }, } @@ -600,9 +601,6 @@ func (s VMWareReplicatedVmResource) Update() sdk.ResourceFunc { vmNics := make([]replicationprotecteditems.InMageRcmNicInput, 0) if metadata.ResourceData.HasChange("network_interface") { - if model.TargetNetworkId == "" && len(model.NetworkInterface) > 0 { - return fmt.Errorf("`target_network_id` must be set when a `network_interface` is configured") - } vmNics = expandVMWareReplicatedVMNics(model.NetworkInterface) } else { if existingDetails.VMNics == nil { @@ -989,7 +987,7 @@ func fetchDiscoveryMachineIdBySite(ctx context.Context, machinesClient *vmwarema continue } if strings.EqualFold(*machine.Properties.DisplayName, machineName) { - parsedMachineId, err := vmwaremachines.ParseVMwareSiteIDInsensitively(*machine.Id) + parsedMachineId, err := commonids.ParseVMwareSiteMachineIDInsensitively(*machine.Id) if err != nil { return "", fmt.Errorf("parse %s: %+v", *machine.Id, err) } diff --git a/internal/services/recoveryservices/site_recovery_vmware_replicated_vm_resource_test.go b/internal/services/recoveryservices/site_recovery_vmware_replicated_vm_resource_test.go index d3d8e709275b..2b227b59d1a9 100644 --- a/internal/services/recoveryservices/site_recovery_vmware_replicated_vm_resource_test.go +++ b/internal/services/recoveryservices/site_recovery_vmware_replicated_vm_resource_test.go @@ -6,7 +6,6 @@ import ( "os" "testing" - "github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservices/2022-10-01/vaults" "github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2022-10-01/replicationprotecteditems" "github.com/hashicorp/terraform-provider-azurerm/internal/acceptance" "github.com/hashicorp/terraform-provider-azurerm/internal/acceptance/check" @@ -16,6 +15,7 @@ import ( ) type SiteRecoveryVMWareReplicatedVmResource struct { + SubscriptionId string VaultName string VaultRgName string SourceVMName string @@ -26,8 +26,14 @@ type SiteRecoveryVMWareReplicatedVmResource struct { } func (r SiteRecoveryVMWareReplicatedVmResource) preCheck(t *testing.T) { - if r.VaultRgName == "" || r.VaultName == "" { - t.Skipf("`ARM_TEST_VMWARE_VAULT_ID` must be set for acceptance tests!") + if r.SubscriptionId == "" { + t.Skipf("subscription id is empty") + } + if r.VaultName == "" { + t.Skipf("vault name is empty") + } + if r.VaultRgName == "" { + t.Skipf("vault resource group name is empty") } if r.SourceVMName == "" { t.Skipf("`ARM_TEST_VMWARE_SOURCE_VM_NAME` must be set for acceptance tests!") @@ -47,11 +53,12 @@ func (r SiteRecoveryVMWareReplicatedVmResource) preCheck(t *testing.T) { } func newSiteRecoveryVMWareReplicatedVMResource(vaultId, sourceVMName, applianceName, location, credential, sourceMacAddress string) (SiteRecoveryVMWareReplicatedVmResource, error) { - parsedVaultId, err := vaults.ParseVaultID(vaultId) + parsedVaultId, err := replicationprotecteditems.ParseVaultID(vaultId) if err != nil { - return SiteRecoveryVMWareReplicatedVmResource{}, fmt.Errorf("parse vault id: %+v", err) + return SiteRecoveryVMWareReplicatedVmResource{}, fmt.Errorf("parsing %q: %+v", vaultId, err) } return SiteRecoveryVMWareReplicatedVmResource{ + SubscriptionId: parsedVaultId.SubscriptionId, VaultName: parsedVaultId.VaultName, VaultRgName: parsedVaultId.ResourceGroupName, SourceVMName: sourceVMName, @@ -87,8 +94,9 @@ func TestAccSiteVMWareRecoveryReplicatedVM_basic(t *testing.T) { os.Getenv("ARM_TEST_VMWARE_SOURCE_MAC_ADDRESS"), ) if err != nil { - t.Fatal(fmt.Errorf("build SiteRecoveryVMWareReplicatedVmResource: %+v", err)) + t.Skipf("failed to create SiteRecoveryVMWareReplicatedVmResource: %+v", err) } + r.preCheck(t) data.ResourceTest(t, r, []acceptance.TestStep{ @@ -105,6 +113,7 @@ func TestAccSiteVMWareRecoveryReplicatedVM_basic(t *testing.T) { func (r SiteRecoveryVMWareReplicatedVmResource) basic(data acceptance.TestData) string { return fmt.Sprintf(` provider "azurerm" { + subscription_id = "%[1]s" features { resource_group { prevent_deletion_if_contains_resources = false @@ -113,30 +122,30 @@ provider "azurerm" { } data "azurerm_recovery_services_vault" "vault" { - name = "%[1]s" - resource_group_name = "%[2]s" + name = "%[2]s" + resource_group_name = "%[3]s" } resource "azurerm_site_recovery_vmware_replication_policy" "test" { recovery_vault_id = data.azurerm_recovery_services_vault.vault.id - name = "acctest-policy-%[3]d" + name = "acctest-policy-%[4]d" recovery_point_retention_in_minutes = 1440 application_consistent_snapshot_frequency_in_minutes = 240 } resource "azurerm_site_recovery_vmware_replication_policy_association" "test" { - name = "acctest-%[3]d" + name = "acctest-%[4]d" recovery_vault_id = data.azurerm_recovery_services_vault.vault.id policy_id = azurerm_site_recovery_vmware_replication_policy.test.id } resource "azurerm_resource_group" "target" { - name = "acctestRG-%[3]d" - location = "%[5]s" + name = "acctestRG-%[4]d" + location = "%[6]s" } resource "azurerm_storage_account" "target" { - name = "acct%[4]s" + name = "acct%[5]s" resource_group_name = azurerm_resource_group.target.name location = azurerm_resource_group.target.location account_tier = "Standard" @@ -144,7 +153,7 @@ resource "azurerm_storage_account" "target" { } resource "azurerm_virtual_network" "target" { - name = "acctestvn-%[3]d" + name = "acctestvn-%[4]d" address_space = ["10.0.0.0/16"] location = azurerm_resource_group.target.location resource_group_name = azurerm_resource_group.target.name @@ -159,21 +168,22 @@ resource "azurerm_subnet" "target" { resource "azurerm_site_recovery_vmware_replicated_vm" "test" { - name = "acct%[3]d" + name = "acct%[4]d" recovery_vault_id = data.azurerm_recovery_services_vault.vault.id - source_vm_name = "%[6]s" - appliance_name = "%[7]s" + source_vm_name = "%[7]s" + appliance_name = "%[8]s" recovery_replication_policy_id = azurerm_site_recovery_vmware_replication_policy_association.test.policy_id - physical_server_credential_name = "%[8]s" + physical_server_credential_name = "%[9]s" license_type = "NotSpecified" target_boot_diagnostics_storage_account_id = azurerm_storage_account.target.id - target_vm_name = "%[6]s" + target_vm_name = "%[7]s" target_resource_group_id = azurerm_resource_group.target.id default_log_storage_account_id = azurerm_storage_account.target.id default_recovery_disk_type = "Standard_LRS" target_network_id = azurerm_virtual_network.target.id network_interface { + source_mac_address = "%[10]s" target_subnet_name = azurerm_subnet.target.name is_primary = true } @@ -192,5 +202,5 @@ resource "azurerm_site_recovery_vmware_replicated_vm" "test" { ] } } -`, r.VaultName, r.VaultRgName, data.RandomInteger, data.RandomString, r.Location, r.SourceVMName, r.ApplianceName, r.Credential) +`, r.SubscriptionId, r.VaultName, r.VaultRgName, data.RandomInteger, data.RandomString, r.Location, r.SourceVMName, r.ApplianceName, r.Credential, r.SourceMacAddress) } diff --git a/website/docs/r/site_recovery_vmware_replicated_vm.html.markdown b/website/docs/r/site_recovery_vmware_replicated_vm.html.markdown index 58978f2bff5a..5f8afb519913 100644 --- a/website/docs/r/site_recovery_vmware_replicated_vm.html.markdown +++ b/website/docs/r/site_recovery_vmware_replicated_vm.html.markdown @@ -102,8 +102,6 @@ The following arguments are supported: * `recovery_vault_id` - (Required) The ID of the Recovery Services Vault where the replicated VM is created. Changing this forces a new resource to be created. -* `network_interface` - (Required) One or more `network_interface` block as defined below. - * `physical_server_credential_name` - (Required) The name of the credential to access the source VM. Changing this forces a new resource to be created. More information about the credentials could be found [here](https://learn.microsoft.com/en-us/azure/site-recovery/deploy-vmware-azure-replication-appliance-modernized). * `recovery_replication_policy_id` - (Required) The ID of the policy to use for this replicated VM. Changing this forces a new resource to be created. @@ -114,7 +112,9 @@ The following arguments are supported: * `target_vm_name` - (Required) Name of the VM that should be created when a failover is done. Changing this forces a new resource to be created. -* `target_network_id` - (Required) The ID of network to use when a failover is done. +* `target_network_id` - (Optional) The ID of network to use when a failover is done. + +**Note:** `target_network_id` is required when `network_interface` is specified. * `default_log_storage_account_id` - (Optional) The ID of the stroage account that should be used for logging during replication. @@ -150,6 +150,8 @@ The following arguments are supported: **Note:** a replicated VM could be created without `managed_disk` block, once the block has been specified, changing it expect removing it forces a new resource to be created.. +* `network_interface` - (Optional) One or more `network_interface` block as defined below. + * `target_boot_diagnostics_storage_account_id` - (Optional) The ID of the storage account that should be used for boot diagnostics when a failover is done. * `test_network_id` - (Optional) The ID of network to use when a test failover is done. From 1b501828ccef2dc69377ff904690c40fbcd2de0f Mon Sep 17 00:00:00 2001 From: ziyeqf <51212351+ziyeqf@users.noreply.github.com> Date: Mon, 14 Aug 2023 14:52:16 +0800 Subject: [PATCH 12/15] refresh vendor Signed-off-by: ziyeqf <51212351+ziyeqf@users.noreply.github.com> --- .../resource-manager/migrate/2020-01-01/machines/client.go | 6 +++--- .../2020-01-01/machines/method_getallmachinesinsite.go | 2 +- .../migrate/2020-01-01/machines/method_getmachine.go | 2 +- .../migrate/2020-01-01/machines/method_startmachine.go | 2 +- .../migrate/2020-01-01/machines/method_stopmachine.go | 2 +- .../migrate/2020-01-01/machines/predicates.go | 6 +++--- .../migrate/2020-01-01/runasaccounts/client.go | 6 +++--- .../runasaccounts/method_getallrunasaccountsinsite.go | 2 +- .../2020-01-01/runasaccounts/method_getrunasaccount.go | 2 +- .../migrate/2020-01-01/runasaccounts/predicates.go | 6 +++--- 10 files changed, 18 insertions(+), 18 deletions(-) diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/migrate/2020-01-01/machines/client.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/migrate/2020-01-01/machines/client.go index 80e10f009c71..e0daf9080614 100644 --- a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/migrate/2020-01-01/machines/client.go +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/migrate/2020-01-01/machines/client.go @@ -4,7 +4,7 @@ import ( "fmt" "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" - "github.com/hashicorp/go-azure-sdk/sdk/environments" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" ) // Copyright (c) Microsoft Corporation. All rights reserved. @@ -14,8 +14,8 @@ type MachinesClient struct { Client *resourcemanager.Client } -func NewMachinesClientWithBaseURI(api environments.Api) (*MachinesClient, error) { - client, err := resourcemanager.NewResourceManagerClient(api, "machines", defaultApiVersion) +func NewMachinesClientWithBaseURI(sdkApi sdkEnv.Api) (*MachinesClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "machines", defaultApiVersion) if err != nil { return nil, fmt.Errorf("instantiating MachinesClient: %+v", err) } diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/migrate/2020-01-01/machines/method_getallmachinesinsite.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/migrate/2020-01-01/machines/method_getallmachinesinsite.go index cdfa5bcaf889..bfdcb2a30377 100644 --- a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/migrate/2020-01-01/machines/method_getallmachinesinsite.go +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/migrate/2020-01-01/machines/method_getallmachinesinsite.go @@ -64,7 +64,7 @@ func (o GetAllMachinesInSiteOperationOptions) ToQuery() *client.QueryParams { // GetAllMachinesInSite ... func (c MachinesClient) GetAllMachinesInSite(ctx context.Context, id VMwareSiteId, options GetAllMachinesInSiteOperationOptions) (result GetAllMachinesInSiteOperationResponse, err error) { opts := client.RequestOptions{ - ContentType: "application/json", + ContentType: "application/json; charset=utf-8", ExpectedStatusCodes: []int{ http.StatusOK, }, diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/migrate/2020-01-01/machines/method_getmachine.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/migrate/2020-01-01/machines/method_getmachine.go index 500d851642e6..471da6ef2296 100644 --- a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/migrate/2020-01-01/machines/method_getmachine.go +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/migrate/2020-01-01/machines/method_getmachine.go @@ -21,7 +21,7 @@ type GetMachineOperationResponse struct { // GetMachine ... func (c MachinesClient) GetMachine(ctx context.Context, id commonids.VMwareSiteMachineId) (result GetMachineOperationResponse, err error) { opts := client.RequestOptions{ - ContentType: "application/json", + ContentType: "application/json; charset=utf-8", ExpectedStatusCodes: []int{ http.StatusOK, }, diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/migrate/2020-01-01/machines/method_startmachine.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/migrate/2020-01-01/machines/method_startmachine.go index 56eeb9c4d933..737475e7a1e7 100644 --- a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/migrate/2020-01-01/machines/method_startmachine.go +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/migrate/2020-01-01/machines/method_startmachine.go @@ -21,7 +21,7 @@ type StartMachineOperationResponse struct { // StartMachine ... func (c MachinesClient) StartMachine(ctx context.Context, id commonids.VMwareSiteMachineId) (result StartMachineOperationResponse, err error) { opts := client.RequestOptions{ - ContentType: "application/json", + ContentType: "application/json; charset=utf-8", ExpectedStatusCodes: []int{ http.StatusAccepted, }, diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/migrate/2020-01-01/machines/method_stopmachine.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/migrate/2020-01-01/machines/method_stopmachine.go index de2580cd3b84..00f031985d4f 100644 --- a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/migrate/2020-01-01/machines/method_stopmachine.go +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/migrate/2020-01-01/machines/method_stopmachine.go @@ -21,7 +21,7 @@ type StopMachineOperationResponse struct { // StopMachine ... func (c MachinesClient) StopMachine(ctx context.Context, id commonids.VMwareSiteMachineId) (result StopMachineOperationResponse, err error) { opts := client.RequestOptions{ - ContentType: "application/json", + ContentType: "application/json; charset=utf-8", ExpectedStatusCodes: []int{ http.StatusAccepted, }, diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/migrate/2020-01-01/machines/predicates.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/migrate/2020-01-01/machines/predicates.go index 8b58b0f2f032..2b0d532f563f 100644 --- a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/migrate/2020-01-01/machines/predicates.go +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/migrate/2020-01-01/machines/predicates.go @@ -11,15 +11,15 @@ type VMwareMachineOperationPredicate struct { func (p VMwareMachineOperationPredicate) Matches(input VMwareMachine) bool { - if p.Id != nil && (input.Id == nil && *p.Id != *input.Id) { + if p.Id != nil && (input.Id == nil || *p.Id != *input.Id) { return false } - if p.Name != nil && (input.Name == nil && *p.Name != *input.Name) { + if p.Name != nil && (input.Name == nil || *p.Name != *input.Name) { return false } - if p.Type != nil && (input.Type == nil && *p.Type != *input.Type) { + if p.Type != nil && (input.Type == nil || *p.Type != *input.Type) { return false } diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/migrate/2020-01-01/runasaccounts/client.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/migrate/2020-01-01/runasaccounts/client.go index d117011f8e54..eec6adbe66f5 100644 --- a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/migrate/2020-01-01/runasaccounts/client.go +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/migrate/2020-01-01/runasaccounts/client.go @@ -4,7 +4,7 @@ import ( "fmt" "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" - "github.com/hashicorp/go-azure-sdk/sdk/environments" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" ) // Copyright (c) Microsoft Corporation. All rights reserved. @@ -14,8 +14,8 @@ type RunAsAccountsClient struct { Client *resourcemanager.Client } -func NewRunAsAccountsClientWithBaseURI(api environments.Api) (*RunAsAccountsClient, error) { - client, err := resourcemanager.NewResourceManagerClient(api, "runasaccounts", defaultApiVersion) +func NewRunAsAccountsClientWithBaseURI(sdkApi sdkEnv.Api) (*RunAsAccountsClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "runasaccounts", defaultApiVersion) if err != nil { return nil, fmt.Errorf("instantiating RunAsAccountsClient: %+v", err) } diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/migrate/2020-01-01/runasaccounts/method_getallrunasaccountsinsite.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/migrate/2020-01-01/runasaccounts/method_getallrunasaccountsinsite.go index bb7345b48a4e..f1fd349a96b3 100644 --- a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/migrate/2020-01-01/runasaccounts/method_getallrunasaccountsinsite.go +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/migrate/2020-01-01/runasaccounts/method_getallrunasaccountsinsite.go @@ -25,7 +25,7 @@ type GetAllRunAsAccountsInSiteCompleteResult struct { // GetAllRunAsAccountsInSite ... func (c RunAsAccountsClient) GetAllRunAsAccountsInSite(ctx context.Context, id VMwareSiteId) (result GetAllRunAsAccountsInSiteOperationResponse, err error) { opts := client.RequestOptions{ - ContentType: "application/json", + ContentType: "application/json; charset=utf-8", ExpectedStatusCodes: []int{ http.StatusOK, }, diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/migrate/2020-01-01/runasaccounts/method_getrunasaccount.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/migrate/2020-01-01/runasaccounts/method_getrunasaccount.go index 7acf449765c0..2d19d053dbcc 100644 --- a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/migrate/2020-01-01/runasaccounts/method_getrunasaccount.go +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/migrate/2020-01-01/runasaccounts/method_getrunasaccount.go @@ -21,7 +21,7 @@ type GetRunAsAccountOperationResponse struct { // GetRunAsAccount ... func (c RunAsAccountsClient) GetRunAsAccount(ctx context.Context, id commonids.VMwareSiteRunAsAccountId) (result GetRunAsAccountOperationResponse, err error) { opts := client.RequestOptions{ - ContentType: "application/json", + ContentType: "application/json; charset=utf-8", ExpectedStatusCodes: []int{ http.StatusOK, }, diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/migrate/2020-01-01/runasaccounts/predicates.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/migrate/2020-01-01/runasaccounts/predicates.go index d1a8b7a5cffb..69ec7fbed704 100644 --- a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/migrate/2020-01-01/runasaccounts/predicates.go +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/migrate/2020-01-01/runasaccounts/predicates.go @@ -11,15 +11,15 @@ type VMwareRunAsAccountOperationPredicate struct { func (p VMwareRunAsAccountOperationPredicate) Matches(input VMwareRunAsAccount) bool { - if p.Id != nil && (input.Id == nil && *p.Id != *input.Id) { + if p.Id != nil && (input.Id == nil || *p.Id != *input.Id) { return false } - if p.Name != nil && (input.Name == nil && *p.Name != *input.Name) { + if p.Name != nil && (input.Name == nil || *p.Name != *input.Name) { return false } - if p.Type != nil && (input.Type == nil && *p.Type != *input.Type) { + if p.Type != nil && (input.Type == nil || *p.Type != *input.Type) { return false } From 477090221521f6703e042908aebf1719b4bca882 Mon Sep 17 00:00:00 2001 From: ziyeqf <51212351+ziyeqf@users.noreply.github.com> Date: Mon, 14 Aug 2023 14:54:02 +0800 Subject: [PATCH 13/15] update code Signed-off-by: ziyeqf <51212351+ziyeqf@users.noreply.github.com> --- .../site_recovery_vmware_replicated_vm_resource.go | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/internal/services/recoveryservices/site_recovery_vmware_replicated_vm_resource.go b/internal/services/recoveryservices/site_recovery_vmware_replicated_vm_resource.go index 6e6052ebd0d2..37eadb7cf096 100644 --- a/internal/services/recoveryservices/site_recovery_vmware_replicated_vm_resource.go +++ b/internal/services/recoveryservices/site_recovery_vmware_replicated_vm_resource.go @@ -22,7 +22,6 @@ import ( "github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2022-10-01/replicationpolicies" "github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2022-10-01/replicationprotecteditems" "github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2022-10-01/replicationprotectioncontainers" - "github.com/hashicorp/go-azure-sdk/resource-manager/storage/2022-05-01/storageaccounts" "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-provider-azurerm/helpers/tf" @@ -160,7 +159,7 @@ func (s VMWareReplicatedVmResource) Arguments() map[string]*pluginsdk.Schema { "default_log_storage_account_id": { Type: pluginsdk.TypeString, Optional: true, - ValidateFunc: storageaccounts.ValidateStorageAccountID, + ValidateFunc: commonids.ValidateStorageAccountID, ExactlyOneOf: []string{"managed_disk", "default_log_storage_account_id"}, }, @@ -230,7 +229,7 @@ func (s VMWareReplicatedVmResource) Arguments() map[string]*pluginsdk.Schema { "target_boot_diagnostics_storage_account_id": { Type: pluginsdk.TypeString, Optional: true, - ValidateFunc: storageaccounts.ValidateStorageAccountID, + ValidateFunc: commonids.ValidateStorageAccountID, }, // managed disk is enabled only if mobility service is already installed. (in most cases, it's not installed) @@ -273,7 +272,7 @@ func resourceSiteRecoveryVMWareReplicatedVMManagedDiskSchema() *pluginsdk.Resour "log_storage_account_id": { Type: pluginsdk.TypeString, Required: true, - ValidateFunc: storageaccounts.ValidateStorageAccountID, + ValidateFunc: commonids.ValidateStorageAccountID, }, }, } @@ -514,7 +513,7 @@ func (s VMWareReplicatedVmResource) Create() sdk.ResourceFunc { // once the PUT request returned successfully, an item has been created, even if it may fail in the poll process. metadata.SetID(id) - err = poller.Poller.PollUntilDone() + err = poller.Poller.PollUntilDone(ctx) if err != nil { return fmt.Errorf("polling %q: %+v", id, err) } From 1cb83012123b2279b74119376eee332e3154d09c Mon Sep 17 00:00:00 2001 From: ziyeqf <51212351+ziyeqf@users.noreply.github.com> Date: Mon, 11 Dec 2023 16:07:22 +0800 Subject: [PATCH 14/15] refresh vendor --- .../2020-01-01/machines/id_vmwaresite.go | 38 +++++++++---------- .../2020-01-01/runasaccounts/id_vmwaresite.go | 38 +++++++++---------- 2 files changed, 36 insertions(+), 40 deletions(-) diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/migrate/2020-01-01/machines/id_vmwaresite.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/migrate/2020-01-01/machines/id_vmwaresite.go index d7c350b4e0f6..ce511fde5bd5 100644 --- a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/migrate/2020-01-01/machines/id_vmwaresite.go +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/migrate/2020-01-01/machines/id_vmwaresite.go @@ -36,19 +36,9 @@ func ParseVMwareSiteID(input string) (*VMwareSiteId, error) { return nil, fmt.Errorf("parsing %q: %+v", input, err) } - var ok bool id := VMwareSiteId{} - - if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { - return nil, resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", *parsed) - } - - if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { - return nil, resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", *parsed) - } - - if id.VmwareSiteName, ok = parsed.Parsed["vmwareSiteName"]; !ok { - return nil, resourceids.NewSegmentNotSpecifiedError(id, "vmwareSiteName", *parsed) + if err := id.FromParseResult(*parsed); err != nil { + return nil, err } return &id, nil @@ -63,22 +53,30 @@ func ParseVMwareSiteIDInsensitively(input string) (*VMwareSiteId, error) { return nil, fmt.Errorf("parsing %q: %+v", input, err) } - var ok bool id := VMwareSiteId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} - if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { - return nil, resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", *parsed) +func (id *VMwareSiteId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) } - if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { - return nil, resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", *parsed) + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) } - if id.VmwareSiteName, ok = parsed.Parsed["vmwareSiteName"]; !ok { - return nil, resourceids.NewSegmentNotSpecifiedError(id, "vmwareSiteName", *parsed) + if id.VmwareSiteName, ok = input.Parsed["vmwareSiteName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "vmwareSiteName", input) } - return &id, nil + return nil } // ValidateVMwareSiteID checks that 'input' can be parsed as a V Mware Site ID diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/migrate/2020-01-01/runasaccounts/id_vmwaresite.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/migrate/2020-01-01/runasaccounts/id_vmwaresite.go index efaf5b4477f6..20b7b8a51466 100644 --- a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/migrate/2020-01-01/runasaccounts/id_vmwaresite.go +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/migrate/2020-01-01/runasaccounts/id_vmwaresite.go @@ -36,19 +36,9 @@ func ParseVMwareSiteID(input string) (*VMwareSiteId, error) { return nil, fmt.Errorf("parsing %q: %+v", input, err) } - var ok bool id := VMwareSiteId{} - - if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { - return nil, resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", *parsed) - } - - if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { - return nil, resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", *parsed) - } - - if id.VmwareSiteName, ok = parsed.Parsed["vmwareSiteName"]; !ok { - return nil, resourceids.NewSegmentNotSpecifiedError(id, "vmwareSiteName", *parsed) + if err := id.FromParseResult(*parsed); err != nil { + return nil, err } return &id, nil @@ -63,22 +53,30 @@ func ParseVMwareSiteIDInsensitively(input string) (*VMwareSiteId, error) { return nil, fmt.Errorf("parsing %q: %+v", input, err) } - var ok bool id := VMwareSiteId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} - if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { - return nil, resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", *parsed) +func (id *VMwareSiteId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) } - if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { - return nil, resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", *parsed) + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) } - if id.VmwareSiteName, ok = parsed.Parsed["vmwareSiteName"]; !ok { - return nil, resourceids.NewSegmentNotSpecifiedError(id, "vmwareSiteName", *parsed) + if id.VmwareSiteName, ok = input.Parsed["vmwareSiteName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "vmwareSiteName", input) } - return &id, nil + return nil } // ValidateVMwareSiteID checks that 'input' can be parsed as a V Mware Site ID From 20227c2ed4a07cbe84ac5e959906361a8426cae2 Mon Sep 17 00:00:00 2001 From: ziyeqf <51212351+ziyeqf@users.noreply.github.com> Date: Tue, 19 Dec 2023 16:59:52 +0800 Subject: [PATCH 15/15] update per comment --- .../vmware_replicated_vm_poller.go | 50 -------- ..._recovery_vmware_replicated_vm_resource.go | 116 ++++++++---------- ...very_vmware_replicated_vm_resource_test.go | 44 +++---- ...ecovery_vmware_replicated_vm.html.markdown | 23 +--- 4 files changed, 78 insertions(+), 155 deletions(-) delete mode 100644 internal/services/recoveryservices/custompollers/vmware_replicated_vm_poller.go diff --git a/internal/services/recoveryservices/custompollers/vmware_replicated_vm_poller.go b/internal/services/recoveryservices/custompollers/vmware_replicated_vm_poller.go deleted file mode 100644 index edb83bdf79fe..000000000000 --- a/internal/services/recoveryservices/custompollers/vmware_replicated_vm_poller.go +++ /dev/null @@ -1,50 +0,0 @@ -package custompollers - -import ( - "context" - "fmt" - "strings" - "time" - - "github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2022-10-01/replicationprotecteditems" - "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" -) - -var _ pollers.PollerType = &VMWareReplicatedVMPoller{} - -func NewVMWareReplicatedVMPoller(client *replicationprotecteditems.ReplicationProtectedItemsClient, id replicationprotecteditems.ReplicationProtectedItemId) *VMWareReplicatedVMPoller { - return &VMWareReplicatedVMPoller{ - client: client, - id: id, - } -} - -type VMWareReplicatedVMPoller struct { - client *replicationprotecteditems.ReplicationProtectedItemsClient - id replicationprotecteditems.ReplicationProtectedItemId -} - -func (p VMWareReplicatedVMPoller) Poll(ctx context.Context) (*pollers.PollResult, error) { - resp, err := p.client.Get(ctx, p.id) - if err != nil { - return nil, fmt.Errorf("retrieving %s: %+v", p.id, err) - } - - protectionState := "" - if model := resp.Model; model != nil && model.Properties != nil && resp.Model.Properties.ProtectionState != nil { - protectionState = *model.Properties.ProtectionState - } - - if strings.EqualFold(protectionState, "Protected") || strings.EqualFold(protectionState, "normal") { - return &pollers.PollResult{ - Status: pollers.PollingStatusSucceeded, - PollInterval: 1 * time.Minute, - }, nil - } - - // Processing - return &pollers.PollResult{ - Status: pollers.PollingStatusInProgress, - PollInterval: 1 * time.Minute, - }, nil -} diff --git a/internal/services/recoveryservices/site_recovery_vmware_replicated_vm_resource.go b/internal/services/recoveryservices/site_recovery_vmware_replicated_vm_resource.go index 37eadb7cf096..3e8fb544fd91 100644 --- a/internal/services/recoveryservices/site_recovery_vmware_replicated_vm_resource.go +++ b/internal/services/recoveryservices/site_recovery_vmware_replicated_vm_resource.go @@ -3,7 +3,6 @@ package recoveryservices import ( "context" "fmt" - "log" "regexp" "strconv" "strings" @@ -13,24 +12,22 @@ import ( "github.com/hashicorp/go-azure-helpers/lang/pointer" "github.com/hashicorp/go-azure-helpers/lang/response" "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonschema" "github.com/hashicorp/go-azure-sdk/resource-manager/compute/2021-11-01/availabilitysets" "github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-01/proximityplacementgroups" "github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-02/diskencryptionsets" vmwaremachines "github.com/hashicorp/go-azure-sdk/resource-manager/migrate/2020-01-01/machines" vmwarerunasaccounts "github.com/hashicorp/go-azure-sdk/resource-manager/migrate/2020-01-01/runasaccounts" + "github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservices/2022-10-01/vaults" "github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2022-10-01/replicationfabrics" "github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2022-10-01/replicationpolicies" "github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2022-10-01/replicationprotecteditems" "github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2022-10-01/replicationprotectioncontainers" - "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-provider-azurerm/helpers/tf" "github.com/hashicorp/terraform-provider-azurerm/internal/sdk" "github.com/hashicorp/terraform-provider-azurerm/internal/services/recoveryservices/azuresdkhacks" - "github.com/hashicorp/terraform-provider-azurerm/internal/services/recoveryservices/custompollers" - validateResourceGroup "github.com/hashicorp/terraform-provider-azurerm/internal/services/resource/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" ) @@ -88,8 +85,10 @@ func (s VMWareReplicatedVmResource) IDValidationFunc() pluginsdk.SchemaValidateF return replicationprotecteditems.ValidateReplicationProtectedItemID } -var _ sdk.ResourceWithUpdate = VMWareReplicatedVmResource{} -var _ sdk.ResourceWithCustomizeDiff = VMWareReplicatedVmResource{} +var ( + _ sdk.ResourceWithUpdate = VMWareReplicatedVmResource{} + _ sdk.ResourceWithCustomizeDiff = VMWareReplicatedVmResource{} +) func (s VMWareReplicatedVmResource) Arguments() map[string]*pluginsdk.Schema { return map[string]*pluginsdk.Schema{ @@ -100,12 +99,7 @@ func (s VMWareReplicatedVmResource) Arguments() map[string]*pluginsdk.Schema { ValidateFunc: validation.StringIsNotEmpty, }, - "recovery_vault_id": { - Type: pluginsdk.TypeString, - Required: true, - ForceNew: true, - ValidateFunc: replicationprotecteditems.ValidateVaultID, - }, + "recovery_vault_id": commonschema.ResourceIDReferenceRequired(vaults.VaultId{}), "source_vm_name": { Type: pluginsdk.TypeString, @@ -121,12 +115,7 @@ func (s VMWareReplicatedVmResource) Arguments() map[string]*pluginsdk.Schema { ValidateFunc: validation.StringIsNotEmpty, }, - "recovery_replication_policy_id": { - Type: pluginsdk.TypeString, - Required: true, - ForceNew: true, - ValidateFunc: replicationpolicies.ValidateReplicationPolicyID, - }, + "recovery_replication_policy_id": commonschema.ResourceIDReferenceRequired(replicationpolicies.ReplicationPolicyId{}), "physical_server_credential_name": { Type: pluginsdk.TypeString, @@ -142,12 +131,7 @@ func (s VMWareReplicatedVmResource) Arguments() map[string]*pluginsdk.Schema { ValidateFunc: validation.StringInSlice(replicationprotecteditems.PossibleValuesForLicenseType(), false), }, - "target_resource_group_id": { - Type: pluginsdk.TypeString, - Required: true, - ForceNew: true, - ValidateFunc: validateResourceGroup.ResourceGroupID, - }, + "target_resource_group_id": commonschema.ResourceIDReferenceRequired(commonids.ResourceGroupId{}), "target_vm_name": { Type: pluginsdk.TypeString, @@ -171,10 +155,9 @@ func (s VMWareReplicatedVmResource) Arguments() map[string]*pluginsdk.Schema { }, "default_target_disk_encryption_set_id": { - Type: pluginsdk.TypeString, - Optional: true, - ConflictsWith: []string{"managed_disk"}, - ValidateFunc: diskencryptionsets.ValidateDiskEncryptionSetID, + Type: pluginsdk.TypeString, + Optional: true, + ValidateFunc: diskencryptionsets.ValidateDiskEncryptionSetID, }, "multi_vm_group_name": { @@ -183,11 +166,7 @@ func (s VMWareReplicatedVmResource) Arguments() map[string]*pluginsdk.Schema { ValidateFunc: validation.StringIsNotEmpty, }, - "target_proximity_placement_group_id": { - Type: pluginsdk.TypeString, - Optional: true, - ValidateFunc: proximityplacementgroups.ValidateProximityPlacementGroupID, - }, + "target_proximity_placement_group_id": commonschema.ResourceIDReferenceOptional(proximityplacementgroups.ProximityPlacementGroupId{}), "target_vm_size": { Type: pluginsdk.TypeString, @@ -220,17 +199,9 @@ func (s VMWareReplicatedVmResource) Arguments() map[string]*pluginsdk.Schema { RequiredWith: []string{"network_interface"}, }, - "test_network_id": { - Type: pluginsdk.TypeString, - Optional: true, - ValidateFunc: commonids.ValidateVirtualNetworkID, - }, + "test_network_id": commonschema.ResourceIDReferenceOptional(commonids.VirtualNetworkId{}), - "target_boot_diagnostics_storage_account_id": { - Type: pluginsdk.TypeString, - Optional: true, - ValidateFunc: commonids.ValidateStorageAccountID, - }, + "target_boot_diagnostics_storage_account_id": commonschema.ResourceIDReferenceOptional(commonids.StorageAccountId{}), // managed disk is enabled only if mobility service is already installed. (in most cases, it's not installed) "managed_disk": { @@ -251,10 +222,9 @@ func resourceSiteRecoveryVMWareReplicatedVMManagedDiskSchema() *pluginsdk.Resour return &pluginsdk.Resource{ Schema: map[string]*pluginsdk.Schema{ "disk_id": { - Type: pluginsdk.TypeString, - Required: true, - ValidateFunc: validation.StringIsNotEmpty, - DiffSuppressFunc: suppress.CaseDifference, + Type: pluginsdk.TypeString, + Required: true, + ValidateFunc: validation.StringIsNotEmpty, }, "target_disk_type": { @@ -263,17 +233,9 @@ func resourceSiteRecoveryVMWareReplicatedVMManagedDiskSchema() *pluginsdk.Resour ValidateFunc: validation.StringInSlice(replicationprotecteditems.PossibleValuesForDiskAccountType(), false), }, - "target_disk_encryption_set_id": { - Type: pluginsdk.TypeString, - Optional: true, - ValidateFunc: diskencryptionsets.ValidateDiskEncryptionSetID, - }, + "target_disk_encryption_set_id": commonschema.ResourceIDReferenceOptional(diskencryptionsets.DiskEncryptionSetId{}), - "log_storage_account_id": { - Type: pluginsdk.TypeString, - Required: true, - ValidateFunc: commonids.ValidateStorageAccountID, - }, + "log_storage_account_id": commonschema.ResourceIDReferenceOptional(commonids.StorageAccountId{}), }, } } @@ -518,11 +480,41 @@ func (s VMWareReplicatedVmResource) Create() sdk.ResourceFunc { return fmt.Errorf("polling %q: %+v", id, err) } - log.Printf("[DEBUG] Waiting for %s to be fully protected..", id) - pollerType := custompollers.NewVMWareReplicatedVMPoller(client, id) + deadline, ok := ctx.Deadline() + if !ok { + return fmt.Errorf("internal-error: context had no deadline") + } + stateConf := &pluginsdk.StateChangeConf{ + Pending: []string{"Pending"}, + Target: []string{"Protected"}, + Refresh: func() (result interface{}, state string, err error) { + resp, err := client.Get(ctx, id) + if err != nil { + return nil, "error", fmt.Errorf("retrieving %s: %+v", id, err) + } + + protectionState := "" + if model := resp.Model; model != nil && model.Properties != nil && resp.Model.Properties.ProtectionState != nil { + protectionState = *model.Properties.ProtectionState + } + + if strings.EqualFold(protectionState, "Protected") { + return resp, protectionState, nil + } + + // The `protectionState` has pretty much enums, and will changes in the duration of replicate. + // While failed ones and canceled ones have common pattern. + if strings.HasSuffix(protectionState, "Failed") || strings.HasPrefix(protectionState, "Cancel") { + return resp, protectionState, fmt.Errorf("replicate failed or canceled") + } + + return resp, "Pending", nil + }, + MinTimeout: 15 * time.Second, + Timeout: time.Until(deadline), + } - protectPoller := pollers.NewPoller(pollerType, 1*time.Minute, pollers.DefaultNumberOfDroppedConnectionsToAllow) - if err := protectPoller.PollUntilDone(ctx); err != nil { + if _, err := stateConf.WaitForStateContext(ctx); err != nil { return fmt.Errorf("waiting for %s to be fully protected: %s", id, err) } diff --git a/internal/services/recoveryservices/site_recovery_vmware_replicated_vm_resource_test.go b/internal/services/recoveryservices/site_recovery_vmware_replicated_vm_resource_test.go index 2b227b59d1a9..1184ed4f8a9b 100644 --- a/internal/services/recoveryservices/site_recovery_vmware_replicated_vm_resource_test.go +++ b/internal/services/recoveryservices/site_recovery_vmware_replicated_vm_resource_test.go @@ -67,8 +67,8 @@ func newSiteRecoveryVMWareReplicatedVMResource(vaultId, sourceVMName, applianceN Credential: credential, SourceMacAddress: sourceMacAddress, }, nil - } + func (r SiteRecoveryVMWareReplicatedVmResource) Exists(ctx context.Context, clients *clients.Client, state *pluginsdk.InstanceState) (*bool, error) { id, err := replicationprotecteditems.ParseReplicationProtectedItemID(state.ID) if err != nil { @@ -115,30 +115,9 @@ func (r SiteRecoveryVMWareReplicatedVmResource) basic(data acceptance.TestData) provider "azurerm" { subscription_id = "%[1]s" features { - resource_group { - prevent_deletion_if_contains_resources = false - } } } -data "azurerm_recovery_services_vault" "vault" { - name = "%[2]s" - resource_group_name = "%[3]s" -} - -resource "azurerm_site_recovery_vmware_replication_policy" "test" { - recovery_vault_id = data.azurerm_recovery_services_vault.vault.id - name = "acctest-policy-%[4]d" - recovery_point_retention_in_minutes = 1440 - application_consistent_snapshot_frequency_in_minutes = 240 -} - -resource "azurerm_site_recovery_vmware_replication_policy_association" "test" { - name = "acctest-%[4]d" - recovery_vault_id = data.azurerm_recovery_services_vault.vault.id - policy_id = azurerm_site_recovery_vmware_replication_policy.test.id -} - resource "azurerm_resource_group" "target" { name = "acctestRG-%[4]d" location = "%[6]s" @@ -166,6 +145,23 @@ resource "azurerm_subnet" "target" { address_prefixes = ["10.0.2.0/24"] } +data "azurerm_recovery_services_vault" "vault" { + name = "%[2]s" + resource_group_name = "%[3]s" +} + +resource "azurerm_site_recovery_vmware_replication_policy" "test" { + recovery_vault_id = data.azurerm_recovery_services_vault.vault.id + name = "acctest-policy-%[4]d" + recovery_point_retention_in_minutes = 1440 + application_consistent_snapshot_frequency_in_minutes = 240 +} + +resource "azurerm_site_recovery_vmware_replication_policy_association" "test" { + name = "acctest-%[4]d" + recovery_vault_id = data.azurerm_recovery_services_vault.vault.id + policy_id = azurerm_site_recovery_vmware_replication_policy.test.id +} resource "azurerm_site_recovery_vmware_replicated_vm" "test" { name = "acct%[4]d" @@ -188,10 +184,6 @@ resource "azurerm_site_recovery_vmware_replicated_vm" "test" { is_primary = true } - timeouts { - create = "600m" - } - lifecycle { ignore_changes = [ target_vm_size, diff --git a/website/docs/r/site_recovery_vmware_replicated_vm.html.markdown b/website/docs/r/site_recovery_vmware_replicated_vm.html.markdown index 5f8afb519913..0979c5f379a3 100644 --- a/website/docs/r/site_recovery_vmware_replicated_vm.html.markdown +++ b/website/docs/r/site_recovery_vmware_replicated_vm.html.markdown @@ -61,14 +61,6 @@ resource "azurerm_subnet" "example" { address_prefixes = ["192.168.2.0/24"] } -resource "azurerm_storage_account" "example" { - name = "examplesa" - resource_group_name = azurerm_resource_group.example.name - location = azurerm_resource_group.example.location - account_tier = "Standard" - account_replication_type = "LRS" -} - resource "azurerm_site_recovery_vmware_replicated_vm" "example" { name = "example-vmware-vm" recovery_vault_id = azurerm_recovery_services_vault.example.id @@ -100,10 +92,10 @@ The following arguments are supported: * `name` - (Required) The name of the replicated VM. Changing this forces a new resource to be created. -* `recovery_vault_id` - (Required) The ID of the Recovery Services Vault where the replicated VM is created. Changing this forces a new resource to be created. - * `physical_server_credential_name` - (Required) The name of the credential to access the source VM. Changing this forces a new resource to be created. More information about the credentials could be found [here](https://learn.microsoft.com/en-us/azure/site-recovery/deploy-vmware-azure-replication-appliance-modernized). +* `recovery_vault_id` - (Required) The ID of the Recovery Services Vault where the replicated VM is created. Changing this forces a new resource to be created. + * `recovery_replication_policy_id` - (Required) The ID of the policy to use for this replicated VM. Changing this forces a new resource to be created. * `source_vm_name` - (Required) The name of the source VM in VMWare. Changing this forces a new resource to be created. @@ -128,8 +120,6 @@ The following arguments are supported: * `default_target_disk_encryption_set_id` - (Optional) The ID of the default Disk Encryption Set that should be used for the disks when a failover is done. -**Note:** Only one of `default_target_disk_encryption_set_id` or `managed_disk` can be specified. - **Note:** Changing `default_target_disk_encryption_set_id` forces a new resource to be created. But removing it does not. **Note:** When `default_target_disk_encryption_set_id` co-exist with `managed_disk`, the value of `default_target_disk_encryption_set_id` must be as same as `target_disk_encryption_set_id` of every `managed_disk` or it forces a new resource to be created. @@ -148,24 +138,23 @@ The following arguments are supported: * `managed_disk` - (Optional) One or more `managed_disk` block as defined below. It's available only if mobility service is already installed on the source VM. -**Note:** a replicated VM could be created without `managed_disk` block, once the block has been specified, changing it expect removing it forces a new resource to be created.. +**Note:** A replicated VM could be created without `managed_disk` block, once the block has been specified, changing it expect removing it forces a new resource to be created. * `network_interface` - (Optional) One or more `network_interface` block as defined below. -* `target_boot_diagnostics_storage_account_id` - (Optional) The ID of the storage account that should be used for boot diagnostics when a failover is done. +* `target_availability_set_id` - (Optional) The ID of availability set that the new VM should belong to when a failover is done. Changing this forces a new resource to be created. -* `test_network_id` - (Optional) The ID of network to use when a test failover is done. +* `target_boot_diagnostics_storage_account_id` - (Optional) The ID of the storage account that should be used for boot diagnostics when a failover is done. * `target_proximity_placement_group_id` - (Optional) The ID of Proximity Placement Group the new VM should belong to when a failover is done. -* `target_availability_set_id` - (Optional) The ID of availability set that the new VM should belong to when a failover is done. Changing this forces a new resource to be created. - **Note:** Only one of `target_availability_set_id` or `target_zone` can be specified. * `target_zone` - (Optional) Specifies the Availability Zone where the Failover VM should exist. * `target_vm_size` - (Optional) Size of the VM that should be created when a failover is done, such as `Standard_F2`. If it's not specified, it will automatically be set by detecting the source VM size. +* `test_network_id` - (Optional) The ID of network to use when a test failover is done. --- A `managed_disk` block supports the following: