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

azurerm_automation_account: fix automation account local_authentication_enabled logic #23082

Merged
merged 1 commit into from
Aug 25, 2023
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions internal/services/automation/automation_account_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,9 +195,7 @@ func resourceAutomationAccountCreate(d *pluginsdk.ResourceData, meta interface{}
},
}

if localAuth := d.Get("local_authentication_enabled").(bool); !localAuth {
parameters.Properties.DisableLocalAuth = utils.Bool(true)
}
parameters.Properties.DisableLocalAuth = utils.Bool(!d.Get("local_authentication_enabled").(bool))

// for create account do not set identity property (even TypeNone is not allowed), or api will response error
if identityVal.Type != identity.TypeNone {
Expand Down Expand Up @@ -247,8 +245,8 @@ func resourceAutomationAccountUpdate(d *pluginsdk.ResourceData, meta interface{}
},
}

if localAuth := d.Get("local_authentication_enabled").(bool); !localAuth {
parameters.Properties.DisableLocalAuth = utils.Bool(true)
if d.HasChange("local_authentication_enabled") {
parameters.Properties.DisableLocalAuth = utils.Bool(!d.Get("local_authentication_enabled").(bool))
}

if tagsVal := tags.Expand(d.Get("tags").(map[string]interface{})); tagsVal != nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,34 @@ func TestAccAutomationAccount_complete(t *testing.T) {
check.That(data.ResourceName).ExistsInAzure(r),
check.That(data.ResourceName).Key("sku_name").HasValue("Basic"),
check.That(data.ResourceName).Key("tags.hello").HasValue("world"),
check.That(data.ResourceName).Key("local_authentication_enabled").HasValue("true"),
),
},
data.ImportStep(),
})
}

func TestAccAutomationAccount_update(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_automation_account", "test")
r := AutomationAccountResource{}

data.ResourceTest(t, r, []acceptance.TestStep{
{
Config: r.basic(data),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
check.That(data.ResourceName).Key("sku_name").HasValue("Basic"),
check.That(data.ResourceName).Key("local_authentication_enabled").HasValue("false"),
),
},
data.ImportStep(),
{
Config: r.complete(data),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
check.That(data.ResourceName).Key("sku_name").HasValue("Basic"),
check.That(data.ResourceName).Key("tags.hello").HasValue("world"),
check.That(data.ResourceName).Key("local_authentication_enabled").HasValue("true"),
),
},
data.ImportStep(),
Expand Down Expand Up @@ -206,10 +234,11 @@ resource "azurerm_resource_group" "test" {
}

resource "azurerm_automation_account" "test" {
name = "acctest-%[1]d"
location = azurerm_resource_group.test.location
resource_group_name = azurerm_resource_group.test.name
sku_name = "Basic"
name = "acctest-%[1]d"
location = azurerm_resource_group.test.location
resource_group_name = azurerm_resource_group.test.name
sku_name = "Basic"
local_authentication_enabled = false
}
`, data.RandomInteger, data.Locations.Primary)
}
Expand Down Expand Up @@ -246,6 +275,7 @@ resource "azurerm_automation_account" "test" {
resource_group_name = azurerm_resource_group.test.name
sku_name = "Basic"
public_network_access_enabled = false
local_authentication_enabled = true
tags = {
"hello" = "world"
}
Expand Down