diff --git a/internal/services/recoveryservices/client/client.go b/internal/services/recoveryservices/client/client.go index 3ad4c832b2a5..d497f73f91fa 100644 --- a/internal/services/recoveryservices/client/client.go +++ b/internal/services/recoveryservices/client/client.go @@ -12,6 +12,7 @@ import ( "github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicesbackup/2023-02-01/protectionpolicies" "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/replicationnetworkmappings" + "github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2022-10-01/replicationnetworks" "github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2022-10-01/replicationpolicies" "github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2022-10-01/replicationprotecteditems" "github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2022-10-01/replicationprotectioncontainermappings" @@ -45,6 +46,7 @@ type Client struct { NetworkMappingClient *replicationnetworkmappings.ReplicationNetworkMappingsClient ReplicationProtectedItemsClient *replicationprotecteditems.ReplicationProtectedItemsClient ReplicationRecoveryPlansClient *replicationrecoveryplans.ReplicationRecoveryPlansClient + ReplicationNetworksClient *replicationnetworks.ReplicationNetworksClient } func NewClient(o *common.ClientOptions) *Client { @@ -108,6 +110,9 @@ func NewClient(o *common.ClientOptions) *Client { replicationRecoveryPlanClient := replicationrecoveryplans.NewReplicationRecoveryPlansClientWithBaseURI(o.ResourceManagerEndpoint) o.ConfigureClient(&replicationRecoveryPlanClient.Client, o.ResourceManagerAuthorizer) + replicationNetworksClient := replicationnetworks.NewReplicationNetworksClientWithBaseURI(o.ResourceManagerEndpoint) + o.ConfigureClient(&replicationNetworksClient.Client, o.ResourceManagerAuthorizer) + return &Client{ ProtectableItemsClient: &protectableItemsClient, ProtectedItemsClient: &protectedItemsClient, @@ -129,5 +134,6 @@ func NewClient(o *common.ClientOptions) *Client { NetworkMappingClient: &networkMappingClient, ReplicationProtectedItemsClient: &replicationMigrationItemsClient, ReplicationRecoveryPlansClient: &replicationRecoveryPlanClient, + ReplicationNetworksClient: &replicationNetworksClient, } } diff --git a/internal/services/recoveryservices/registration.go b/internal/services/recoveryservices/registration.go index 01dc2ac2654d..da7936b69e87 100644 --- a/internal/services/recoveryservices/registration.go +++ b/internal/services/recoveryservices/registration.go @@ -29,6 +29,7 @@ func (r Registration) Resources() []sdk.Resource { ReplicationPolicyHyperVResource{}, HyperVSiteResource{}, HyperVReplicationPolicyAssociationResource{}, + HyperVNetworkMappingResource{}, VMWareReplicationPolicyResource{}, } } diff --git a/internal/services/recoveryservices/site_recovery_hyperv_network_mapping_resource.go b/internal/services/recoveryservices/site_recovery_hyperv_network_mapping_resource.go new file mode 100644 index 000000000000..353aa00c714f --- /dev/null +++ b/internal/services/recoveryservices/site_recovery_hyperv_network_mapping_resource.go @@ -0,0 +1,253 @@ +package recoveryservices + +import ( + "context" + "fmt" + "time" + + "github.com/hashicorp/go-azure-helpers/lang/pointer" + "github.com/hashicorp/go-azure-helpers/lang/response" + "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/replicationnetworkmappings" + "github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2022-10-01/replicationnetworks" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/hashicorp/terraform-provider-azurerm/helpers/azure" + "github.com/hashicorp/terraform-provider-azurerm/helpers/tf" + "github.com/hashicorp/terraform-provider-azurerm/internal/sdk" + "github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk" + "github.com/hashicorp/terraform-provider-azurerm/internal/tf/suppress" + "github.com/hashicorp/terraform-provider-azurerm/internal/tf/validation" +) + +const HyperVNetworkMappingRecoveryFabricName = "Microsoft Azure" + +type HyperVNetworkMappingResource struct{} + +type HyperVNetworkMappingModel struct { + Name string `tfschema:"name"` + VaultId string `tfschema:"recovery_vault_id"` + SCVMMname string `tfschema:"source_system_center_virtual_machine_manager_name"` + NetworkName string `tfschema:"source_network_name"` + TargetNetworkId string `tfschema:"target_network_id"` +} + +var _ sdk.Resource = HyperVNetworkMappingResource{} + +func (s HyperVNetworkMappingResource) Arguments() map[string]*schema.Schema { + return map[string]*schema.Schema{ + "name": { + Type: pluginsdk.TypeString, + Required: true, + ForceNew: true, + ValidateFunc: validation.StringIsNotEmpty, + }, + + "recovery_vault_id": { + Type: pluginsdk.TypeString, + Required: true, + ForceNew: true, + ValidateFunc: vaults.ValidateVaultID, + }, + + "source_system_center_virtual_machine_manager_name": { + Type: pluginsdk.TypeString, + Required: true, + ForceNew: true, + ValidateFunc: validation.StringIsNotEmpty, + }, + + "source_network_name": { + Type: pluginsdk.TypeString, + Required: true, + ForceNew: true, + ValidateFunc: validation.StringIsNotEmpty, + DiffSuppressFunc: suppress.CaseDifference, + }, + + "target_network_id": { + Type: pluginsdk.TypeString, + Required: true, + ForceNew: true, + ValidateFunc: azure.ValidateResourceID, + DiffSuppressFunc: suppress.CaseDifference, + }, + } +} + +func (s HyperVNetworkMappingResource) Attributes() map[string]*schema.Schema { + return map[string]*schema.Schema{} +} + +func (s HyperVNetworkMappingResource) ModelObject() interface{} { + return &HyperVNetworkMappingModel{} +} + +func (s HyperVNetworkMappingResource) ResourceType() string { + return "azurerm_site_recovery_hyperv_network_mapping" +} + +func (s HyperVNetworkMappingResource) IDValidationFunc() pluginsdk.SchemaValidateFunc { + return replicationnetworkmappings.ValidateReplicationNetworkMappingID +} + +func (s HyperVNetworkMappingResource) Create() sdk.ResourceFunc { + return sdk.ResourceFunc{ + Timeout: 30 * time.Minute, + Func: func(ctx context.Context, metadata sdk.ResourceMetaData) error { + var plan HyperVNetworkMappingModel + if err := metadata.Decode(&plan); err != nil { + return fmt.Errorf("decoding %+v", err) + } + + client := metadata.Client.RecoveryServices.NetworkMappingClient + fabricClient := metadata.Client.RecoveryServices.FabricClient + networksClient := metadata.Client.RecoveryServices.ReplicationNetworksClient + + vaultId, err := replicationnetworkmappings.ParseVaultID(plan.VaultId) + if err != nil { + return fmt.Errorf("parsing vault id: %+v", err) + } + + fabricId, err := fetchFabricIdByFriendlyName(ctx, fabricClient, vaultId.ID(), plan.SCVMMname) + if err != nil { + return fmt.Errorf("fetching fabric id: %+v", err) + } + + networkId, err := fetchReplicationNetworkIdByFriendlyName(ctx, networksClient, fabricId, plan.NetworkName) + if err != nil { + return fmt.Errorf("fetching network id: %+v", err) + } + + parsedNetworkId, err := replicationnetworkmappings.ParseReplicationNetworkID(networkId) + if err != nil { + return fmt.Errorf("parsing network id: %+v", err) + } + + id := replicationnetworkmappings.NewReplicationNetworkMappingID(parsedNetworkId.SubscriptionId, parsedNetworkId.ResourceGroupName, parsedNetworkId.VaultName, parsedNetworkId.ReplicationFabricName, parsedNetworkId.ReplicationNetworkName, plan.Name) + existing, err := client.Get(ctx, id) + if err != nil { + if !response.WasNotFound(existing.HttpResponse) { + return fmt.Errorf("checking presence of network mapping: %+v", err) + } + } + + if !response.WasNotFound(existing.HttpResponse) { + return tf.ImportAsExistsError("azurerm_site_recovery_hyperv_network_mapping", id.ID()) + } + + err = client.CreateThenPoll(ctx, id, replicationnetworkmappings.CreateNetworkMappingInput{ + Properties: replicationnetworkmappings.CreateNetworkMappingInputProperties{ + RecoveryNetworkId: plan.TargetNetworkId, + RecoveryFabricName: pointer.To(HyperVNetworkMappingRecoveryFabricName), + FabricSpecificDetails: replicationnetworkmappings.VMmToAzureCreateNetworkMappingInput{}, + }, + }) + if err != nil { + return fmt.Errorf("creating %s: %+v", id, err) + } + + metadata.SetID(id) + return nil + }, + } +} + +func (s HyperVNetworkMappingResource) Read() sdk.ResourceFunc { + return sdk.ResourceFunc{ + Timeout: 5 * time.Minute, + Func: func(ctx context.Context, metadata sdk.ResourceMetaData) error { + id, err := replicationnetworkmappings.ParseReplicationNetworkMappingID(metadata.ResourceData.Id()) + if err != nil { + return fmt.Errorf("parsing id: %+v", err) + } + + client := metadata.Client.RecoveryServices.NetworkMappingClient + + resp, err := client.Get(ctx, *id) + if err != nil { + if response.WasNotFound(resp.HttpResponse) { + return metadata.MarkAsGone(id) + } + return fmt.Errorf("retrieving %s: %v", id, err) + } + + vaultId := replicationnetworkmappings.NewVaultID(id.SubscriptionId, id.ResourceGroupName, id.VaultName) + state := HyperVNetworkMappingModel{ + Name: id.ReplicationNetworkMappingName, + VaultId: vaultId.ID(), + } + + if model := resp.Model; model != nil { + if props := model.Properties; props != nil { + state.TargetNetworkId = pointer.From(props.RecoveryNetworkId) + state.SCVMMname = pointer.From(props.PrimaryFabricFriendlyName) + state.NetworkName = pointer.From(props.PrimaryNetworkFriendlyName) + } + } + + return metadata.Encode(&state) + }, + } +} + +func (s HyperVNetworkMappingResource) Delete() sdk.ResourceFunc { + return sdk.ResourceFunc{ + Timeout: 30 * time.Minute, + Func: func(ctx context.Context, metadata sdk.ResourceMetaData) error { + id, err := replicationnetworkmappings.ParseReplicationNetworkMappingID(metadata.ResourceData.Id()) + if err != nil { + return fmt.Errorf("parsing id: %+v", err) + } + + client := metadata.Client.RecoveryServices.NetworkMappingClient + + err = client.DeleteThenPoll(ctx, *id) + if err != nil { + return fmt.Errorf("deleting %s: %v", id, err) + } + + return nil + }, + } +} + +func fetchFabricIdByFriendlyName(ctx context.Context, fabricClient *replicationfabrics.ReplicationFabricsClient, vaultId, friendlyName string) (string, error) { + parsedVaultId, err := replicationfabrics.ParseVaultID(vaultId) + if err != nil { + return "", fmt.Errorf("parsing vault id: %+v", err) + } + + fabrics, err := fabricClient.ListComplete(ctx, *parsedVaultId) + if err != nil { + return "", fmt.Errorf("listing fabrics: %+v", err) + } + + for _, fabric := range fabrics.Items { + if fabric.Properties != nil && fabric.Properties.FriendlyName != nil && *fabric.Properties.FriendlyName == friendlyName && fabric.Id != nil { + return handleAzureSdkForGoBug2824(*fabric.Id), nil + } + } + + return "", fmt.Errorf("fabric not found") +} + +func fetchReplicationNetworkIdByFriendlyName(ctx context.Context, networksClient *replicationnetworks.ReplicationNetworksClient, fabricId, friendlyName string) (string, error) { + parsedFabricId, err := replicationnetworks.ParseReplicationFabricID(fabricId) + if err != nil { + return "", fmt.Errorf("parsing fabric id: %+v", err) + } + + networks, err := networksClient.ListByReplicationFabricsComplete(ctx, *parsedFabricId) + if err != nil { + return "", fmt.Errorf("listing networks: %+v", err) + } + + for _, network := range networks.Items { + if network.Properties != nil && network.Properties.FriendlyName != nil && *network.Properties.FriendlyName == friendlyName { + return handleAzureSdkForGoBug2824(*network.Id), nil + } + } + + return "", fmt.Errorf("replication network not found") +} diff --git a/internal/services/recoveryservices/site_recovery_hyperv_network_mapping_resource_test.go b/internal/services/recoveryservices/site_recovery_hyperv_network_mapping_resource_test.go new file mode 100644 index 000000000000..de4b4a8b2a62 --- /dev/null +++ b/internal/services/recoveryservices/site_recovery_hyperv_network_mapping_resource_test.go @@ -0,0 +1,82 @@ +package recoveryservices_test + +import ( + "context" + "fmt" + "os" + "testing" + + "github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2022-10-01/replicationnetworkmappings" + "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 SiteRecoveryHyperVNetworkMappingResource struct{} + +func TestAccSiteRecoveryHyperVNetworkMapping_basic(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_site_recovery_hyperv_network_mapping", "test") + r := SiteRecoveryHyperVNetworkMappingResource{} + + vaultId := os.Getenv("ARM_TEST_HYPERV_VAULT_ID") + vmmName := os.Getenv("ARM_TEST_HYPERV_VMM_NAME") + networkName := os.Getenv("ARM_TEST_HYPERV_VMM_NETWORK_NAME") + + if vaultId == "" || vmmName == "" || networkName == "" { + t.Skip("Skipping as ARM_TEST_HYPERV_VAULT_ID, ARM_TEST_HYPERV_VMM_NAME or ARM_TEST_HYPERV_VMM_NETWORK_NAME not set") + return + } + + data.ResourceTest(t, r, []acceptance.TestStep{ + { + Config: r.basic(data, vaultId, vmmName, networkName), + Check: acceptance.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + ), + }, + data.ImportStep(), + }) +} + +func (SiteRecoveryHyperVNetworkMappingResource) basic(data acceptance.TestData, vaultId, vmmName, networkName string) string { + return fmt.Sprintf(` +resource "azurerm_resource_group" "target" { + name = "acctestRG-recovery-%[1]d-1" + location = "%[2]s" +} + +resource "azurerm_virtual_network" "target" { + name = "network-%[1]d" + resource_group_name = azurerm_resource_group.target.name + address_space = ["192.168.2.0/24"] + location = azurerm_resource_group.target.location +} + +resource "azurerm_site_recovery_hyperv_network_mapping" "test" { + name = "mapping-%[1]d" + recovery_vault_id = "%[3]s" + source_system_center_virtual_machine_manager_name = "%[4]s" + source_network_name = "%[5]s" + target_network_id = azurerm_virtual_network.target.id +} +`, data.RandomInteger, data.Locations.Primary, vaultId, vmmName, networkName) +} + +func (t SiteRecoveryHyperVNetworkMappingResource) Exists(ctx context.Context, clients *clients.Client, state *pluginsdk.InstanceState) (*bool, error) { + id, err := replicationnetworkmappings.ParseReplicationNetworkMappingID(state.ID) + if err != nil { + return nil, err + } + + resp, err := clients.RecoveryServices.NetworkMappingClient.Get(ctx, *id) + if err != nil { + return nil, fmt.Errorf("reading Recovery Service Network Mapping %q: %+v", id, err) + } + if resp.Model == nil { + return nil, fmt.Errorf("retrieving Recovery Service Network Mapping %q: `model` was nil", id) + } + + return utils.Bool(resp.Model.Id != nil), nil +} diff --git a/internal/services/recoveryservices/site_recovery_hyperv_replication_policy_association_resource.go b/internal/services/recoveryservices/site_recovery_hyperv_replication_policy_association_resource.go index 7ae2ab644f3e..060f333cb6c0 100644 --- a/internal/services/recoveryservices/site_recovery_hyperv_replication_policy_association_resource.go +++ b/internal/services/recoveryservices/site_recovery_hyperv_replication_policy_association_resource.go @@ -40,12 +40,14 @@ func (h HyperVReplicationPolicyAssociationResource) Arguments() map[string]*plug ForceNew: true, ValidateFunc: validation.StringIsNotEmpty, }, + "hyperv_site_id": { Type: pluginsdk.TypeString, Required: true, ForceNew: true, ValidateFunc: replicationfabrics.ValidateReplicationFabricID, }, + "policy_id": { Type: pluginsdk.TypeString, Required: true, diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2022-10-01/replicationnetworks/README.md b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2022-10-01/replicationnetworks/README.md new file mode 100644 index 000000000000..b456770604c2 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2022-10-01/replicationnetworks/README.md @@ -0,0 +1,70 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2022-10-01/replicationnetworks` Documentation + +The `replicationnetworks` SDK allows for interaction with the Azure Resource Manager Service `recoveryservicessiterecovery` (API Version `2022-10-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2022-10-01/replicationnetworks" +``` + + +### Client Initialization + +```go +client := replicationnetworks.NewReplicationNetworksClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `ReplicationNetworksClient.Get` + +```go +ctx := context.TODO() +id := replicationnetworks.NewReplicationNetworkID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue", "replicationFabricValue", "replicationNetworkValue") + +read, err := client.Get(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ReplicationNetworksClient.List` + +```go +ctx := context.TODO() +id := replicationnetworks.NewVaultID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue") + +// alternatively `client.List(ctx, id)` can be used to do batched pagination +items, err := client.ListComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `ReplicationNetworksClient.ListByReplicationFabrics` + +```go +ctx := context.TODO() +id := replicationnetworks.NewReplicationFabricID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue", "replicationFabricValue") + +// alternatively `client.ListByReplicationFabrics(ctx, id)` can be used to do batched pagination +items, err := client.ListByReplicationFabricsComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2022-10-01/replicationnetworks/client.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2022-10-01/replicationnetworks/client.go new file mode 100644 index 000000000000..13a853fab010 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2022-10-01/replicationnetworks/client.go @@ -0,0 +1,18 @@ +package replicationnetworks + +import "github.com/Azure/go-autorest/autorest" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ReplicationNetworksClient struct { + Client autorest.Client + baseUri string +} + +func NewReplicationNetworksClientWithBaseURI(endpoint string) ReplicationNetworksClient { + return ReplicationNetworksClient{ + Client: autorest.NewClientWithUserAgent(userAgent()), + baseUri: endpoint, + } +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2022-10-01/replicationnetworks/id_replicationfabric.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2022-10-01/replicationnetworks/id_replicationfabric.go new file mode 100644 index 000000000000..73c02b723eee --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2022-10-01/replicationnetworks/id_replicationfabric.go @@ -0,0 +1,140 @@ +package replicationnetworks + +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 = ReplicationFabricId{} + +// ReplicationFabricId is a struct representing the Resource ID for a Replication Fabric +type ReplicationFabricId struct { + SubscriptionId string + ResourceGroupName string + VaultName string + ReplicationFabricName string +} + +// NewReplicationFabricID returns a new ReplicationFabricId struct +func NewReplicationFabricID(subscriptionId string, resourceGroupName string, vaultName string, replicationFabricName string) ReplicationFabricId { + return ReplicationFabricId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + VaultName: vaultName, + ReplicationFabricName: replicationFabricName, + } +} + +// ParseReplicationFabricID parses 'input' into a ReplicationFabricId +func ParseReplicationFabricID(input string) (*ReplicationFabricId, error) { + parser := resourceids.NewParserFromResourceIdType(ReplicationFabricId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := ReplicationFabricId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", *parsed) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", *parsed) + } + + if id.VaultName, ok = parsed.Parsed["vaultName"]; !ok { + return nil, resourceids.NewSegmentNotSpecifiedError(id, "vaultName", *parsed) + } + + if id.ReplicationFabricName, ok = parsed.Parsed["replicationFabricName"]; !ok { + return nil, resourceids.NewSegmentNotSpecifiedError(id, "replicationFabricName", *parsed) + } + + return &id, nil +} + +// ParseReplicationFabricIDInsensitively parses 'input' case-insensitively into a ReplicationFabricId +// note: this method should only be used for API response data and not user input +func ParseReplicationFabricIDInsensitively(input string) (*ReplicationFabricId, error) { + parser := resourceids.NewParserFromResourceIdType(ReplicationFabricId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := ReplicationFabricId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", *parsed) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", *parsed) + } + + if id.VaultName, ok = parsed.Parsed["vaultName"]; !ok { + return nil, resourceids.NewSegmentNotSpecifiedError(id, "vaultName", *parsed) + } + + if id.ReplicationFabricName, ok = parsed.Parsed["replicationFabricName"]; !ok { + return nil, resourceids.NewSegmentNotSpecifiedError(id, "replicationFabricName", *parsed) + } + + return &id, nil +} + +// ValidateReplicationFabricID checks that 'input' can be parsed as a Replication Fabric ID +func ValidateReplicationFabricID(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 := ParseReplicationFabricID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Replication Fabric ID +func (id ReplicationFabricId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.RecoveryServices/vaults/%s/replicationFabrics/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.VaultName, id.ReplicationFabricName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Replication Fabric ID +func (id ReplicationFabricId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftRecoveryServices", "Microsoft.RecoveryServices", "Microsoft.RecoveryServices"), + resourceids.StaticSegment("staticVaults", "vaults", "vaults"), + resourceids.UserSpecifiedSegment("vaultName", "vaultValue"), + resourceids.StaticSegment("staticReplicationFabrics", "replicationFabrics", "replicationFabrics"), + resourceids.UserSpecifiedSegment("replicationFabricName", "replicationFabricValue"), + } +} + +// String returns a human-readable description of this Replication Fabric ID +func (id ReplicationFabricId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Vault Name: %q", id.VaultName), + fmt.Sprintf("Replication Fabric Name: %q", id.ReplicationFabricName), + } + return fmt.Sprintf("Replication Fabric (%s)", strings.Join(components, "\n")) +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2022-10-01/replicationnetworks/id_replicationnetwork.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2022-10-01/replicationnetworks/id_replicationnetwork.go new file mode 100644 index 000000000000..e1869f6fb0d3 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2022-10-01/replicationnetworks/id_replicationnetwork.go @@ -0,0 +1,153 @@ +package replicationnetworks + +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 = ReplicationNetworkId{} + +// ReplicationNetworkId is a struct representing the Resource ID for a Replication Network +type ReplicationNetworkId struct { + SubscriptionId string + ResourceGroupName string + VaultName string + ReplicationFabricName string + ReplicationNetworkName string +} + +// NewReplicationNetworkID returns a new ReplicationNetworkId struct +func NewReplicationNetworkID(subscriptionId string, resourceGroupName string, vaultName string, replicationFabricName string, replicationNetworkName string) ReplicationNetworkId { + return ReplicationNetworkId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + VaultName: vaultName, + ReplicationFabricName: replicationFabricName, + ReplicationNetworkName: replicationNetworkName, + } +} + +// ParseReplicationNetworkID parses 'input' into a ReplicationNetworkId +func ParseReplicationNetworkID(input string) (*ReplicationNetworkId, error) { + parser := resourceids.NewParserFromResourceIdType(ReplicationNetworkId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := ReplicationNetworkId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", *parsed) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", *parsed) + } + + if id.VaultName, ok = parsed.Parsed["vaultName"]; !ok { + return nil, resourceids.NewSegmentNotSpecifiedError(id, "vaultName", *parsed) + } + + if id.ReplicationFabricName, ok = parsed.Parsed["replicationFabricName"]; !ok { + return nil, resourceids.NewSegmentNotSpecifiedError(id, "replicationFabricName", *parsed) + } + + if id.ReplicationNetworkName, ok = parsed.Parsed["replicationNetworkName"]; !ok { + return nil, resourceids.NewSegmentNotSpecifiedError(id, "replicationNetworkName", *parsed) + } + + return &id, nil +} + +// ParseReplicationNetworkIDInsensitively parses 'input' case-insensitively into a ReplicationNetworkId +// note: this method should only be used for API response data and not user input +func ParseReplicationNetworkIDInsensitively(input string) (*ReplicationNetworkId, error) { + parser := resourceids.NewParserFromResourceIdType(ReplicationNetworkId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := ReplicationNetworkId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", *parsed) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", *parsed) + } + + if id.VaultName, ok = parsed.Parsed["vaultName"]; !ok { + return nil, resourceids.NewSegmentNotSpecifiedError(id, "vaultName", *parsed) + } + + if id.ReplicationFabricName, ok = parsed.Parsed["replicationFabricName"]; !ok { + return nil, resourceids.NewSegmentNotSpecifiedError(id, "replicationFabricName", *parsed) + } + + if id.ReplicationNetworkName, ok = parsed.Parsed["replicationNetworkName"]; !ok { + return nil, resourceids.NewSegmentNotSpecifiedError(id, "replicationNetworkName", *parsed) + } + + return &id, nil +} + +// ValidateReplicationNetworkID checks that 'input' can be parsed as a Replication Network ID +func ValidateReplicationNetworkID(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 := ParseReplicationNetworkID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Replication Network ID +func (id ReplicationNetworkId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.RecoveryServices/vaults/%s/replicationFabrics/%s/replicationNetworks/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.VaultName, id.ReplicationFabricName, id.ReplicationNetworkName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Replication Network ID +func (id ReplicationNetworkId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftRecoveryServices", "Microsoft.RecoveryServices", "Microsoft.RecoveryServices"), + resourceids.StaticSegment("staticVaults", "vaults", "vaults"), + resourceids.UserSpecifiedSegment("vaultName", "vaultValue"), + resourceids.StaticSegment("staticReplicationFabrics", "replicationFabrics", "replicationFabrics"), + resourceids.UserSpecifiedSegment("replicationFabricName", "replicationFabricValue"), + resourceids.StaticSegment("staticReplicationNetworks", "replicationNetworks", "replicationNetworks"), + resourceids.UserSpecifiedSegment("replicationNetworkName", "replicationNetworkValue"), + } +} + +// String returns a human-readable description of this Replication Network ID +func (id ReplicationNetworkId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Vault Name: %q", id.VaultName), + fmt.Sprintf("Replication Fabric Name: %q", id.ReplicationFabricName), + fmt.Sprintf("Replication Network Name: %q", id.ReplicationNetworkName), + } + return fmt.Sprintf("Replication Network (%s)", strings.Join(components, "\n")) +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2022-10-01/replicationnetworks/id_vault.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2022-10-01/replicationnetworks/id_vault.go new file mode 100644 index 000000000000..0bfde13c55de --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2022-10-01/replicationnetworks/id_vault.go @@ -0,0 +1,127 @@ +package replicationnetworks + +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 = VaultId{} + +// VaultId is a struct representing the Resource ID for a Vault +type VaultId struct { + SubscriptionId string + ResourceGroupName string + VaultName string +} + +// NewVaultID returns a new VaultId struct +func NewVaultID(subscriptionId string, resourceGroupName string, vaultName string) VaultId { + return VaultId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + VaultName: vaultName, + } +} + +// ParseVaultID parses 'input' into a VaultId +func ParseVaultID(input string) (*VaultId, error) { + parser := resourceids.NewParserFromResourceIdType(VaultId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := VaultId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", *parsed) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", *parsed) + } + + if id.VaultName, ok = parsed.Parsed["vaultName"]; !ok { + return nil, resourceids.NewSegmentNotSpecifiedError(id, "vaultName", *parsed) + } + + return &id, nil +} + +// ParseVaultIDInsensitively parses 'input' case-insensitively into a VaultId +// note: this method should only be used for API response data and not user input +func ParseVaultIDInsensitively(input string) (*VaultId, error) { + parser := resourceids.NewParserFromResourceIdType(VaultId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := VaultId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", *parsed) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", *parsed) + } + + if id.VaultName, ok = parsed.Parsed["vaultName"]; !ok { + return nil, resourceids.NewSegmentNotSpecifiedError(id, "vaultName", *parsed) + } + + return &id, nil +} + +// ValidateVaultID checks that 'input' can be parsed as a Vault ID +func ValidateVaultID(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 := ParseVaultID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Vault ID +func (id VaultId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.RecoveryServices/vaults/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.VaultName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Vault ID +func (id VaultId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftRecoveryServices", "Microsoft.RecoveryServices", "Microsoft.RecoveryServices"), + resourceids.StaticSegment("staticVaults", "vaults", "vaults"), + resourceids.UserSpecifiedSegment("vaultName", "vaultValue"), + } +} + +// String returns a human-readable description of this Vault ID +func (id VaultId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Vault Name: %q", id.VaultName), + } + return fmt.Sprintf("Vault (%s)", strings.Join(components, "\n")) +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2022-10-01/replicationnetworks/method_get_autorest.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2022-10-01/replicationnetworks/method_get_autorest.go new file mode 100644 index 000000000000..38146e2d3d53 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2022-10-01/replicationnetworks/method_get_autorest.go @@ -0,0 +1,68 @@ +package replicationnetworks + +import ( + "context" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + Model *Network +} + +// Get ... +func (c ReplicationNetworksClient) Get(ctx context.Context, id ReplicationNetworkId) (result GetOperationResponse, err error) { + req, err := c.preparerForGet(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationnetworks.ReplicationNetworksClient", "Get", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationnetworks.ReplicationNetworksClient", "Get", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForGet(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationnetworks.ReplicationNetworksClient", "Get", result.HttpResponse, "Failure responding to request") + return + } + + return +} + +// preparerForGet prepares the Get request. +func (c ReplicationNetworksClient) preparerForGet(ctx context.Context, id ReplicationNetworkId) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(id.ID()), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForGet handles the response to the Get request. The method always +// closes the http.Response Body. +func (c ReplicationNetworksClient) responderForGet(resp *http.Response) (result GetOperationResponse, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result.Model), + autorest.ByClosing()) + result.HttpResponse = resp + + return +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2022-10-01/replicationnetworks/method_list_autorest.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2022-10-01/replicationnetworks/method_list_autorest.go new file mode 100644 index 000000000000..075aca6607d8 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2022-10-01/replicationnetworks/method_list_autorest.go @@ -0,0 +1,186 @@ +package replicationnetworks + +import ( + "context" + "fmt" + "net/http" + "net/url" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListOperationResponse struct { + HttpResponse *http.Response + Model *[]Network + + nextLink *string + nextPageFunc func(ctx context.Context, nextLink string) (ListOperationResponse, error) +} + +type ListCompleteResult struct { + Items []Network +} + +func (r ListOperationResponse) HasMore() bool { + return r.nextLink != nil +} + +func (r ListOperationResponse) LoadMore(ctx context.Context) (resp ListOperationResponse, err error) { + if !r.HasMore() { + err = fmt.Errorf("no more pages returned") + return + } + return r.nextPageFunc(ctx, *r.nextLink) +} + +// List ... +func (c ReplicationNetworksClient) List(ctx context.Context, id VaultId) (resp ListOperationResponse, err error) { + req, err := c.preparerForList(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationnetworks.ReplicationNetworksClient", "List", nil, "Failure preparing request") + return + } + + resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationnetworks.ReplicationNetworksClient", "List", resp.HttpResponse, "Failure sending request") + return + } + + resp, err = c.responderForList(resp.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationnetworks.ReplicationNetworksClient", "List", resp.HttpResponse, "Failure responding to request") + return + } + return +} + +// preparerForList prepares the List request. +func (c ReplicationNetworksClient) preparerForList(ctx context.Context, id VaultId) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(fmt.Sprintf("%s/replicationNetworks", id.ID())), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// preparerForListWithNextLink prepares the List request with the given nextLink token. +func (c ReplicationNetworksClient) preparerForListWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { + uri, err := url.Parse(nextLink) + if err != nil { + return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) + } + queryParameters := map[string]interface{}{} + for k, v := range uri.Query() { + if len(v) == 0 { + continue + } + val := v[0] + val = autorest.Encode("query", val) + queryParameters[k] = val + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(uri.Path), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForList handles the response to the List request. The method always +// closes the http.Response Body. +func (c ReplicationNetworksClient) responderForList(resp *http.Response) (result ListOperationResponse, err error) { + type page struct { + Values []Network `json:"value"` + NextLink *string `json:"nextLink"` + } + var respObj page + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&respObj), + autorest.ByClosing()) + result.HttpResponse = resp + result.Model = &respObj.Values + result.nextLink = respObj.NextLink + if respObj.NextLink != nil { + result.nextPageFunc = func(ctx context.Context, nextLink string) (result ListOperationResponse, err error) { + req, err := c.preparerForListWithNextLink(ctx, nextLink) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationnetworks.ReplicationNetworksClient", "List", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationnetworks.ReplicationNetworksClient", "List", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForList(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationnetworks.ReplicationNetworksClient", "List", result.HttpResponse, "Failure responding to request") + return + } + + return + } + } + return +} + +// ListComplete retrieves all of the results into a single object +func (c ReplicationNetworksClient) ListComplete(ctx context.Context, id VaultId) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, NetworkOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all of the results and then applied the predicate +func (c ReplicationNetworksClient) ListCompleteMatchingPredicate(ctx context.Context, id VaultId, predicate NetworkOperationPredicate) (resp ListCompleteResult, err error) { + items := make([]Network, 0) + + page, err := c.List(ctx, id) + if err != nil { + err = fmt.Errorf("loading the initial page: %+v", err) + return + } + if page.Model != nil { + for _, v := range *page.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + for page.HasMore() { + page, err = page.LoadMore(ctx) + if err != nil { + err = fmt.Errorf("loading the next page: %+v", err) + return + } + + if page.Model != nil { + for _, v := range *page.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + } + + out := ListCompleteResult{ + Items: items, + } + return out, nil +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2022-10-01/replicationnetworks/method_listbyreplicationfabrics_autorest.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2022-10-01/replicationnetworks/method_listbyreplicationfabrics_autorest.go new file mode 100644 index 000000000000..e9d8ef73e15c --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2022-10-01/replicationnetworks/method_listbyreplicationfabrics_autorest.go @@ -0,0 +1,186 @@ +package replicationnetworks + +import ( + "context" + "fmt" + "net/http" + "net/url" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListByReplicationFabricsOperationResponse struct { + HttpResponse *http.Response + Model *[]Network + + nextLink *string + nextPageFunc func(ctx context.Context, nextLink string) (ListByReplicationFabricsOperationResponse, error) +} + +type ListByReplicationFabricsCompleteResult struct { + Items []Network +} + +func (r ListByReplicationFabricsOperationResponse) HasMore() bool { + return r.nextLink != nil +} + +func (r ListByReplicationFabricsOperationResponse) LoadMore(ctx context.Context) (resp ListByReplicationFabricsOperationResponse, err error) { + if !r.HasMore() { + err = fmt.Errorf("no more pages returned") + return + } + return r.nextPageFunc(ctx, *r.nextLink) +} + +// ListByReplicationFabrics ... +func (c ReplicationNetworksClient) ListByReplicationFabrics(ctx context.Context, id ReplicationFabricId) (resp ListByReplicationFabricsOperationResponse, err error) { + req, err := c.preparerForListByReplicationFabrics(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationnetworks.ReplicationNetworksClient", "ListByReplicationFabrics", nil, "Failure preparing request") + return + } + + resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationnetworks.ReplicationNetworksClient", "ListByReplicationFabrics", resp.HttpResponse, "Failure sending request") + return + } + + resp, err = c.responderForListByReplicationFabrics(resp.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationnetworks.ReplicationNetworksClient", "ListByReplicationFabrics", resp.HttpResponse, "Failure responding to request") + return + } + return +} + +// preparerForListByReplicationFabrics prepares the ListByReplicationFabrics request. +func (c ReplicationNetworksClient) preparerForListByReplicationFabrics(ctx context.Context, id ReplicationFabricId) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(fmt.Sprintf("%s/replicationNetworks", id.ID())), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// preparerForListByReplicationFabricsWithNextLink prepares the ListByReplicationFabrics request with the given nextLink token. +func (c ReplicationNetworksClient) preparerForListByReplicationFabricsWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { + uri, err := url.Parse(nextLink) + if err != nil { + return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) + } + queryParameters := map[string]interface{}{} + for k, v := range uri.Query() { + if len(v) == 0 { + continue + } + val := v[0] + val = autorest.Encode("query", val) + queryParameters[k] = val + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(uri.Path), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForListByReplicationFabrics handles the response to the ListByReplicationFabrics request. The method always +// closes the http.Response Body. +func (c ReplicationNetworksClient) responderForListByReplicationFabrics(resp *http.Response) (result ListByReplicationFabricsOperationResponse, err error) { + type page struct { + Values []Network `json:"value"` + NextLink *string `json:"nextLink"` + } + var respObj page + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&respObj), + autorest.ByClosing()) + result.HttpResponse = resp + result.Model = &respObj.Values + result.nextLink = respObj.NextLink + if respObj.NextLink != nil { + result.nextPageFunc = func(ctx context.Context, nextLink string) (result ListByReplicationFabricsOperationResponse, err error) { + req, err := c.preparerForListByReplicationFabricsWithNextLink(ctx, nextLink) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationnetworks.ReplicationNetworksClient", "ListByReplicationFabrics", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationnetworks.ReplicationNetworksClient", "ListByReplicationFabrics", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForListByReplicationFabrics(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationnetworks.ReplicationNetworksClient", "ListByReplicationFabrics", result.HttpResponse, "Failure responding to request") + return + } + + return + } + } + return +} + +// ListByReplicationFabricsComplete retrieves all of the results into a single object +func (c ReplicationNetworksClient) ListByReplicationFabricsComplete(ctx context.Context, id ReplicationFabricId) (ListByReplicationFabricsCompleteResult, error) { + return c.ListByReplicationFabricsCompleteMatchingPredicate(ctx, id, NetworkOperationPredicate{}) +} + +// ListByReplicationFabricsCompleteMatchingPredicate retrieves all of the results and then applied the predicate +func (c ReplicationNetworksClient) ListByReplicationFabricsCompleteMatchingPredicate(ctx context.Context, id ReplicationFabricId, predicate NetworkOperationPredicate) (resp ListByReplicationFabricsCompleteResult, err error) { + items := make([]Network, 0) + + page, err := c.ListByReplicationFabrics(ctx, id) + if err != nil { + err = fmt.Errorf("loading the initial page: %+v", err) + return + } + if page.Model != nil { + for _, v := range *page.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + for page.HasMore() { + page, err = page.LoadMore(ctx) + if err != nil { + err = fmt.Errorf("loading the next page: %+v", err) + return + } + + if page.Model != nil { + for _, v := range *page.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + } + + out := ListByReplicationFabricsCompleteResult{ + Items: items, + } + return out, nil +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2022-10-01/replicationnetworks/model_network.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2022-10-01/replicationnetworks/model_network.go new file mode 100644 index 000000000000..a55b39eacf2e --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2022-10-01/replicationnetworks/model_network.go @@ -0,0 +1,12 @@ +package replicationnetworks + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type Network struct { + Id *string `json:"id,omitempty"` + Location *string `json:"location,omitempty"` + Name *string `json:"name,omitempty"` + Properties *NetworkProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2022-10-01/replicationnetworks/model_networkproperties.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2022-10-01/replicationnetworks/model_networkproperties.go new file mode 100644 index 000000000000..7a2c7204a97c --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2022-10-01/replicationnetworks/model_networkproperties.go @@ -0,0 +1,11 @@ +package replicationnetworks + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type NetworkProperties struct { + FabricType *string `json:"fabricType,omitempty"` + FriendlyName *string `json:"friendlyName,omitempty"` + NetworkType *string `json:"networkType,omitempty"` + Subnets *[]Subnet `json:"subnets,omitempty"` +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2022-10-01/replicationnetworks/model_subnet.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2022-10-01/replicationnetworks/model_subnet.go new file mode 100644 index 000000000000..fed1f4919d87 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2022-10-01/replicationnetworks/model_subnet.go @@ -0,0 +1,10 @@ +package replicationnetworks + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type Subnet struct { + AddressList *[]string `json:"addressList,omitempty"` + FriendlyName *string `json:"friendlyName,omitempty"` + Name *string `json:"name,omitempty"` +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2022-10-01/replicationnetworks/predicates.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2022-10-01/replicationnetworks/predicates.go new file mode 100644 index 000000000000..7cf85d61c5a4 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2022-10-01/replicationnetworks/predicates.go @@ -0,0 +1,32 @@ +package replicationnetworks + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type NetworkOperationPredicate struct { + Id *string + Location *string + Name *string + Type *string +} + +func (p NetworkOperationPredicate) Matches(input Network) bool { + + if p.Id != nil && (input.Id == nil && *p.Id != *input.Id) { + return false + } + + if p.Location != nil && (input.Location == nil && *p.Location != *input.Location) { + return false + } + + if p.Name != nil && (input.Name == nil && *p.Name != *input.Name) { + return false + } + + if p.Type != nil && (input.Type == nil && *p.Type != *input.Type) { + return false + } + + return true +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2022-10-01/replicationnetworks/version.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2022-10-01/replicationnetworks/version.go new file mode 100644 index 000000000000..414d543ac3c2 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2022-10-01/replicationnetworks/version.go @@ -0,0 +1,12 @@ +package replicationnetworks + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2022-10-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/replicationnetworks/%s", defaultApiVersion) +} diff --git a/vendor/modules.txt b/vendor/modules.txt index cba4d7ff4dcc..e0f5b8e3258c 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -516,6 +516,7 @@ github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicesbackup/2023-0 github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicesbackup/2023-02-01/protectionpolicies 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/replicationnetworkmappings +github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2022-10-01/replicationnetworks github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2022-10-01/replicationpolicies github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2022-10-01/replicationprotecteditems github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2022-10-01/replicationprotectioncontainermappings diff --git a/website/docs/r/site_recovery_hyperv_network_mapping.html.markdown b/website/docs/r/site_recovery_hyperv_network_mapping.html.markdown new file mode 100644 index 000000000000..eff03603dee4 --- /dev/null +++ b/website/docs/r/site_recovery_hyperv_network_mapping.html.markdown @@ -0,0 +1,83 @@ +--- +subcategory: "Recovery Services" +layout: "azurerm" +page_title: "Azure Resource Manager: azurerm_site_recovery_hyperv_network_mapping" +description: |- + Manages a HyperV site recovery network mapping on Azure. +--- + +# azurerm_site_recovery_hyperv_network_mapping + +Manages a HyperV site recovery network mapping on Azure. A network mapping decides how to translate connected networks when a VM is migrated from HyperV VMM Center to Azure. + +## Example Usage + +```hcl +provider "azurerm" { + features {} +} + +resource "azurerm_resource_group" "target" { + name = "tfex-network-mapping" + location = "East US" +} + +resource "azurerm_recovery_services_vault" "vault" { + name = "example-recovery-vault" + location = azurerm_resource_group.target.location + resource_group_name = azurerm_resource_group.target.name + sku = "Standard" +} + +resource "azurerm_virtual_network" "target" { + name = "network" + resource_group_name = azurerm_resource_group.target.name + address_space = ["192.168.2.0/24"] + location = azurerm_resource_group.target.location +} + +resource "azurerm_site_recovery_network_mapping" "recovery-mapping" { + name = "recovery-network-mapping" + recovery_vault_id = azurerm_recovery_services_vault.vault.id + source_system_center_virtual_machine_manager_name = "my-vmm-server" + source_network_name = "my-vmm-network" + target_network_id = azurerm_virtual_network.target.id +} +``` + +## Argument Reference + +The following arguments are supported: + +* `name` - (Required) The name of the network mapping. Changing this forces a new resource to be created. + +* `recovery_vault_id` - (Required) The ID of the Recovery Services Vault where the network mapping should be created. Changing this forces a new resource to be created. + +* `source_system_center_virtual_machine_manager_name` - (Required) Specifies the name of source System Center Virtual Machine Manager where the source network exists. Changing this forces a new resource to be created. + +* `source_network_name` - (Required) The Name of the primary network. Changing this forces a new resource to be created. + +* `target_network_id` - (Required) The id of the recovery network. Changing this forces a new resource to be created. + +## Attributes Reference + +In addition to the arguments above, the following attributes are exported: + +* `id` - The ID of the Site Recovery Network Mapping. + +## Timeouts + +The `timeouts` block allows you to specify [timeouts](https://www.terraform.io/language/resources/syntax#operation-timeouts) for certain actions: + +* `create` - (Defaults to 30 minutes) Used when creating the Site Recovery Network Mapping. +* `update` - (Defaults to 30 minutes) Used when updating the Site Recovery Network Mapping. +* `read` - (Defaults to 5 minutes) Used when retrieving the Site Recovery Network Mapping. +* `delete` - (Defaults to 30 minutes) Used when deleting the Site Recovery Network Mapping. + +## Import + +Site Recovery Network Mapping can be imported using the `resource id`, e.g. + +```shell +terraform import azurerm_site_recovery_network_mapping.mymapping /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resource-group-name/providers/Microsoft.RecoveryServices/vaults/recovery-vault-name/replicationFabrics/primary-fabric-name/replicationNetworks/azureNetwork/replicationNetworkMappings/mapping-name +```