-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New Resource:
azurerm_site_recovery_services_vault_hyperv_site
- Loading branch information
Showing
41 changed files
with
2,530 additions
and
0 deletions.
There are no files selected for viewing
155 changes: 155 additions & 0 deletions
155
internal/services/recoveryservices/recovery_services_vault_hyperv_site_resource.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,155 @@ | ||
package recoveryservices | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"time" | ||
|
||
"github.com/hashicorp/go-azure-helpers/lang/response" | ||
"github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2022-10-01/replicationfabrics" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" | ||
"github.com/hashicorp/terraform-provider-azurerm/internal/sdk" | ||
"github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk" | ||
) | ||
|
||
type HyperVSiteModel struct { | ||
Name string `tfschema:"name"` | ||
RecoveryVaultId string `tfschema:"recovery_vault_id"` | ||
} | ||
|
||
type HyperVSiteResource struct{} | ||
|
||
var _ sdk.Resource = HyperVSiteResource{} | ||
|
||
func (r HyperVSiteResource) 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: replicationfabrics.ValidateVaultID, | ||
}, | ||
} | ||
} | ||
|
||
func (r HyperVSiteResource) Attributes() map[string]*schema.Schema { | ||
return map[string]*schema.Schema{} | ||
} | ||
|
||
func (r HyperVSiteResource) ModelObject() interface{} { | ||
return &HyperVSiteModel{} | ||
} | ||
|
||
func (r HyperVSiteResource) ResourceType() string { | ||
return "azurerm_site_recovery_services_vault_hyperv_site" | ||
} | ||
|
||
func (r HyperVSiteResource) Create() sdk.ResourceFunc { | ||
return sdk.ResourceFunc{ | ||
Timeout: 30 * time.Minute, | ||
Func: func(ctx context.Context, metadata sdk.ResourceMetaData) error { | ||
var metaModel HyperVSiteModel | ||
if err := metadata.Decode(&metaModel); err != nil { | ||
return fmt.Errorf("decoding %s", err) | ||
} | ||
|
||
client := metadata.Client.RecoveryServices.FabricClient | ||
subscriptionId := metadata.Client.Account.SubscriptionId | ||
|
||
vaultId, err := replicationfabrics.ParseVaultID(metaModel.RecoveryVaultId) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
id := replicationfabrics.NewReplicationFabricID(subscriptionId, vaultId.ResourceGroupName, vaultId.VaultName, metaModel.Name) | ||
|
||
type HyperVSiteInstanceType struct { | ||
InstanceType string `json:"instanceType"` | ||
} | ||
|
||
// the instance type `HyperVSite` is not exposed in Swagger, tracked on https://github.com/Azure/azure-rest-api-specs/issues/22016 | ||
parameters := replicationfabrics.FabricCreationInput{ | ||
Properties: &replicationfabrics.FabricCreationInputProperties{ | ||
CustomDetails: HyperVSiteInstanceType{ | ||
InstanceType: "HyperVSite", | ||
}, | ||
}, | ||
} | ||
|
||
err = client.CreateThenPoll(ctx, id, parameters) | ||
if err != nil { | ||
return fmt.Errorf("creating %s: %+v", id, err) | ||
} | ||
|
||
metadata.SetID(id) | ||
return nil | ||
}, | ||
} | ||
} | ||
|
||
func (r HyperVSiteResource) Read() sdk.ResourceFunc { | ||
return sdk.ResourceFunc{ | ||
Timeout: 5 * time.Minute, | ||
Func: func(ctx context.Context, metadata sdk.ResourceMetaData) error { | ||
client := metadata.Client.RecoveryServices.FabricClient | ||
id, err := replicationfabrics.ParseReplicationFabricID(metadata.ResourceData.Id()) | ||
if err != nil { | ||
return fmt.Errorf("parsing %s: %+v", metadata.ResourceData.Id(), err) | ||
} | ||
|
||
resp, err := client.Get(ctx, *id, replicationfabrics.DefaultGetOperationOptions()) | ||
if err != nil { | ||
if response.WasNotFound(resp.HttpResponse) { | ||
return metadata.MarkAsGone(id) | ||
} | ||
|
||
return fmt.Errorf("retrieving %s: %+v", id, err) | ||
} | ||
|
||
if resp.Model == nil { | ||
return fmt.Errorf("retrieving %s: `model` was nil", id) | ||
} | ||
|
||
state := HyperVSiteModel{ | ||
Name: id.ReplicationFabricName, | ||
} | ||
|
||
vaultId := replicationfabrics.NewVaultID(id.SubscriptionId, id.ResourceGroupName, id.VaultName) | ||
state.RecoveryVaultId = vaultId.ID() | ||
|
||
return metadata.Encode(&state) | ||
}, | ||
} | ||
} | ||
|
||
func (r HyperVSiteResource) Delete() sdk.ResourceFunc { | ||
return sdk.ResourceFunc{ | ||
Timeout: 30 * time.Minute, | ||
Func: func(ctx context.Context, metadata sdk.ResourceMetaData) error { | ||
client := metadata.Client.RecoveryServices.FabricClient | ||
id, err := replicationfabrics.ParseReplicationFabricID(metadata.ResourceData.Id()) | ||
if err != nil { | ||
return fmt.Errorf("parsing %s: %+v", metadata.ResourceData.Id(), err) | ||
} | ||
|
||
err = client.DeleteThenPoll(ctx, *id) | ||
if err != nil { | ||
return fmt.Errorf("creating %s: %+v", id, err) | ||
} | ||
|
||
return nil | ||
}, | ||
} | ||
} | ||
|
||
func (r HyperVSiteResource) IDValidationFunc() pluginsdk.SchemaValidateFunc { | ||
return replicationfabrics.ValidateReplicationFabricID | ||
} |
72 changes: 72 additions & 0 deletions
72
internal/services/recoveryservices/recovery_services_vault_hyperv_site_resource_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
package recoveryservices_test | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2022-10-01/replicationfabrics" | ||
"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 HyperVSiteResource struct{} | ||
|
||
func TestAccSiteRecoveryHyperVSite_basic(t *testing.T) { | ||
data := acceptance.BuildTestData(t, "azurerm_site_recovery_services_vault_hyperv_site", "test") | ||
r := HyperVSiteResource{} | ||
|
||
data.ResourceTest(t, r, []acceptance.TestStep{ | ||
{ | ||
Config: r.basic(data), | ||
Check: acceptance.ComposeTestCheckFunc( | ||
check.That(data.ResourceName).ExistsInAzure(r), | ||
), | ||
}, | ||
data.ImportStep(), | ||
}) | ||
} | ||
|
||
func (HyperVSiteResource) basic(data acceptance.TestData) string { | ||
return fmt.Sprintf(` | ||
provider "azurerm" { | ||
features {} | ||
} | ||
resource "azurerm_resource_group" "test" { | ||
name = "acctestRG-recovery-%[1]d" | ||
location = "%s" | ||
} | ||
resource "azurerm_recovery_services_vault" "test" { | ||
name = "acctest-vault-%[1]d" | ||
location = azurerm_resource_group.test.location | ||
resource_group_name = azurerm_resource_group.test.name | ||
sku = "Standard" | ||
soft_delete_enabled = false | ||
} | ||
resource "azurerm_site_recovery_services_vault_hyperv_site" "test" { | ||
recovery_vault_id = azurerm_recovery_services_vault.test.id | ||
name = "acctest-site-%[1]d" | ||
} | ||
`, data.RandomInteger, data.Locations.Primary) | ||
} | ||
|
||
func (t HyperVSiteResource) Exists(ctx context.Context, clients *clients.Client, state *pluginsdk.InstanceState) (*bool, error) { | ||
id, err := replicationfabrics.ParseReplicationFabricID(state.ID) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
resp, err := clients.RecoveryServices.FabricClient.Get(ctx, *id, replicationfabrics.DefaultGetOperationOptions()) | ||
if err != nil { | ||
return nil, fmt.Errorf("reading Recovery Service Vault (%s): %+v", id.String(), err) | ||
} | ||
|
||
return utils.Bool(resp.Model != nil), nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
...re-sdk/resource-manager/recoveryservices/2022-10-01/vaultcertificates/README.md
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
18 changes: 18 additions & 0 deletions
18
...orp/go-azure-sdk/resource-manager/recoveryservices/2022-10-01/vaultcertificates/client.go
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
43 changes: 43 additions & 0 deletions
43
.../go-azure-sdk/resource-manager/recoveryservices/2022-10-01/vaultcertificates/constants.go
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.