Skip to content

Commit

Permalink
Add Connection Monitor resource and Network Watcher data source (#2791)
Browse files Browse the repository at this point in the history
  • Loading branch information
lewinski authored and katbyte committed Feb 19, 2019
1 parent 2c51155 commit 412001c
Show file tree
Hide file tree
Showing 10 changed files with 1,380 additions and 0 deletions.
5 changes: 5 additions & 0 deletions azurerm/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@ type ArmClient struct {
applicationGatewayClient network.ApplicationGatewaysClient
applicationSecurityGroupsClient network.ApplicationSecurityGroupsClient
azureFirewallsClient network.AzureFirewallsClient
connectionMonitorsClient network.ConnectionMonitorsClient
ddosProtectionPlanClient network.DdosProtectionPlansClient
expressRouteAuthsClient network.ExpressRouteCircuitAuthorizationsClient
expressRouteCircuitClient network.ExpressRouteCircuitsClient
Expand Down Expand Up @@ -914,6 +915,10 @@ func (c *ArmClient) registerNetworkingClients(endpoint, subscriptionId string, a
c.configureClient(&azureFirewallsClient.Client, auth)
c.azureFirewallsClient = azureFirewallsClient

connectionMonitorsClient := network.NewConnectionMonitorsClientWithBaseURI(endpoint, subscriptionId)
c.configureClient(&connectionMonitorsClient.Client, auth)
c.connectionMonitorsClient = connectionMonitorsClient

ddosProtectionPlanClient := network.NewDdosProtectionPlansClientWithBaseURI(endpoint, subscriptionId)
c.configureClient(&ddosProtectionPlanClient.Client, auth)
c.ddosProtectionPlanClient = ddosProtectionPlanClient
Expand Down
54 changes: 54 additions & 0 deletions azurerm/data_source_network_watcher.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package azurerm

import (
"fmt"

"github.com/hashicorp/terraform/helper/schema"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/validate"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils"
)

func dataSourceArmNetworkWatcher() *schema.Resource {
return &schema.Resource{
Read: dataSourceArmNetworkWatcherRead,

Schema: map[string]*schema.Schema{
"name": {
Type: schema.TypeString,
Required: true,
ValidateFunc: validate.NoEmptyStrings,
},

"resource_group_name": resourceGroupNameForDataSourceSchema(),
"location": locationForDataSourceSchema(),
"tags": tagsForDataSourceSchema(),
},
}
}

func dataSourceArmNetworkWatcherRead(d *schema.ResourceData, meta interface{}) error {
client := meta.(*ArmClient).watcherClient

name := d.Get("name").(string)
resourceGroup := d.Get("resource_group_name").(string)

ctx := meta.(*ArmClient).StopContext
resp, err := client.Get(ctx, resourceGroup, name)
if err != nil {
if utils.ResponseWasNotFound(resp.Response) {
return fmt.Errorf("Error: Network Watcher %q (Resource Group %q) was not found", name, resourceGroup)
}
return fmt.Errorf("Error making Read request on Network Watcher %q (Resource Group %q): %+v", name, resourceGroup, err)
}

d.SetId(*resp.ID)

d.Set("name", name)
d.Set("resource_group_name", resourceGroup)
if location := resp.Location; location != nil {
d.Set("location", azureRMNormalizeLocation(*location))
}
flattenAndSetTags(d, resp.Tags)

return nil
}
59 changes: 59 additions & 0 deletions azurerm/data_source_network_watcher_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package azurerm

import (
"fmt"
"testing"

"github.com/hashicorp/terraform/helper/resource"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf"
)

func testAccDataSourceAzureRMNetworkWatcher_basic(t *testing.T) {
dataSourceName := "data.azurerm_network_watcher.test"

ri := tf.AccRandTimeInt()
name := fmt.Sprintf("acctestnw-%d", ri)
location := testLocation()

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Config: testAccDataSourceAzureRMNetworkWatcher_basicConfig(ri, location),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrSet(dataSourceName, "id"),
resource.TestCheckResourceAttr(dataSourceName, "name", name),
resource.TestCheckResourceAttrSet(dataSourceName, "resource_group_name"),
resource.TestCheckResourceAttr(dataSourceName, "location", azureRMNormalizeLocation(location)),
resource.TestCheckResourceAttr(dataSourceName, "tags.%", "1"),
resource.TestCheckResourceAttr(dataSourceName, "tags.env", "test"),
),
},
},
})
}

func testAccDataSourceAzureRMNetworkWatcher_basicConfig(rInt int, location string) string {
return fmt.Sprintf(`
resource "azurerm_resource_group" "test" {
name = "acctestrg-%d"
location = "%s"
}
resource "azurerm_network_watcher" "test" {
name = "acctestnw-%d"
location = "${azurerm_resource_group.test.location}"
resource_group_name = "${azurerm_resource_group.test.name}"
tags {
env = "test"
}
}
data "azurerm_network_watcher" "test" {
name = "${azurerm_network_watcher.test.name}"
resource_group_name = "${azurerm_resource_group.test.name}"
}
`, rInt, location, rInt)
}
2 changes: 2 additions & 0 deletions azurerm/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ func Provider() terraform.ResourceProvider {
"azurerm_monitor_log_profile": dataSourceArmMonitorLogProfile(),
"azurerm_network_interface": dataSourceArmNetworkInterface(),
"azurerm_network_security_group": dataSourceArmNetworkSecurityGroup(),
"azurerm_network_watcher": dataSourceArmNetworkWatcher(),
"azurerm_notification_hub_namespace": dataSourceNotificationHubNamespace(),
"azurerm_notification_hub": dataSourceNotificationHub(),
"azurerm_platform_image": dataSourceArmPlatformImage(),
Expand Down Expand Up @@ -189,6 +190,7 @@ func Provider() terraform.ResourceProvider {
"azurerm_cdn_endpoint": resourceArmCdnEndpoint(),
"azurerm_cdn_profile": resourceArmCdnProfile(),
"azurerm_cognitive_account": resourceArmCognitiveAccount(),
"azurerm_connection_monitor": resourceArmConnectionMonitor(),
"azurerm_container_group": resourceArmContainerGroup(),
"azurerm_container_registry": resourceArmContainerRegistry(),
"azurerm_container_service": resourceArmContainerService(),
Expand Down
Loading

0 comments on commit 412001c

Please sign in to comment.