Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New Data Source: azurerm_recovery_services_protection_policy_vm #2974

Merged
merged 4 commits into from
Feb 28, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 58 additions & 0 deletions azurerm/data_source_recovery_services_protection_policy_vm.go
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 azurerm/data_source_recovery_services_protection_policy_vm_test.go
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))
}
131 changes: 66 additions & 65 deletions azurerm/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,71 +98,72 @@ func Provider() terraform.ResourceProvider {
},

DataSourcesMap: map[string]*schema.Resource{
"azurerm_api_management": dataSourceApiManagementService(),
"azurerm_api_management_group": dataSourceApiManagementGroup(),
"azurerm_api_management_product": dataSourceApiManagementProduct(),
"azurerm_api_management_user": dataSourceArmApiManagementUser(),
"azurerm_app_service_plan": dataSourceAppServicePlan(),
"azurerm_app_service": dataSourceArmAppService(),
"azurerm_application_insights": dataSourceArmApplicationInsights(),
"azurerm_application_security_group": dataSourceArmApplicationSecurityGroup(),
"azurerm_availability_set": dataSourceArmAvailabilitySet(),
"azurerm_azuread_application": dataSourceArmAzureADApplication(),
"azurerm_azuread_service_principal": dataSourceArmActiveDirectoryServicePrincipal(),
"azurerm_batch_account": dataSourceArmBatchAccount(),
"azurerm_batch_pool": dataSourceArmBatchPool(),
"azurerm_builtin_role_definition": dataSourceArmBuiltInRoleDefinition(),
"azurerm_cdn_profile": dataSourceArmCdnProfile(),
"azurerm_client_config": dataSourceArmClientConfig(),
"azurerm_container_registry": dataSourceArmContainerRegistry(),
"azurerm_cosmosdb_account": dataSourceArmCosmosDBAccount(),
"azurerm_data_lake_store": dataSourceArmDataLakeStoreAccount(),
"azurerm_dev_test_lab": dataSourceArmDevTestLab(),
"azurerm_dns_zone": dataSourceArmDnsZone(),
"azurerm_eventhub_namespace": dataSourceEventHubNamespace(),
"azurerm_image": dataSourceArmImage(),
"azurerm_key_vault_access_policy": dataSourceArmKeyVaultAccessPolicy(),
"azurerm_key_vault_key": dataSourceArmKeyVaultKey(),
"azurerm_key_vault_secret": dataSourceArmKeyVaultSecret(),
"azurerm_key_vault": dataSourceArmKeyVault(),
"azurerm_kubernetes_cluster": dataSourceArmKubernetesCluster(),
"azurerm_lb": dataSourceArmLoadBalancer(),
"azurerm_lb_backend_address_pool": dataSourceArmLoadBalancerBackendAddressPool(),
"azurerm_log_analytics_workspace": dataSourceLogAnalyticsWorkspace(),
"azurerm_logic_app_workflow": dataSourceArmLogicAppWorkflow(),
"azurerm_managed_disk": dataSourceArmManagedDisk(),
"azurerm_management_group": dataSourceArmManagementGroup(),
"azurerm_monitor_action_group": dataSourceArmMonitorActionGroup(),
"azurerm_monitor_diagnostic_categories": dataSourceArmMonitorDiagnosticCategories(),
"azurerm_monitor_log_profile": dataSourceArmMonitorLogProfile(),
"azurerm_network_interface": dataSourceArmNetworkInterface(),
"azurerm_network_security_group": dataSourceArmNetworkSecurityGroup(),
"azurerm_network_watcher": dataSourceArmNetworkWatcher(),
"azurerm_notification_hub_namespace": dataSourceNotificationHubNamespace(),
"azurerm_notification_hub": dataSourceNotificationHub(),
"azurerm_platform_image": dataSourceArmPlatformImage(),
"azurerm_policy_definition": dataSourceArmPolicyDefinition(),
"azurerm_public_ip": dataSourceArmPublicIP(),
"azurerm_public_ips": dataSourceArmPublicIPs(),
"azurerm_recovery_services_vault": dataSourceArmRecoveryServicesVault(),
"azurerm_resource_group": dataSourceArmResourceGroup(),
"azurerm_role_definition": dataSourceArmRoleDefinition(),
"azurerm_route_table": dataSourceArmRouteTable(),
"azurerm_scheduler_job_collection": dataSourceArmSchedulerJobCollection(),
"azurerm_servicebus_namespace": dataSourceArmServiceBusNamespace(),
"azurerm_shared_image_gallery": dataSourceArmSharedImageGallery(),
"azurerm_shared_image_version": dataSourceArmSharedImageVersion(),
"azurerm_shared_image": dataSourceArmSharedImage(),
"azurerm_snapshot": dataSourceArmSnapshot(),
"azurerm_storage_account_sas": dataSourceArmStorageAccountSharedAccessSignature(),
"azurerm_storage_account": dataSourceArmStorageAccount(),
"azurerm_subnet": dataSourceArmSubnet(),
"azurerm_subscription": dataSourceArmSubscription(),
"azurerm_subscriptions": dataSourceArmSubscriptions(),
"azurerm_traffic_manager_geographical_location": dataSourceArmTrafficManagerGeographicalLocation(),
"azurerm_virtual_machine": dataSourceArmVirtualMachine(),
"azurerm_virtual_network_gateway": dataSourceArmVirtualNetworkGateway(),
"azurerm_virtual_network": dataSourceArmVirtualNetwork(),
"azurerm_api_management": dataSourceApiManagementService(),
"azurerm_api_management_group": dataSourceApiManagementGroup(),
"azurerm_api_management_product": dataSourceApiManagementProduct(),
"azurerm_api_management_user": dataSourceArmApiManagementUser(),
"azurerm_app_service_plan": dataSourceAppServicePlan(),
"azurerm_app_service": dataSourceArmAppService(),
"azurerm_application_insights": dataSourceArmApplicationInsights(),
"azurerm_application_security_group": dataSourceArmApplicationSecurityGroup(),
"azurerm_availability_set": dataSourceArmAvailabilitySet(),
"azurerm_azuread_application": dataSourceArmAzureADApplication(),
"azurerm_azuread_service_principal": dataSourceArmActiveDirectoryServicePrincipal(),
"azurerm_batch_account": dataSourceArmBatchAccount(),
"azurerm_batch_pool": dataSourceArmBatchPool(),
"azurerm_builtin_role_definition": dataSourceArmBuiltInRoleDefinition(),
"azurerm_cdn_profile": dataSourceArmCdnProfile(),
"azurerm_client_config": dataSourceArmClientConfig(),
"azurerm_container_registry": dataSourceArmContainerRegistry(),
"azurerm_cosmosdb_account": dataSourceArmCosmosDBAccount(),
"azurerm_data_lake_store": dataSourceArmDataLakeStoreAccount(),
"azurerm_dev_test_lab": dataSourceArmDevTestLab(),
"azurerm_dns_zone": dataSourceArmDnsZone(),
"azurerm_eventhub_namespace": dataSourceEventHubNamespace(),
"azurerm_image": dataSourceArmImage(),
"azurerm_key_vault_access_policy": dataSourceArmKeyVaultAccessPolicy(),
"azurerm_key_vault_key": dataSourceArmKeyVaultKey(),
"azurerm_key_vault_secret": dataSourceArmKeyVaultSecret(),
"azurerm_key_vault": dataSourceArmKeyVault(),
"azurerm_kubernetes_cluster": dataSourceArmKubernetesCluster(),
"azurerm_lb": dataSourceArmLoadBalancer(),
"azurerm_lb_backend_address_pool": dataSourceArmLoadBalancerBackendAddressPool(),
"azurerm_log_analytics_workspace": dataSourceLogAnalyticsWorkspace(),
"azurerm_logic_app_workflow": dataSourceArmLogicAppWorkflow(),
"azurerm_managed_disk": dataSourceArmManagedDisk(),
"azurerm_management_group": dataSourceArmManagementGroup(),
"azurerm_monitor_action_group": dataSourceArmMonitorActionGroup(),
"azurerm_monitor_diagnostic_categories": dataSourceArmMonitorDiagnosticCategories(),
"azurerm_monitor_log_profile": dataSourceArmMonitorLogProfile(),
"azurerm_network_interface": dataSourceArmNetworkInterface(),
"azurerm_network_security_group": dataSourceArmNetworkSecurityGroup(),
"azurerm_network_watcher": dataSourceArmNetworkWatcher(),
"azurerm_notification_hub_namespace": dataSourceNotificationHubNamespace(),
"azurerm_notification_hub": dataSourceNotificationHub(),
"azurerm_platform_image": dataSourceArmPlatformImage(),
"azurerm_policy_definition": dataSourceArmPolicyDefinition(),
"azurerm_public_ip": dataSourceArmPublicIP(),
"azurerm_public_ips": dataSourceArmPublicIPs(),
"azurerm_recovery_services_vault": dataSourceArmRecoveryServicesVault(),
"azurerm_recovery_services_protection_policy_vm": dataSourceArmRecoveryServicesProtectionPolicyVm(),
"azurerm_resource_group": dataSourceArmResourceGroup(),
"azurerm_role_definition": dataSourceArmRoleDefinition(),
"azurerm_route_table": dataSourceArmRouteTable(),
"azurerm_scheduler_job_collection": dataSourceArmSchedulerJobCollection(),
"azurerm_servicebus_namespace": dataSourceArmServiceBusNamespace(),
"azurerm_shared_image_gallery": dataSourceArmSharedImageGallery(),
"azurerm_shared_image_version": dataSourceArmSharedImageVersion(),
"azurerm_shared_image": dataSourceArmSharedImage(),
"azurerm_snapshot": dataSourceArmSnapshot(),
"azurerm_storage_account_sas": dataSourceArmStorageAccountSharedAccessSignature(),
"azurerm_storage_account": dataSourceArmStorageAccount(),
"azurerm_subnet": dataSourceArmSubnet(),
"azurerm_subscription": dataSourceArmSubscription(),
"azurerm_subscriptions": dataSourceArmSubscriptions(),
"azurerm_traffic_manager_geographical_location": dataSourceArmTrafficManagerGeographicalLocation(),
"azurerm_virtual_machine": dataSourceArmVirtualMachine(),
"azurerm_virtual_network_gateway": dataSourceArmVirtualNetworkGateway(),
"azurerm_virtual_network": dataSourceArmVirtualNetwork(),
},

ResourcesMap: map[string]*schema.Resource{
Expand Down
40 changes: 40 additions & 0 deletions website/docs/d/recovery_services_protection_policy_vm.markdown
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.