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_network_connection_monitor - support coverage_level, excluded_ip_addresses, included_ip_addresses, target_resource_id, resource_type #11540

Merged
Original file line number Diff line number Diff line change
Expand Up @@ -200,10 +200,31 @@ func resourceNetworkConnectionMonitor() *schema.Resource {
},
},

"resource_id": {
katbyte marked this conversation as resolved.
Show resolved Hide resolved
Type: schema.TypeString,
Optional: true,
Computed: true,
manicminer marked this conversation as resolved.
Show resolved Hide resolved
ValidateFunc: validation.Any(
computeValidate.VirtualMachineID,
logAnalyticsValidate.LogAnalyticsWorkspaceID,
),
},

"type": {
katbyte marked this conversation as resolved.
Show resolved Hide resolved
neil-yechenwei marked this conversation as resolved.
Show resolved Hide resolved
Type: schema.TypeString,
Optional: true,
ValidateFunc: validation.StringInSlice([]string{
string(network.MMAWorkspaceMachine),
manicminer marked this conversation as resolved.
Show resolved Hide resolved
}, false),
},

// TODO 3.0 - remove this property
"virtual_machine_id": {
Type: schema.TypeString,
Optional: true,
Computed: true,
ValidateFunc: computeValidate.VirtualMachineID,
Deprecated: "Deprecated in favour of `resource_id` since the service API supports more resource types",
manicminer marked this conversation as resolved.
Show resolved Hide resolved
},
},
},
Expand Down Expand Up @@ -600,10 +621,18 @@ func expandNetworkConnectionMonitorEndpoint(input []interface{}) *[]network.Conn
result.Address = utils.String(address.(string))
}

if resourceId := v["virtual_machine_id"]; resourceId != "" {
if resourceId := v["resource_id"]; resourceId != "" {
result.ResourceID = utils.String(resourceId.(string))
}

if endpointType := v["type"]; endpointType != "" {
result.Type = network.EndpointType(endpointType.(string))
manicminer marked this conversation as resolved.
Show resolved Hide resolved
}

if vmId := v["virtual_machine_id"]; vmId != "" {
manicminer marked this conversation as resolved.
Show resolved Hide resolved
result.ResourceID = utils.String(vmId.(string))
}

results = append(results, result)
}

Expand Down Expand Up @@ -814,16 +843,22 @@ func flattenNetworkConnectionMonitorEndpoint(input *[]network.ConnectionMonitorE
address = *item.Address
}

var endpointType network.EndpointType
manicminer marked this conversation as resolved.
Show resolved Hide resolved
if item.Type != "" {
endpointType = item.Type
}

var resourceId string
if item.ResourceID != nil {
resourceId = *item.ResourceID
}

v := map[string]interface{}{
"name": name,
"address": address,
"filter": flattenNetworkConnectionMonitorEndpointFilter(item.Filter),
"virtual_machine_id": resourceId,
"name": name,
"address": address,
"resource_id": resourceId,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should set virtual_machine_id too whilst it's still in the schema

Copy link
Contributor Author

@neil-yechenwei neil-yechenwei Apr 30, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After tested, there is diff when the virtual_machine_id property isn't specified in tf config file but it is set in state file. Seems Computed: true doesn't work in TypeSet. So I have to not set it in state file. Otherwise, test case would fail.

"type": endpointType,
"filter": flattenNetworkConnectionMonitorEndpointFilter(item.Filter),
}

results = append(results, v)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,35 @@ func testAccNetworkConnectionMonitor_icmpConfiguration(t *testing.T) {
})
}

func testAccNetworkConnectionMonitor_endpointType(t *testing.T) {
manicminer marked this conversation as resolved.
Show resolved Hide resolved
data := acceptance.BuildTestData(t, "azurerm_network_connection_monitor", "test")
r := NetworkConnectionMonitorResource{}

data.ResourceTest(t, r, []resource.TestStep{
{
Config: r.endpointType(data),
manicminer marked this conversation as resolved.
Show resolved Hide resolved
Check: resource.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
},
data.ImportStep(),
{
Config: r.basicAddressConfig(data),
Check: resource.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
},
data.ImportStep(),
{
Config: r.endpointType(data),
manicminer marked this conversation as resolved.
Show resolved Hide resolved
Check: resource.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
},
data.ImportStep(),
})
}

func (t NetworkConnectionMonitorResource) Exists(ctx context.Context, clients *clients.Client, state *terraform.InstanceState) (*bool, error) {
id, err := parse.ConnectionMonitorID(state.ID)
if err != nil {
Expand Down Expand Up @@ -394,8 +423,8 @@ resource "azurerm_network_connection_monitor" "test" {
location = azurerm_network_watcher.test.location

endpoint {
name = "source"
virtual_machine_id = azurerm_virtual_machine.src.id
name = "source"
resource_id = azurerm_virtual_machine.src.id
}

endpoint {
Expand Down Expand Up @@ -441,8 +470,8 @@ resource "azurerm_network_connection_monitor" "test" {
location = azurerm_network_watcher.test.location

endpoint {
name = "source"
virtual_machine_id = azurerm_virtual_machine.src.id
name = "source"
resource_id = azurerm_virtual_machine.src.id

filter {
item {
Expand Down Expand Up @@ -506,13 +535,13 @@ resource "azurerm_network_connection_monitor" "test" {
location = azurerm_network_watcher.test.location

endpoint {
name = "source"
virtual_machine_id = azurerm_virtual_machine.src.id
name = "source"
resource_id = azurerm_virtual_machine.src.id
}

endpoint {
name = "destination"
virtual_machine_id = azurerm_virtual_machine.dest.id
name = "destination"
resource_id = azurerm_virtual_machine.dest.id
}

test_configuration {
Expand Down Expand Up @@ -546,14 +575,14 @@ resource "azurerm_network_connection_monitor" "test" {
location = azurerm_network_watcher.test.location

endpoint {
name = "source"
virtual_machine_id = azurerm_virtual_machine.src.id
name = "source"
resource_id = azurerm_virtual_machine.src.id
}

endpoint {
name = "destination"
virtual_machine_id = azurerm_virtual_machine.dest.id
address = azurerm_network_interface.dest.private_ip_address
name = "destination"
resource_id = azurerm_virtual_machine.dest.id
address = azurerm_network_interface.dest.private_ip_address
}

test_configuration {
Expand Down Expand Up @@ -587,8 +616,8 @@ resource "azurerm_network_connection_monitor" "test" {
location = azurerm_network_watcher.test.location

endpoint {
name = "source"
virtual_machine_id = azurerm_virtual_machine.src.id
name = "source"
resource_id = azurerm_virtual_machine.src.id

filter {
item {
Expand All @@ -601,8 +630,8 @@ resource "azurerm_network_connection_monitor" "test" {
}

endpoint {
name = "destination"
virtual_machine_id = azurerm_virtual_machine.dest.id
name = "destination"
resource_id = azurerm_virtual_machine.dest.id
}

test_configuration {
Expand Down Expand Up @@ -642,8 +671,8 @@ resource "azurerm_network_connection_monitor" "test" {
location = azurerm_network_watcher.test.location

endpoint {
name = "source"
virtual_machine_id = azurerm_virtual_machine.src.id
name = "source"
resource_id = azurerm_virtual_machine.src.id
}

test_configuration {
Expand Down Expand Up @@ -677,13 +706,13 @@ resource "azurerm_network_connection_monitor" "test" {
location = azurerm_network_watcher.test.location

endpoint {
name = "source"
virtual_machine_id = azurerm_virtual_machine.src.id
name = "source"
resource_id = azurerm_virtual_machine.src.id
}

endpoint {
name = "destination"
virtual_machine_id = azurerm_virtual_machine.src.id
name = "destination"
resource_id = azurerm_virtual_machine.src.id
}

test_configuration {
Expand Down Expand Up @@ -717,8 +746,8 @@ resource "azurerm_network_connection_monitor" "import" {
location = azurerm_network_connection_monitor.test.location

endpoint {
name = "source"
virtual_machine_id = azurerm_virtual_machine.src.id
name = "source"
resource_id = azurerm_virtual_machine.src.id
}

endpoint {
Expand Down Expand Up @@ -757,8 +786,8 @@ resource "azurerm_network_connection_monitor" "test" {
location = azurerm_network_watcher.test.location

endpoint {
name = "source"
virtual_machine_id = azurerm_virtual_machine.src.id
name = "source"
resource_id = azurerm_virtual_machine.src.id
}

endpoint {
Expand Down Expand Up @@ -806,8 +835,8 @@ resource "azurerm_network_connection_monitor" "test" {
location = azurerm_network_watcher.test.location

endpoint {
name = "source"
virtual_machine_id = azurerm_virtual_machine.src.id
name = "source"
resource_id = azurerm_virtual_machine.src.id
}

endpoint {
Expand Down Expand Up @@ -835,3 +864,53 @@ resource "azurerm_network_connection_monitor" "test" {
}
`, r.baseConfig(data), data.RandomInteger)
}

func (r NetworkConnectionMonitorResource) endpointType(data acceptance.TestData) string {
manicminer marked this conversation as resolved.
Show resolved Hide resolved
return fmt.Sprintf(`
%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"
retention_in_days = 30
}

resource "azurerm_network_connection_monitor" "test" {
name = "acctest-CM-%d"
network_watcher_id = azurerm_network_watcher.test.id
location = azurerm_network_watcher.test.location

endpoint {
name = "source"
type = "MMAWorkspaceMachine"
address = "test.internal.domain.com"
resource_id = azurerm_log_analytics_workspace.test.id
}

endpoint {
name = "destination"
address = "terraform.io"
}

test_configuration {
name = "tcp"
protocol = "Tcp"

tcp_configuration {
port = 80
}
}

test_group {
name = "testtg"
destination_endpoints = ["destination"]
source_endpoints = ["source"]
test_configuration_names = ["tcp"]
}

depends_on = [azurerm_virtual_machine_extension.src]
}
`, r.baseConfig(data), data.RandomInteger, data.RandomInteger)
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ func TestAccNetworkWatcher(t *testing.T) {
"httpConfiguration": testAccNetworkConnectionMonitor_httpConfiguration,
"icmpConfiguration": testAccNetworkConnectionMonitor_icmpConfiguration,
"bothAddressAndVirtualMachineId": testAccNetworkConnectionMonitor_withAddressAndVirtualMachineId,
"endpointType": testAccNetworkConnectionMonitor_endpointType,
},
"PacketCapture": {
"localDisk": testAccNetworkPacketCapture_localDisk,
Expand Down
10 changes: 7 additions & 3 deletions website/docs/r/network_connection_monitor.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,8 @@ resource "azurerm_network_connection_monitor" "example" {
location = azurerm_network_watcher.example.location

endpoint {
name = "source"
virtual_machine_id = azurerm_virtual_machine.example.id
name = "source"
resource_id = azurerm_virtual_machine.example.id

filter {
item {
Expand Down Expand Up @@ -183,9 +183,13 @@ A `endpoint` block supports the following:

* `address` - (Optional) The IP address or domain name of the Network Connection Monitor endpoint.

* `resource_id` - (Optional) The resource ID which is used as the endpoint by the Network Connection Monitor.

* `filter` - (Optional) A `filter` block as defined below.

* `virtual_machine_id` - (Optional) The ID of the Virtual Machine which is used as the endpoint by the Network Connection Monitor.
* `type` - (Optional) The endpoint type of the Network Connection Monitor. Possible value is `MMAWorkspaceMachine`.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's be sure to add any other values we can support :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated


* `virtual_machine_id` - (Optional/ **Deprecated) The ID of the Virtual Machine which is used as the endpoint by the Network Connection Monitor.
manicminer marked this conversation as resolved.
Show resolved Hide resolved

---

Expand Down