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_container_group - allow empty log_type #4013

Merged
merged 2 commits into from
Aug 8, 2019
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
31 changes: 17 additions & 14 deletions azurerm/resource_arm_container_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ func resourceArmContainerGroup() *schema.Resource {

"log_type": {
Type: schema.TypeString,
Required: true,
Optional: true,
ForceNew: true,
ValidateFunc: validation.StringInSlice([]string{
string(containerinstance.ContainerInsights),
Expand Down Expand Up @@ -1241,23 +1241,26 @@ func expandContainerGroupDiagnostics(input []interface{}) *containerinstance.Con

workspaceId := analyticsV["workspace_id"].(string)
workspaceKey := analyticsV["workspace_key"].(string)
logType := containerinstance.LogAnalyticsLogType(analyticsV["log_type"].(string))

metadataMap := analyticsV["metadata"].(map[string]interface{})
metadata := make(map[string]*string)
for k, v := range metadataMap {
strValue := v.(string)
metadata[k] = &strValue
logAnalytics := containerinstance.LogAnalytics{
WorkspaceID: utils.String(workspaceId),
WorkspaceKey: utils.String(workspaceKey),
}

return &containerinstance.ContainerGroupDiagnostics{
LogAnalytics: &containerinstance.LogAnalytics{
WorkspaceID: utils.String(workspaceId),
WorkspaceKey: utils.String(workspaceKey),
LogType: logType,
Metadata: metadata,
},
if logType := analyticsV["log_type"].(string); logType != "" {
logAnalytics.LogType = containerinstance.LogAnalyticsLogType(logType)

metadataMap := analyticsV["metadata"].(map[string]interface{})
metadata := make(map[string]*string)
for k, v := range metadataMap {
strValue := v.(string)
metadata[k] = &strValue
}

logAnalytics.Metadata = metadata
tombuildsstuff marked this conversation as resolved.
Show resolved Hide resolved
}

return &containerinstance.ContainerGroupDiagnostics{LogAnalytics: &logAnalytics}
}

func flattenContainerGroupDiagnostics(d *schema.ResourceData, input *containerinstance.ContainerGroupDiagnostics) []interface{} {
Expand Down
75 changes: 75 additions & 0 deletions azurerm/resource_arm_container_group_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,38 @@ func TestAccAzureRMContainerGroup_imageRegistryCredentialsUpdate(t *testing.T) {
})
}

func TestAccAzureRMContainerGroup_logTypeUnset(t *testing.T) {
resourceName := "azurerm_container_group.test"
ri := tf.AccRandTimeInt()
config := testAccAzureRMContainerGroup_logTypeUnset(ri, testLocation())
resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testCheckAzureRMContainerGroupDestroy,
Steps: []resource.TestStep{
{
Config: config,
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMContainerGroupExists(resourceName),
resource.TestCheckResourceAttr(resourceName, "diagnostics.0.log_analytics.#", "1"),
resource.TestCheckResourceAttr(resourceName, "diagnostics.0.log_analytics.0.log_type", ""),
resource.TestCheckResourceAttr(resourceName, "diagnostics.0.log_analytics.0.metadata.%", "0"),
resource.TestCheckResourceAttrSet(resourceName, "diagnostics.0.log_analytics.0.workspace_id"),
resource.TestCheckResourceAttrSet(resourceName, "diagnostics.0.log_analytics.0.workspace_key"),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{
"diagnostics.0.log_analytics.0.workspace_key",
},
},
},
})
}

func TestAccAzureRMContainerGroup_linuxBasic(t *testing.T) {
resourceName := "azurerm_container_group.test"
ri := tf.AccRandTimeInt()
Expand Down Expand Up @@ -721,6 +753,49 @@ resource "azurerm_container_group" "test" {
`, ri, location, ri)
}

func testAccAzureRMContainerGroup_logTypeUnset(ri int, location string) string {
return fmt.Sprintf(`
resource "azurerm_resource_group" "test" {
name = "acctestRG-%d"
location = "%s"
}

resource "azurerm_log_analytics_workspace" "test" {
name = "acctestLAW-%d"
location = "${azurerm_resource_group.test.location}"
resource_group_name = "${azurerm_resource_group.test.name}"
sku = "PerGB2018"
}

resource "azurerm_container_group" "test" {
name = "acctestcontainergroup-%d"
location = "${azurerm_resource_group.test.location}"
resource_group_name = "${azurerm_resource_group.test.name}"
ip_address_type = "public"
os_type = "Linux"

container {
name = "hw"
image = "microsoft/aci-helloworld:latest"
cpu = "0.5"
memory = "0.5"
port = 80
}

diagnostics {
log_analytics {
workspace_id = "${azurerm_log_analytics_workspace.test.workspace_id}"
workspace_key = "${azurerm_log_analytics_workspace.test.primary_shared_key}"
}
}

tags = {
environment = "Testing"
}
}
`, ri, location, ri, ri)
}

func testAccAzureRMContainerGroup_linuxBasicUpdated(ri int, location string) string {
return fmt.Sprintf(`
resource "azurerm_resource_group" "test" {
Expand Down
2 changes: 1 addition & 1 deletion website/docs/r/container_group.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ A `image_registry_credential` block supports:

A `log_analytics` block supports:

* `log_type` - (Required) The log type which should be used. Possible values are `ContainerInsights` and `ContainerInstanceLogs`. Changing this forces a new resource to be created.
* `log_type` - (Optional) The log type which should be used. Possible values are `ContainerInsights` and `ContainerInstanceLogs`. Changing this forces a new resource to be created.

* `workspace_id` - (Required) The Workspace ID of the Log Analytics Workspace. Changing this forces a new resource to be created.

Expand Down