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_automation_account #4740

Merged
merged 7 commits into from
Oct 29, 2019
Merged
Show file tree
Hide file tree
Changes from 6 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
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
24 changes: 10 additions & 14 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 Expand Up @@ -286,10 +290,6 @@
<a href="/docs/providers/azurerm/d/policy_definition.html">azurerm_policy_definition</a>
</li>

<li>
<a href="/docs/d/postgresql_server.html">azurerm_postgresql_server</a>
whytoe marked this conversation as resolved.
Show resolved Hide resolved
</li>

<li>
<a href="/docs/providers/azurerm/d/public_ip_prefix.html">azurerm_public_ip_prefix</a>
</li>
Expand Down Expand Up @@ -361,7 +361,7 @@
<li>
<a href="/docs/providers/azurerm/d/storage_account.html">azurerm_storage_account</a>
</li>

<li>
<a href="/docs/providers/azurerm/d/storage_account_blob_container_sas.html">azurerm_storage_account_blob_container_sas</a>
</li>
Expand Down Expand Up @@ -456,8 +456,8 @@
<li>
<a href="/docs/providers/azurerm/r/api_management_api_schema.html">azurerm_api_management_api_schema</a>
</li>

<li>
<li>
<a href="/docs/providers/azurerm/r/api_management_subscription.html">azurerm_api_management_subscription</a>
</li>

Expand Down Expand Up @@ -614,10 +614,6 @@
<a href="/docs/providers/azurerm/r/automation_dsc_nodeconfiguration.html">azurerm_automation_dsc_nodeconfiguration</a>
</li>

<li>
<a href="/docs/providers/azurerm/r/automation_job_schedule.html">azurerm_automation_job_schedule</a>
whytoe marked this conversation as resolved.
Show resolved Hide resolved
</li>

<li>
<a href="/docs/providers/azurerm/r/automation_module.html">azurerm_automation_module</a>
</li>
Expand Down Expand Up @@ -917,7 +913,7 @@
<li>
<a href="/docs/providers/azurerm/r/sql_failover_group.html">azurerm_sql_failover_group</a>
</li>

<li>
<a href="/docs/providers/azurerm/r/sql_firewall_rule.html">azurerm_sql_firewall_rule</a>
</li>
Expand Down Expand Up @@ -1761,7 +1757,7 @@

<li>
<a href="/docs/providers/azurerm/r/stream_analytics_output_eventhub.html">azurerm_stream_analytics_output_eventhub</a>
</li>
</li>

<li>
<a href="/docs/providers/azurerm/r/stream_analytics_output_servicebus_queue.html">azurerm_stream_analytics_output_servicebus_queue</a>
Expand Down Expand Up @@ -1796,7 +1792,7 @@
<li>
<a href="/docs/providers/azurerm/r/storage_blob.html">azurerm_storage_blob</a>
</li>

<li>
<a href="/docs/providers/azurerm/r/storage_container.html">azurerm_storage_container</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