Skip to content

Commit

Permalink
add fields to loganalytics workspaces (#9033)
Browse files Browse the repository at this point in the history
Co-authored-by: kt <[email protected]>
  • Loading branch information
dw511214992 and katbyte authored Nov 11, 2020
1 parent 2d26606 commit 1ed9b6d
Show file tree
Hide file tree
Showing 3 changed files with 168 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,18 @@ func resourceArmLogAnalyticsWorkspace() *schema.Resource {

"resource_group_name": azure.SchemaResourceGroupNameDiffSuppress(),

"internet_ingestion_enabled": {
Type: schema.TypeBool,
Optional: true,
Default: true,
},

"internet_query_enabled": {
Type: schema.TypeBool,
Optional: true,
Default: true,
},

"sku": {
Type: schema.TypeString,
Optional: true,
Expand Down Expand Up @@ -147,6 +159,15 @@ func resourceArmLogAnalyticsWorkspaceCreateUpdate(d *schema.ResourceData, meta i
Name: operationalinsights.WorkspaceSkuNameEnum(skuName),
}

internetIngestionEnabled := operationalinsights.Disabled
if d.Get("internet_ingestion_enabled").(bool) {
internetIngestionEnabled = operationalinsights.Enabled
}
internetQueryEnabled := operationalinsights.Disabled
if d.Get("internet_query_enabled").(bool) {
internetQueryEnabled = operationalinsights.Enabled
}

retentionInDays := int32(d.Get("retention_in_days").(int))

t := d.Get("tags").(map[string]interface{})
Expand All @@ -156,8 +177,10 @@ func resourceArmLogAnalyticsWorkspaceCreateUpdate(d *schema.ResourceData, meta i
Location: &location,
Tags: tags.Expand(t),
WorkspaceProperties: &operationalinsights.WorkspaceProperties{
Sku: sku,
RetentionInDays: &retentionInDays,
Sku: sku,
PublicNetworkAccessForIngestion: internetIngestionEnabled,
PublicNetworkAccessForQuery: internetQueryEnabled,
RetentionInDays: &retentionInDays,
},
}

Expand Down Expand Up @@ -209,6 +232,9 @@ func resourceArmLogAnalyticsWorkspaceRead(d *schema.ResourceData, meta interface
d.Set("location", azure.NormalizeLocation(*location))
}

d.Set("internet_ingestion_enabled", resp.PublicNetworkAccessForIngestion == operationalinsights.Enabled)
d.Set("internet_query_enabled", resp.PublicNetworkAccessForQuery == operationalinsights.Enabled)

d.Set("workspace_id", resp.CustomerID)
d.Set("portal_url", "")
if sku := resp.Sku; sku != nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,58 @@ func TestAccAzureRMLogAnalyticsWorkspace_removeVolumeCap(t *testing.T) {
})
}

func TestAccAzureRMLogAnalyticsWorkspace_withInternetIngestionEnabled(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_log_analytics_workspace", "test")

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acceptance.PreCheck(t) },
Providers: acceptance.SupportedProviders,
CheckDestroy: testCheckAzureRMLogAnalyticsWorkspaceDestroy,
Steps: []resource.TestStep{
{
Config: testAccAzureRMLogAnalyticsWorkspace_withInternetIngestionEnabled(data),
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMLogAnalyticsWorkspaceExists(data.ResourceName),
),
},
data.ImportStep(),
{
Config: testAccAzureRMLogAnalyticsWorkspace_withInternetIngestionEnabledUpdate(data),
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMLogAnalyticsWorkspaceExists(data.ResourceName),
),
},
data.ImportStep(),
},
})
}

func TestAccAzureRMLogAnalyticsWorkspace_withInternetQueryEnabled(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_log_analytics_workspace", "test")

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acceptance.PreCheck(t) },
Providers: acceptance.SupportedProviders,
CheckDestroy: testCheckAzureRMLogAnalyticsWorkspaceDestroy,
Steps: []resource.TestStep{
{
Config: testAccAzureRMLogAnalyticsWorkspace_withInternetQueryEnabled(data),
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMLogAnalyticsWorkspaceExists(data.ResourceName),
),
},
data.ImportStep(),
{
Config: testAccAzureRMLogAnalyticsWorkspace_withInternetQueryEnabledUpdate(data),
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMLogAnalyticsWorkspaceExists(data.ResourceName),
),
},
data.ImportStep(),
},
})
}

func testCheckAzureRMLogAnalyticsWorkspaceDestroy(s *terraform.State) error {
conn := acceptance.AzureProvider.Meta().(*clients.Client).LogAnalytics.WorkspacesClient
ctx := acceptance.AzureProvider.Meta().(*clients.Client).StopContext
Expand Down Expand Up @@ -404,3 +456,87 @@ resource "azurerm_log_analytics_workspace" "test" {
}
`, data.RandomInteger, data.Locations.Primary, data.RandomInteger)
}

func testAccAzureRMLogAnalyticsWorkspace_withInternetIngestionEnabled(data acceptance.TestData) string {
return fmt.Sprintf(`
provider "azurerm" {
features {}
}
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
internet_ingestion_enabled = true
sku = "PerGB2018"
}
`, data.RandomInteger, data.Locations.Primary, data.RandomInteger)
}

func testAccAzureRMLogAnalyticsWorkspace_withInternetIngestionEnabledUpdate(data acceptance.TestData) string {
return fmt.Sprintf(`
provider "azurerm" {
features {}
}
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
internet_ingestion_enabled = false
sku = "PerGB2018"
}
`, data.RandomInteger, data.Locations.Primary, data.RandomInteger)
}

func testAccAzureRMLogAnalyticsWorkspace_withInternetQueryEnabled(data acceptance.TestData) string {
return fmt.Sprintf(`
provider "azurerm" {
features {}
}
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
internet_query_enabled = true
sku = "PerGB2018"
}
`, data.RandomInteger, data.Locations.Primary, data.RandomInteger)
}

func testAccAzureRMLogAnalyticsWorkspace_withInternetQueryEnabledUpdate(data acceptance.TestData) string {
return fmt.Sprintf(`
provider "azurerm" {
features {}
}
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
internet_query_enabled = false
sku = "PerGB2018"
}
`, data.RandomInteger, data.Locations.Primary, data.RandomInteger)
}
4 changes: 4 additions & 0 deletions website/docs/r/log_analytics_workspace.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ The following arguments are supported:

~> **NOTE:** When `sku_name` is set to `Free` this field can be set to a maximum of `0.5` (GB), and has a default value of `0.5`.

* `internet_ingestion_enabled ` - (Optional) Should the Log Analytics Workflow support ingestion over the Public Internet? Defaults to `true`.

* `internet_query_enabled` - (Optional) Should the Log Analytics Workflow support querying over the Public Internet? Defaults to `true`.

* `tags` - (Optional) A mapping of tags to assign to the resource.

## Attributes Reference
Expand Down

0 comments on commit 1ed9b6d

Please sign in to comment.