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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

azurerm_automation_account DS set its own ID #6848

Merged
merged 2 commits into from May 11, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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