Skip to content

Commit

Permalink
Merge pull request #6848 from magodo/automation_account_ds_id
Browse files Browse the repository at this point in the history
`azurerm_automation_account` DS set its own ID
  • Loading branch information
tombuildsstuff committed May 11, 2020
2 parents b2bc8ea + 877890a commit cb5e732
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
Expand Up @@ -44,7 +44,8 @@ func dataSourceArmAutomationAccount() *schema.Resource {
}

func dataSourceAutomationAccountRead(d *schema.ResourceData, meta interface{}) error {
client := meta.(*clients.Client).Automation.AgentRegistrationInfoClient
iclient := meta.(*clients.Client).Automation.AgentRegistrationInfoClient
client := meta.(*clients.Client).Automation.AccountClient
ctx, cancel := timeouts.ForRead(meta.(*clients.Client).StopContext, d)
defer cancel()

Expand All @@ -56,11 +57,19 @@ func dataSourceAutomationAccountRead(d *schema.ResourceData, meta interface{}) e
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)
return fmt.Errorf("Error making Read request on Automation %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)

iresp, err := iclient.Get(ctx, resourceGroupName, name)
if err != nil {
if utils.ResponseWasNotFound(iresp.Response) {
return fmt.Errorf("Error: Automation Account Registration Information %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.Set("primary_key", iresp.Keys.Primary)
d.Set("secondary_key", iresp.Keys.Secondary)
d.Set("endpoint", iresp.Endpoint)
return nil
}
Expand Up @@ -2,6 +2,7 @@ package tests

import (
"fmt"
"regexp"
"testing"

"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
Expand All @@ -20,6 +21,8 @@ func TestAccDataSourceAutomationAccount(t *testing.T) {
Config: testAccDataSourceAutomationAccount_complete(resourceGroupName, data),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(data.ResourceName, "resource_group_name", resourceGroupName),
resource.TestMatchResourceAttr(data.ResourceName, "id",
regexp.MustCompile(`^/subscriptions/[^/]+/resourceGroups/[^/]+/providers/Microsoft\.Automation/automationAccounts/[^/]+$`)),
),
},
},
Expand Down

0 comments on commit cb5e732

Please sign in to comment.