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

Add Connection Monitor resource and Network Watcher data source #2791

Merged
merged 6 commits into from
Feb 19, 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
5 changes: 5 additions & 0 deletions azurerm/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,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 @@ -909,6 +910,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,
},
lewinski marked this conversation as resolved.
Show resolved Hide resolved

"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 @@ -133,6 +133,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 @@ -188,6 +189,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