-
Notifications
You must be signed in to change notification settings - Fork 4.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New Data Source azurerm_automation_account - exposes "Keys" and Endpo…
…int configuration (#4740)
- Loading branch information
Showing
5 changed files
with
157 additions
and
0 deletions.
There are no files selected for viewing
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,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 | ||
} |
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,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) | ||
} |
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
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
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,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 |