-
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.
Merge pull request #2974 from mcharriere/feat/recoveryservicepolicy
New Data Source: `azurerm_recovery_services_protection_policy_vm`
- Loading branch information
Showing
4 changed files
with
207 additions
and
65 deletions.
There are no files selected for viewing
58 changes: 58 additions & 0 deletions
58
azurerm/data_source_recovery_services_protection_policy_vm.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,58 @@ | ||
package azurerm | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
|
||
"github.com/hashicorp/terraform/helper/schema" | ||
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" | ||
) | ||
|
||
func dataSourceArmRecoveryServicesProtectionPolicyVm() *schema.Resource { | ||
return &schema.Resource{ | ||
Read: dataSourceArmRecoveryServicesProtectionPolicyVmRead, | ||
|
||
Schema: map[string]*schema.Schema{ | ||
"name": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
ForceNew: true, | ||
}, | ||
|
||
"recovery_vault_name": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
ForceNew: true, | ||
}, | ||
|
||
"resource_group_name": resourceGroupNameForDataSourceSchema(), | ||
|
||
"tags": tagsForDataSourceSchema(), | ||
}, | ||
} | ||
} | ||
|
||
func dataSourceArmRecoveryServicesProtectionPolicyVmRead(d *schema.ResourceData, meta interface{}) error { | ||
client := meta.(*ArmClient).recoveryServicesProtectionPoliciesClient | ||
ctx := meta.(*ArmClient).StopContext | ||
|
||
name := d.Get("name").(string) | ||
resourceGroup := d.Get("resource_group_name").(string) | ||
vaultName := d.Get("recovery_vault_name").(string) | ||
|
||
log.Printf("[DEBUG] Reading Recovery Service Protection Policy %q (resource group %q)", name, resourceGroup) | ||
|
||
protectionPolicy, err := client.Get(ctx, vaultName, resourceGroup, name) | ||
if err != nil { | ||
if utils.ResponseWasNotFound(protectionPolicy.Response) { | ||
return fmt.Errorf("Error: Recovery Services Protection Policy %q (Resource Group %q) was not found", name, resourceGroup) | ||
} | ||
|
||
return fmt.Errorf("Error making Read request on Recovery Service Protection Policy %q (Resource Group %q): %+v", name, resourceGroup, err) | ||
} | ||
|
||
d.SetId(*protectionPolicy.ID) | ||
|
||
flattenAndSetTags(d, protectionPolicy.Tags) | ||
return nil | ||
} |
43 changes: 43 additions & 0 deletions
43
azurerm/data_source_recovery_services_protection_policy_vm_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,43 @@ | ||
package azurerm | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform/helper/resource" | ||
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" | ||
) | ||
|
||
func TestAccDataSourceAzureRMRecoveryServicesProtectionPolicyVm_basic(t *testing.T) { | ||
dataSourceName := "data.azurerm_recovery_services_protection_policy_vm.test" | ||
ri := tf.AccRandTimeInt() | ||
|
||
resource.ParallelTest(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
Providers: testAccProviders, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccDataSourceRecoveryServicesProtectionPolicyVm_basic(ri, testLocation()), | ||
Check: resource.ComposeTestCheckFunc( | ||
testCheckAzureRMRecoveryServicesProtectionPolicyVmExists(dataSourceName), | ||
resource.TestCheckResourceAttrSet(dataSourceName, "name"), | ||
resource.TestCheckResourceAttrSet(dataSourceName, "recovery_vault_name"), | ||
resource.TestCheckResourceAttrSet(dataSourceName, "resource_group_name"), | ||
resource.TestCheckResourceAttr(dataSourceName, "tags.%", "0"), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func testAccDataSourceRecoveryServicesProtectionPolicyVm_basic(rInt int, location string) string { | ||
return fmt.Sprintf(` | ||
%s | ||
data "azurerm_recovery_services_protection_policy_vm" "test" { | ||
name = "${azurerm_recovery_services_protection_policy_vm.test.name}" | ||
recovery_vault_name = "${azurerm_recovery_services_vault.test.name}" | ||
resource_group_name = "${azurerm_resource_group.test.name}" | ||
} | ||
`, testAccAzureRMRecoveryServicesProtectionPolicyVm_basicDaily(rInt, location)) | ||
} |
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
40 changes: 40 additions & 0 deletions
40
website/docs/d/recovery_services_protection_policy_vm.markdown
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,40 @@ | ||
--- | ||
layout: "azurerm" | ||
page_title: "Azure Resource Manager: azurerm_recovery_services_protection_policy_vm" | ||
sidebar_current: "docs-azurerm-datasource-recovery-services-protection-policy-vm" | ||
description: |- | ||
Gets information about an existing Recovery Services VM Protection Policy. | ||
--- | ||
|
||
# Data Source: azurerm_recovery_services_protection_policy_vm | ||
|
||
Use this data source to access information about an existing Recovery Services VM Protection Policy. | ||
|
||
## Example Usage | ||
|
||
```hcl | ||
data "azurerm_recovery_services_protection_policy_vm" "policy" { | ||
name = "policy" | ||
recovery_vault_name = "recovery_vault" | ||
resource_group_name = "resource_group" | ||
} | ||
``` | ||
|
||
## Argument Reference | ||
|
||
The following arguments are supported: | ||
|
||
* `name` - (Required) Specifies the name of the Recovery Services VM Protection Policy. | ||
|
||
* `recovery_vault_name` - (Required) Specifies the name of the Recovery Services Vault. | ||
|
||
* `resource_group_name` - (Required) The name of the resource group in which the Recovery Services VM Protection Policy resides. | ||
|
||
## Attributes Reference | ||
|
||
The following attributes are exported: | ||
|
||
* `id` - The ID of the Recovery Services VM Protection Policy. | ||
|
||
* `tags` - A mapping of tags assigned to the resource. | ||
|