Skip to content

Commit

Permalink
New Data Source azurerm_automation_account - exposes "Keys" and Endpo…
Browse files Browse the repository at this point in the history
…int configuration (#4740)
  • Loading branch information
whytoe authored and mbfrahry committed Oct 29, 2019
1 parent 5a3a3fd commit a31671c
Show file tree
Hide file tree
Showing 5 changed files with 157 additions and 0 deletions.
65 changes: 65 additions & 0 deletions azurerm/data_source_automation_account.go
Original file line number Diff line number Diff line change
@@ -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
}
48 changes: 48 additions & 0 deletions azurerm/data_source_automation_account_test.go
Original file line number Diff line number Diff line change
@@ -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)
}
1 change: 1 addition & 0 deletions azurerm/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
4 changes: 4 additions & 0 deletions website/azurerm.erb
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,10 @@
<a href="/docs/providers/azurerm/d/application_insights.html">azurerm_application_insights</a>
</li>

<li>
<a href="/docs/providers/azurerm/d/automation_account.html">azurerm_automation_account</a>
</li>

<li>
<a href="/docs/providers/azurerm/d/automation_variable_bool.html">azurerm_automation_variable_bool</a>
</li>
Expand Down
39 changes: 39 additions & 0 deletions website/docs/d/automation_account.html.markdown
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit a31671c

Please sign in to comment.