From 4070c8a9eb44b66a7604c0d676ad6f7f3b98e267 Mon Sep 17 00:00:00 2001 From: ziyeqf <51212351+ziyeqf@users.noreply.github.com> Date: Tue, 30 Jan 2024 08:39:44 +0800 Subject: [PATCH] New Resource: `azurerm_site_recovery_vmware_replicated_vm` (#22477) * New Resource: `azurerm_site_recovery_vmware_replicated_vm` Signed-off-by: ziyeqf <51212351+ziyeqf@users.noreply.github.com> * update test case Signed-off-by: ziyeqf <51212351+ziyeqf@users.noreply.github.com> * update `physical_server_credential_name` Signed-off-by: ziyeqf <51212351+ziyeqf@users.noreply.github.com> * refresh /vendor Signed-off-by: ziyeqf <51212351+ziyeqf@users.noreply.github.com> * website typo Signed-off-by: ziyeqf <51212351+ziyeqf@users.noreply.github.com> * golint Signed-off-by: ziyeqf <51212351+ziyeqf@users.noreply.github.com> * update per comments Signed-off-by: ziyeqf <51212351+ziyeqf@users.noreply.github.com> * add comments Signed-off-by: ziyeqf <51212351+ziyeqf@users.noreply.github.com> * replace `utils.String` to `pointer.To` Signed-off-by: ziyeqf <51212351+ziyeqf@users.noreply.github.com> * schema lint Signed-off-by: ziyeqf <51212351+ziyeqf@users.noreply.github.com> * update test case Signed-off-by: ziyeqf <51212351+ziyeqf@users.noreply.github.com> * refresh vendor Signed-off-by: ziyeqf <51212351+ziyeqf@users.noreply.github.com> * update code Signed-off-by: ziyeqf <51212351+ziyeqf@users.noreply.github.com> * refresh vendor * update per comment --------- Signed-off-by: ziyeqf <51212351+ziyeqf@users.noreply.github.com> --- .../method_getallmachinesinsite.go | 81 ++ .../method_getallrunasaccountsinsite.go | 84 ++ .../azuresdkhacks/model_vmwarerunasaccount.go | 19 + .../recoveryservices/client/client.go | 18 + .../services/recoveryservices/registration.go | 1 + ..._recovery_vmware_replicated_vm_resource.go | 1059 +++++++++++++++++ ...very_vmware_replicated_vm_resource_test.go | 198 +++ .../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 | 125 ++ .../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 | 125 ++ .../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 + vendor/modules.txt | 2 + ...ecovery_vmware_replicated_vm.html.markdown | 205 ++++ 46 files changed, 3016 insertions(+) create mode 100644 internal/services/recoveryservices/azuresdkhacks/method_getallmachinesinsite.go 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 website/docs/r/site_recovery_vmware_replicated_vm.html.markdown diff --git a/internal/services/recoveryservices/azuresdkhacks/method_getallmachinesinsite.go b/internal/services/recoveryservices/azuresdkhacks/method_getallmachinesinsite.go new file mode 100644 index 0000000000000..1b7f1425b822e --- /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 new file mode 100644 index 0000000000000..2587a74442e62 --- /dev/null +++ b/internal/services/recoveryservices/azuresdkhacks/method_getallrunasaccountsinsite.go @@ -0,0 +1,84 @@ +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 +// the difference is in the struct `RunAsAccountProperties` +// 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 { + items = append(items, *resp.Model...) + } + + 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 0000000000000..a97c94a9a47bb --- /dev/null +++ b/internal/services/recoveryservices/azuresdkhacks/model_vmwarerunasaccount.go @@ -0,0 +1,19 @@ +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 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 7ff971c23b57e..3433eaf5e92db 100644 --- a/internal/services/recoveryservices/client/client.go +++ b/internal/services/recoveryservices/client/client.go @@ -7,6 +7,8 @@ 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" @@ -56,6 +58,8 @@ type Client struct { ReplicationRecoveryPlansClient *replicationrecoveryplans.ReplicationRecoveryPlansClient ReplicationNetworksClient *replicationnetworks.ReplicationNetworksClient ResourceGuardProxyClient *resourceguardproxy.ResourceGuardProxyClient + VMWareMachinesClient *vmwaremachines.MachinesClient + VMWareRunAsAccountsClient *vmwarerunasaccounts.RunAsAccountsClient } func NewClient(o *common.ClientOptions) (*Client, error) { @@ -158,6 +162,18 @@ func NewClient(o *common.ClientOptions) (*Client, error) { 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 Run As Accounts client: %+v", err) + } + o.Configure(vmwareRunAsAccountsClient.Client, o.Authorizers.ResourceManager) + return &Client{ ProtectableItemsClient: &protectableItemsClient, ProtectedItemsClient: &protectedItemsClient, @@ -182,5 +198,7 @@ func NewClient(o *common.ClientOptions) (*Client, error) { 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 d62133fc9928c..27bff567db10b 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 0000000000000..3e8fb544fd915 --- /dev/null +++ b/internal/services/recoveryservices/site_recovery_vmware_replicated_vm_resource.go @@ -0,0 +1,1059 @@ +package recoveryservices + +import ( + "context" + "fmt" + "regexp" + "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-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/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/tf/pluginsdk" + "github.com/hashicorp/terraform-provider-azurerm/internal/tf/validation" +) + +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"` + 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"` + 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"` + 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{} + _ 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": commonschema.ResourceIDReferenceRequired(vaults.VaultId{}), + + "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": commonschema.ResourceIDReferenceRequired(replicationpolicies.ReplicationPolicyId{}), + + "physical_server_credential_name": { + Type: pluginsdk.TypeString, + Required: true, + ForceNew: true, + ValidateFunc: validation.StringIsNotEmpty, + }, + + "license_type": { + Type: pluginsdk.TypeString, + Optional: true, + Default: string(replicationprotecteditems.LicenseTypeNotSpecified), + ValidateFunc: validation.StringInSlice(replicationprotecteditems.PossibleValuesForLicenseType(), false), + }, + + "target_resource_group_id": commonschema.ResourceIDReferenceRequired(commonids.ResourceGroupId{}), + + "target_vm_name": { + Type: pluginsdk.TypeString, + Required: true, + ForceNew: true, + ValidateFunc: validation.StringIsNotEmpty, + }, + + "default_log_storage_account_id": { + Type: pluginsdk.TypeString, + Optional: true, + ValidateFunc: commonids.ValidateStorageAccountID, + ExactlyOneOf: []string{"managed_disk", "default_log_storage_account_id"}, + }, + + "default_recovery_disk_type": { + Type: pluginsdk.TypeString, + Optional: true, + ExactlyOneOf: []string{"managed_disk", "default_recovery_disk_type"}, + ValidateFunc: validation.StringInSlice(replicationprotecteditems.PossibleValuesForDiskAccountType(), false), + }, + + "default_target_disk_encryption_set_id": { + Type: pluginsdk.TypeString, + Optional: true, + ValidateFunc: diskencryptionsets.ValidateDiskEncryptionSetID, + }, + + "multi_vm_group_name": { + Type: pluginsdk.TypeString, + Optional: true, + ValidateFunc: validation.StringIsNotEmpty, + }, + + "target_proximity_placement_group_id": commonschema.ResourceIDReferenceOptional(proximityplacementgroups.ProximityPlacementGroupId{}), + + "target_vm_size": { + Type: pluginsdk.TypeString, + Optional: true, + ValidateFunc: validation.StringIsNotEmpty, + }, + + "target_availability_set_id": { + Type: pluginsdk.TypeString, + Optional: true, + ValidateFunc: availabilitysets.ValidateAvailabilitySetID, + 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, + RequiredWith: []string{"network_interface"}, + }, + + "test_network_id": commonschema.ResourceIDReferenceOptional(commonids.VirtualNetworkId{}), + + "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": { + Type: pluginsdk.TypeList, + Optional: true, + Elem: resourceSiteRecoveryVMWareReplicatedVMManagedDiskSchema(), + }, + + "network_interface": { + Type: pluginsdk.TypeList, + Optional: 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, + }, + + "target_disk_type": { + Type: pluginsdk.TypeString, + Required: true, + ValidateFunc: validation.StringInSlice(replicationprotecteditems.PossibleValuesForDiskAccountType(), false), + }, + + "target_disk_encryption_set_id": commonschema.ResourceIDReferenceOptional(diskencryptionsets.DiskEncryptionSetId{}), + + "log_storage_account_id": commonschema.ResourceIDReferenceOptional(commonids.StorageAccountId{}), + }, + } +} + +func resourceSiteRecoveryVMWareReplicatedVMNetworkInterfaceSchema() *pluginsdk.Resource { + return &pluginsdk.Resource{ + Schema: map[string]*pluginsdk.Schema{ + "source_mac_address": { + Type: pluginsdk.TypeString, + 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.IsIPv4Address, + }, + + "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") + 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") + } + 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 forces new. + // or it acts as an optional field. + if len(newDisks.([]interface{})) != 0 { + metadata.ResourceDiff.ForceNew("managed_disk") + } + } + + return nil + }, + Timeout: 30 * time.Minute, + } +} + +func (s VMWareReplicatedVmResource) Create() sdk.ResourceFunc { + return sdk.ResourceFunc{ + Timeout: 120 * 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) + } + + vaultId, err := replicationprotecteditems.ParseVaultID(model.RecoveryVaultId) + if err != nil { + return fmt.Errorf("parsing vault id %q: %+v", model.RecoveryVaultId, err) + } + + containerId, err := fetchSiteRecoveryContainerId(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) + + 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) + } + + 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.PhysicalServerCredentialName, model.ApplianceName) + if err != nil { + return fmt.Errorf("fetch run as account id %s: %+v", model.PhysicalServerCredentialName, 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, + } + + 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.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) + } + + if model.TargetZone != "" { + providerSpecificDetail.TargetAvailabilityZone = pointer.To(model.TargetZone) + } + + if model.TargetBootDiagnosticsStorageAccountId != "" { + providerSpecificDetail.TargetBootDiagnosticsStorageAccountId = pointer.To(model.TargetBootDiagnosticsStorageAccountId) + } + + if model.TargetProximityPlacementGroupId != "" { + providerSpecificDetail.TargetProximityPlacementGroupId = &model.TargetProximityPlacementGroupId + } + + 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) + } + // 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(ctx) + if err != nil { + return fmt.Errorf("polling %q: %+v", id, err) + } + + 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), + } + + if _, err := stateConf.WaitForStateContext(ctx); err != nil { + 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, + 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) + } + + return nil + }, + } +} + +func (s VMWareReplicatedVmResource) Update() sdk.ResourceFunc { + return sdk.ResourceFunc{ + Timeout: 90 * time.Minute, + 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") { + 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 + }, + } +} + +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 + runAsAccountId := metadata.Client.RecoveryServices.VMWareRunAsAccountsClient + + 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) + + 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 { + 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 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) + } + + 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, 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 + } + + 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, displayName) && strings.EqualFold(*account.Properties.ApplianceName, applianceName) { + return *account.Id, nil + } + } + + 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) { + resp, err := fabricClient.Get(ctx, fabricId, replicationfabrics.DefaultGetOperationOptions()) + if err != nil { + return "", err + } + + if resp.Model == nil { + return "", fmt.Errorf("retrieving %q: Model is nil", fabricId) + } + + if resp.Model.Properties == nil { + return "", fmt.Errorf("retrieving %q: Properties is nil", fabricId) + } + + if resp.Model.Properties.CustomDetails == nil { + return "", fmt.Errorf("retrieving %q: CustomDetails is nil", fabricId) + } + + if detail, ok := resp.Model.Properties.CustomDetails.(replicationfabrics.InMageRcmFabricSpecificDetails); ok { + 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("retrieving %q: process server %s not found", fabricId, processServerName) + } + return "", fmt.Errorf("retrieving %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) + } + + hackedClient := azuresdkhacks.MachinesClient{Client: machinesClient.Client} + resp, err := hackedClient.GetAllVMWareMachinesInSite(ctx, *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) { + parsedMachineId, err := commonids.ParseVMwareSiteMachineIDInsensitively(*machine.Id) + if err != nil { + return "", fmt.Errorf("parse %s: %+v", *machine.Id, err) + } + return parsedMachineId.ID(), nil + } + } + } + + return "", fmt.Errorf("retrieving %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("retrieving %q: Model was nil", id) + } + + if resp.Model.Properties == nil { + return "", fmt.Errorf("retrieving %q: Properties was nil", id) + } + + if resp.Model.Properties.DisplayName == nil { + return "", fmt.Errorf("retrieving %q: DisplayName was nil", id) + } + + return *resp.Model.Properties.DisplayName, nil +} + +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("retrieving %q: Model is nil", fabricId) + } + if resp.Model.Properties == nil { + 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("retrieving %q: VMwareSiteId is nil", fabricId) + } + return *v.VMwareSiteId, nil + } + 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 = pointer.To("true") + } else { + vmNic.IsPrimaryNic = strconv.FormatBool(false) + vmNic.IsSelectedForFailover = pointer.To("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 new file mode 100644 index 0000000000000..1184ed4f8a9bc --- /dev/null +++ b/internal/services/recoveryservices/site_recovery_vmware_replicated_vm_resource_test.go @@ -0,0 +1,198 @@ +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 { + SubscriptionId string + VaultName string + VaultRgName string + SourceVMName string + ApplianceName string + Location string + Credential string + SourceMacAddress string +} + +func (r SiteRecoveryVMWareReplicatedVmResource) preCheck(t *testing.T) { + 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!") + } + 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 := replicationprotecteditems.ParseVaultID(vaultId) + if err != nil { + return SiteRecoveryVMWareReplicatedVmResource{}, fmt.Errorf("parsing %q: %+v", vaultId, err) + } + return SiteRecoveryVMWareReplicatedVmResource{ + SubscriptionId: parsedVaultId.SubscriptionId, + 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 { + 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, 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.Skipf("failed to create SiteRecoveryVMWareReplicatedVmResource: %+v", err) + } + + r.preCheck(t) + + data.ResourceTest(t, r, []acceptance.TestStep{ + { + Config: r.basic(data), + Check: acceptance.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + ), + }, + data.ImportStep(), + }) +} + +func (r SiteRecoveryVMWareReplicatedVmResource) basic(data acceptance.TestData) string { + return fmt.Sprintf(` +provider "azurerm" { + subscription_id = "%[1]s" + features { + } +} + +resource "azurerm_resource_group" "target" { + name = "acctestRG-%[4]d" + location = "%[6]s" +} + +resource "azurerm_storage_account" "target" { + name = "acct%[5]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-%[4]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"] +} + +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" + recovery_vault_id = data.azurerm_recovery_services_vault.vault.id + 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 = "%[9]s" + license_type = "NotSpecified" + target_boot_diagnostics_storage_account_id = azurerm_storage_account.target.id + 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 + } + + lifecycle { + ignore_changes = [ + target_vm_size, + default_log_storage_account_id, + default_recovery_disk_type, + managed_disk, + network_interface + ] + } +} +`, r.SubscriptionId, r.VaultName, r.VaultRgName, data.RandomInteger, data.RandomString, r.Location, r.SourceVMName, r.ApplianceName, r.Credential, r.SourceMacAddress) +} 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 0000000000000..a5acf2832f989 --- /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 0000000000000..e0daf9080614d --- /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" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type MachinesClient struct { + Client *resourcemanager.Client +} + +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) + } + + 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 0000000000000..2e9c98c034e1f --- /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 0000000000000..ce511fde5bd5f --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/migrate/2020-01-01/machines/id_vmwaresite.go @@ -0,0 +1,125 @@ +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) + } + + id := VMwareSiteId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + 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) + } + + id := VMwareSiteId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +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 = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.VmwareSiteName, ok = input.Parsed["vmwareSiteName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "vmwareSiteName", input) + } + + return 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 0000000000000..bfdcb2a30377d --- /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; charset=utf-8", + 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 0000000000000..471da6ef22967 --- /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; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + 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 0000000000000..737475e7a1e78 --- /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; charset=utf-8", + 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 0000000000000..00f031985d4fb --- /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; charset=utf-8", + 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 0000000000000..3cc5f9c1cc395 --- /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 0000000000000..b1d02fdea3ae9 --- /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 0000000000000..78fa9a908e7fc --- /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 0000000000000..26dd1b2e46378 --- /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 0000000000000..7d99cf9017ba3 --- /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 0000000000000..007ec0b1e3d06 --- /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 0000000000000..48f82e65ceaa9 --- /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 0000000000000..358760587b782 --- /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 0000000000000..8014cb880e0c0 --- /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 0000000000000..5aaefcef0e925 --- /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 0000000000000..034ab8266a8c3 --- /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 0000000000000..b269a7c1e1abf --- /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 0000000000000..4cc6da44fe59a --- /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 0000000000000..b51f2577378b2 --- /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 0000000000000..3d95d8a1a6bc2 --- /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 0000000000000..3ffc1e25b8a7f --- /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 0000000000000..fea275a48c884 --- /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 0000000000000..2b0d532f563f1 --- /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 0000000000000..c0980e7be08aa --- /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 0000000000000..215d6f649894a --- /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 0000000000000..eec6adbe66f52 --- /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" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RunAsAccountsClient struct { + Client *resourcemanager.Client +} + +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) + } + + 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 0000000000000..b800ddda1e76e --- /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 0000000000000..20b7b8a51466b --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/migrate/2020-01-01/runasaccounts/id_vmwaresite.go @@ -0,0 +1,125 @@ +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) + } + + id := VMwareSiteId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + 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) + } + + id := VMwareSiteId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +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 = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.VmwareSiteName, ok = input.Parsed["vmwareSiteName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "vmwareSiteName", input) + } + + return 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 0000000000000..f1fd349a96b3a --- /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; charset=utf-8", + 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 0000000000000..2d19d053dbcc4 --- /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; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + 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 0000000000000..568a58ae0217a --- /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 0000000000000..960acd23b420b --- /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 0000000000000..69ec7fbed704f --- /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 0000000000000..8c3c4c0c7b81f --- /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/modules.txt b/vendor/modules.txt index b2d6c4de59829..7dfd3407fba0e 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -623,6 +623,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/attacheddatanetwork github.com/hashicorp/go-azure-sdk/resource-manager/mobilenetwork/2022-11-01/datanetwork 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 0000000000000..0979c5f379a36 --- /dev/null +++ b/website/docs/r/site_recovery_vmware_replicated_vm.html.markdown @@ -0,0 +1,205 @@ +--- +subcategory: "Recovery Services" +layout: "azurerm" +page_title: "Azure Resource Manager: azurerm_site_recovery_vmware_replicated_vm" +description: |- + Manages a VMWare replicated VM protected with Azure Site Recovery on Azure. +--- + +# azurerm_site_recovery_vmware_replicated_vm + +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 + +```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_vmware_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_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_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" + 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 { + source_mac_address = "00:00:00:00:00:00" + target_subnet_name = azurerm_subnet.example.name + is_primary = true + } +} +``` + +## Argument Reference + +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. + +* `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. + +* `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. + +* `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. + +**Note:** Only standard types of storage accounts are allowed. + +**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. + +**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. + +* `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_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. + +* `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:** Only 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. + +**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. + +* `license_type` - (Optional) The license type of the VM. Possible values are `NoLicenseType`, `NotSpecified` and `WindowsServer`. Defaults to `NotSpecified`. + +* `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. + +* `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. + +* `network_interface` - (Optional) One or more `network_interface` block as defined below. + +* `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. + +* `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. + +**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: + +* `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` - (Required) Mac address of the network interface of 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. + +* `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. + +## 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 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. + +## 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 +```