diff --git a/azurerm/data_source_automation_account.go b/azurerm/data_source_automation_account.go new file mode 100644 index 000000000000..012b74c09110 --- /dev/null +++ b/azurerm/data_source_automation_account.go @@ -0,0 +1,65 @@ +package azurerm + +import ( + "fmt" + "time" + + "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/timeouts" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" +) + +func dataSourceArmAutomationAccount() *schema.Resource { + return &schema.Resource{ + Read: dataSourceAutomationAccountRead, + + Timeouts: &schema.ResourceTimeout{ + Read: schema.DefaultTimeout(5 * time.Minute), + }, + + Schema: map[string]*schema.Schema{ + "name": { + Type: schema.TypeString, + Required: true, + }, + + "resource_group_name": azure.SchemaResourceGroupNameDiffSuppress(), + + "primary_key": { + Type: schema.TypeString, + Computed: true, + }, + "secondary_key": { + Type: schema.TypeString, + Computed: true, + }, + "endpoint": { + Type: schema.TypeString, + Computed: true, + }, + }, + } +} + +func dataSourceAutomationAccountRead(d *schema.ResourceData, meta interface{}) error { + client := meta.(*ArmClient).Automation.AgentRegistrationInfoClient + ctx, cancel := timeouts.ForRead(meta.(*ArmClient).StopContext, d) + defer cancel() + + name := d.Get("name").(string) + resourceGroupName := d.Get("resource_group_name").(string) + + resp, err := client.Get(ctx, resourceGroupName, name) + if err != nil { + if utils.ResponseWasNotFound(resp.Response) { + return fmt.Errorf("Error: Automation Account %q (Resource Group %q) was not found", name, resourceGroupName) + } + return fmt.Errorf("Error making Read request on Automation Account Registration Information %q (Resource Group %q): %+v", name, resourceGroupName, err) + } + d.SetId(*resp.ID) + d.Set("primary_key", resp.Keys.Primary) + d.Set("secondary_key", resp.Keys.Secondary) + d.Set("endpoint", resp.Endpoint) + return nil +} diff --git a/azurerm/data_source_automation_account_test.go b/azurerm/data_source_automation_account_test.go new file mode 100644 index 000000000000..958dff642e58 --- /dev/null +++ b/azurerm/data_source_automation_account_test.go @@ -0,0 +1,48 @@ +package azurerm + +import ( + "fmt" + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" +) + +func TestAccDataSourceAutomationAccount(t *testing.T) { + dataSourceName := "data.azurerm_automation_account.test" + ri := tf.AccRandTimeInt() + location := testLocation() + resourceGroupName := fmt.Sprintf("acctestRG-%d", ri) + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + Steps: []resource.TestStep{ + { + Config: testAccDataSourceAutomationAccount_complete(resourceGroupName, location, ri), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr(dataSourceName, "resource_group_name", resourceGroupName), + ), + }, + }, + }) +} + +func testAccDataSourceAutomationAccount_complete(resourceGroupName string, location string, ri int) string { + return fmt.Sprintf(` +resource "azurerm_resource_group" "test" { + name = "%s" + location = "%s" +} +resource "azurerm_automation_account" "test" { + name = "acctestautomationAccount-%d" + location = "${azurerm_resource_group.test.location}" + resource_group_name = "${azurerm_resource_group.test.name}" + sku_name = "Basic" +} +data "azurerm_automation_account" "test" { + resource_group_name = "${azurerm_resource_group.test.name}" + name = "${azurerm_automation_account.test.name}" +} +`, resourceGroupName, location, ri) +} diff --git a/azurerm/provider.go b/azurerm/provider.go index b37dbde356b5..7eb20555bcaf 100644 --- a/azurerm/provider.go +++ b/azurerm/provider.go @@ -63,6 +63,7 @@ func Provider() terraform.ResourceProvider { "azurerm_app_service_certificate_order": dataSourceArmAppServiceCertificateOrder(), "azurerm_application_insights": dataSourceArmApplicationInsights(), "azurerm_application_security_group": dataSourceArmApplicationSecurityGroup(), + "azurerm_automation_account": dataSourceArmAutomationAccount(), "azurerm_automation_variable_bool": dataSourceArmAutomationVariableBool(), "azurerm_automation_variable_datetime": dataSourceArmAutomationVariableDateTime(), "azurerm_automation_variable_int": dataSourceArmAutomationVariableInt(), diff --git a/website/azurerm.erb b/website/azurerm.erb index 7859ebbb6087..917a0aefc57a 100644 --- a/website/azurerm.erb +++ b/website/azurerm.erb @@ -90,6 +90,10 @@ azurerm_application_insights +
  • + azurerm_automation_account +
  • +
  • azurerm_automation_variable_bool
  • diff --git a/website/docs/d/automation_account.html.markdown b/website/docs/d/automation_account.html.markdown new file mode 100644 index 000000000000..34da4f6f68d0 --- /dev/null +++ b/website/docs/d/automation_account.html.markdown @@ -0,0 +1,39 @@ +--- +layout: "azurerm" +page_title: "Azure Resource Manager: azurerm_automation_registration_info" +sidebar_current: "docs-azurerm-datasource-automation-registration-info" +description: |- + Gets information about an existing Automation Account Registration Information. +--- + +# Data Source: azurerm_automation_account_registration_info + +Use this data source to access information about an existing Automation Account Registration Information. + +## Example Usage + +```hcl +data "azurerm_automation_account_registration_info" "test" { + name = "automation-account" + resource_group_name = "automation-resource-group" +} +output "automation_account_id" { + value = "${data.azurerm_automation_account_registration_info.test.id}" +} +``` + +## Argument Reference + +* `name` - (Required) The name of the Automation Account. + +* `resource_group_name` - (Required) Specifies the name of the Resource Group where the Automation Account exists. + +## Attributes Reference + +* `id` - The ID of the Automation Account + +* `primary_key` - The primary key for the Automation Account Registration information + +* `secondary_key` - The primary key for the Automation Account Registration information + +* `endpoint` - The Assigned Automation Account Registration endpoint