-
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_replication_recovery_plan
;New D…
…ata Source: `azurerm_site_recovery_replication_recovery_plan` (#19940)
- Loading branch information
Showing
7 changed files
with
1,418 additions
and
1 deletion.
There are no files selected for viewing
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
200 changes: 200 additions & 0 deletions
200
internal/services/recoveryservices/site_recovery_replication_recovery_plan_data_source.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,200 @@ | ||
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/replicationrecoveryplans" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||
"github.com/hashicorp/terraform-provider-azurerm/internal/sdk" | ||
"github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk" | ||
"github.com/hashicorp/terraform-provider-azurerm/internal/tf/validation" | ||
) | ||
|
||
type SiteRecoveryReplicationRecoveryPlanDataSource struct{} | ||
|
||
var _ sdk.DataSource = SiteRecoveryReplicationRecoveryPlanDataSource{} | ||
|
||
func (r SiteRecoveryReplicationRecoveryPlanDataSource) ResourceType() string { | ||
return "azurerm_site_recovery_replication_recovery_plan" | ||
} | ||
|
||
func (r SiteRecoveryReplicationRecoveryPlanDataSource) ModelObject() interface{} { | ||
return &SiteRecoveryReplicationRecoveryPlanModel{} | ||
} | ||
|
||
func (r SiteRecoveryReplicationRecoveryPlanDataSource) IDValidationFunc() pluginsdk.SchemaValidateFunc { | ||
return replicationrecoveryplans.ValidateReplicationRecoveryPlanID | ||
} | ||
|
||
func (r SiteRecoveryReplicationRecoveryPlanDataSource) Read() sdk.ResourceFunc { | ||
return sdk.ResourceFunc{ | ||
Timeout: 5 * time.Minute, | ||
Func: func(ctx context.Context, metadata sdk.ResourceMetaData) error { | ||
var metaModel SiteRecoveryReplicationRecoveryPlanModel | ||
if err := metadata.Decode(&metaModel); err != nil { | ||
return fmt.Errorf("decoding %+v", err) | ||
} | ||
|
||
client := metadata.Client.RecoveryServices.ReplicationRecoveryPlansClient | ||
subscriptionId := metadata.Client.Account.SubscriptionId | ||
|
||
vaultId, err := replicationrecoveryplans.ParseVaultID(metaModel.RecoveryVaultId) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
id := replicationrecoveryplans.NewReplicationRecoveryPlanID(subscriptionId, vaultId.ResourceGroupName, vaultId.ResourceName, metaModel.Name) | ||
|
||
resp, err := client.Get(ctx, id) | ||
if err != nil { | ||
if response.WasNotFound(resp.HttpResponse) { | ||
return metadata.MarkAsGone(id) | ||
} | ||
return fmt.Errorf("making Read request on site recovery replication plan %s : %+v", id.String(), err) | ||
} | ||
|
||
model := resp.Model | ||
if model == nil { | ||
return fmt.Errorf("making Read request on site recovery replication plan %s : model is nil", id.String()) | ||
} | ||
|
||
state := SiteRecoveryReplicationRecoveryPlanModel{ | ||
Name: id.RecoveryPlanName, | ||
RecoveryVaultId: vaultId.ID(), | ||
} | ||
|
||
if prop := model.Properties; prop != nil { | ||
if prop.PrimaryFabricId != nil { | ||
state.SourceRecoveryFabricId = handleAzureSdkForGoBug2824(*prop.PrimaryFabricId) | ||
} | ||
if prop.RecoveryFabricId != nil { | ||
state.TargetRecoveryFabricId = handleAzureSdkForGoBug2824(*prop.RecoveryFabricId) | ||
} | ||
|
||
if group := prop.Groups; group != nil { | ||
state.RecoveryGroup = flattenRecoveryGroups(*group) | ||
} | ||
} | ||
|
||
metadata.SetID(id) | ||
return metadata.Encode(&state) | ||
}, | ||
} | ||
|
||
} | ||
|
||
func (r SiteRecoveryReplicationRecoveryPlanDataSource) Arguments() map[string]*pluginsdk.Schema { | ||
return map[string]*pluginsdk.Schema{ | ||
"name": { | ||
Type: pluginsdk.TypeString, | ||
Required: true, | ||
ValidateFunc: validation.StringIsNotEmpty, | ||
}, | ||
|
||
"recovery_vault_id": { | ||
Type: pluginsdk.TypeString, | ||
Required: true, | ||
ValidateFunc: replicationrecoveryplans.ValidateVaultID, | ||
}, | ||
} | ||
} | ||
|
||
func (r SiteRecoveryReplicationRecoveryPlanDataSource) Attributes() map[string]*pluginsdk.Schema { | ||
return map[string]*pluginsdk.Schema{ | ||
"source_recovery_fabric_id": { | ||
Type: pluginsdk.TypeString, | ||
Computed: true, | ||
}, | ||
|
||
"target_recovery_fabric_id": { | ||
Type: pluginsdk.TypeString, | ||
Computed: true, | ||
}, | ||
|
||
"failover_deployment_model": { | ||
Type: pluginsdk.TypeString, | ||
Computed: true, | ||
}, | ||
|
||
"recovery_group": { | ||
Type: pluginsdk.TypeSet, | ||
Computed: true, | ||
Elem: &pluginsdk.Resource{ | ||
Schema: map[string]*pluginsdk.Schema{ | ||
"type": { | ||
Type: pluginsdk.TypeString, | ||
Computed: true, | ||
}, | ||
"replicated_protected_items": { | ||
Type: pluginsdk.TypeList, | ||
Computed: true, | ||
Elem: &pluginsdk.Schema{ | ||
Type: pluginsdk.TypeString, | ||
}, | ||
}, | ||
"pre_action": { | ||
Type: pluginsdk.TypeSet, | ||
Computed: true, | ||
Elem: dataSourceSiteRecoveryReplicationPlanActions(), | ||
}, | ||
"post_action": { | ||
Type: pluginsdk.TypeSet, | ||
Computed: true, | ||
Elem: dataSourceSiteRecoveryReplicationPlanActions(), | ||
}, | ||
}, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func dataSourceSiteRecoveryReplicationPlanActions() *pluginsdk.Schema { | ||
return &pluginsdk.Schema{ | ||
Type: pluginsdk.TypeList, | ||
Elem: &pluginsdk.Resource{ | ||
Schema: map[string]*schema.Schema{ | ||
"name": { | ||
Type: pluginsdk.TypeString, | ||
Computed: true, | ||
}, | ||
"type": { | ||
Type: pluginsdk.TypeString, | ||
Computed: true, | ||
}, | ||
"fail_over_directions": { | ||
Type: pluginsdk.TypeSet, | ||
Computed: true, | ||
Elem: &pluginsdk.Schema{ | ||
Type: pluginsdk.TypeString, | ||
}, | ||
}, | ||
"fail_over_types": { | ||
Type: pluginsdk.TypeSet, | ||
Computed: true, | ||
Elem: &pluginsdk.Schema{ | ||
Type: pluginsdk.TypeString, | ||
}, | ||
}, | ||
"runbook_id": { | ||
Type: pluginsdk.TypeString, | ||
Computed: true, | ||
}, | ||
"fabric_location": { | ||
Type: pluginsdk.TypeString, | ||
Computed: true, | ||
}, | ||
"manual_action_instruction": { | ||
Type: pluginsdk.TypeString, | ||
Computed: true, | ||
}, | ||
"script_path": { | ||
Type: pluginsdk.TypeString, | ||
Computed: true, | ||
}, | ||
}, | ||
}, | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
...nal/services/recoveryservices/site_recovery_replication_recovery_plan_data_source_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,42 @@ | ||
package recoveryservices_test | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform-provider-azurerm/internal/acceptance" | ||
"github.com/hashicorp/terraform-provider-azurerm/internal/acceptance/check" | ||
) | ||
|
||
type SiteRecoveryReplicationRecoveryPlanDataSource struct{} | ||
|
||
func TestAccDataSourceSiteRecoveryReplicationRecoveryPlan_basic(t *testing.T) { | ||
data := acceptance.BuildTestData(t, "azurerm_site_recovery_replication_recovery_plan", "test") | ||
r := SiteRecoveryReplicationRecoveryPlanDataSource{} | ||
|
||
data.DataSourceTest(t, []acceptance.TestStep{ | ||
{ | ||
Config: r.basic(data), | ||
Check: acceptance.ComposeTestCheckFunc( | ||
check.That(data.ResourceName).Key("name").Exists(), | ||
check.That(data.ResourceName).Key("recovery_vault_id").Exists(), | ||
check.That(data.ResourceName).Key("source_recovery_fabric_id").Exists(), | ||
check.That(data.ResourceName).Key("target_recovery_fabric_id").Exists(), | ||
check.That(data.ResourceName).Key("recovery_group.0.type").HasValue("Boot"), | ||
check.That(data.ResourceName).Key("recovery_group.1.type").HasValue("Failover"), | ||
check.That(data.ResourceName).Key("recovery_group.2.type").HasValue("Shutdown"), | ||
), | ||
}, | ||
}) | ||
} | ||
|
||
func (SiteRecoveryReplicationRecoveryPlanDataSource) basic(data acceptance.TestData) string { | ||
return fmt.Sprintf(` | ||
%s | ||
data "azurerm_site_recovery_replication_recovery_plan" "test" { | ||
name = azurerm_site_recovery_replication_recovery_plan.test.name | ||
recovery_vault_id = azurerm_site_recovery_replication_recovery_plan.test.recovery_vault_id | ||
} | ||
`, SiteRecoveryReplicationRecoveryPlan{}.basic(data)) | ||
} |
Oops, something went wrong.