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_watcher_flow_log: Add 2 more resource types to target_resource_id #28177

Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ func resourceNetworkWatcherFlowLog() *pluginsdk.Resource {
ValidateFunc: validation.Any(
networksecuritygroups.ValidateNetworkSecurityGroupID,
commonids.ValidateVirtualNetworkID,
commonids.ValidateSubnetID,
commonids.ValidateNetworkInterfaceID,
),
},

Expand Down Expand Up @@ -422,6 +424,10 @@ func resourceNetworkWatcherFlowLogRead(d *pluginsdk.ResourceData, meta interface
targetIsNSG = true
} else if vnetId, err := commonids.ParseVirtualNetworkIDInsensitively(props.TargetResourceId); err == nil {
targetResourceId = vnetId.ID()
} else if subnetId, err := commonids.ParseSubnetIDInsensitively(props.TargetResourceId); err == nil {
targetResourceId = subnetId.ID()
} else if nicId, err := commonids.ParseNetworkInterfaceIDInsensitively(props.TargetResourceId); err == nil {
targetResourceId = nicId.ID()
}

if !features.FivePointOhBeta() && targetIsNSG {
Expand Down
112 changes: 112 additions & 0 deletions internal/services/network/network_watcher_flow_log_resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,36 @@ func testAccNetworkWatcherFlowLog_basicWithVirtualNetwork(t *testing.T) {
})
}

func testAccNetworkWatcherFlowLog_basicWithSubnet(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_network_watcher_flow_log", "test")
r := NetworkWatcherFlowLogResource{}

data.ResourceSequentialTest(t, r, []acceptance.TestStep{
{
Config: r.basicConfigWithSubnet(data),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
},
data.ImportStep(),
})
}

func testAccNetworkWatcherFlowLog_basicWithNIC(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_network_watcher_flow_log", "test")
r := NetworkWatcherFlowLogResource{}

data.ResourceSequentialTest(t, r, []acceptance.TestStep{
{
Config: r.basicConfigWithNIC(data),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
},
data.ImportStep(),
})
}

func testAccNetworkWatcherFlowLog_requiresImport(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_network_watcher_flow_log", "test")
r := NetworkWatcherFlowLogResource{}
Expand Down Expand Up @@ -396,6 +426,88 @@ resource "azurerm_network_watcher_flow_log" "test" {
`, r.prerequisites(data), data.RandomInteger, data.RandomInteger)
}

func (r NetworkWatcherFlowLogResource) basicConfigWithSubnet(data acceptance.TestData) string {
return fmt.Sprintf(`
%s

resource "azurerm_virtual_network" "test" {
name = "acctestvn-%d"
address_space = ["10.0.0.0/16"]
location = azurerm_resource_group.test.location
resource_group_name = azurerm_resource_group.test.name
}

resource "azurerm_subnet" "test" {
name = "acctestsubnet-%d"
resource_group_name = azurerm_resource_group.test.name
virtual_network_name = azurerm_virtual_network.test.name
address_prefixes = ["10.0.1.0/24"]
}

resource "azurerm_network_watcher_flow_log" "test" {
network_watcher_name = azurerm_network_watcher.test.name
resource_group_name = azurerm_resource_group.test.name
name = "flowlog-%d"

target_resource_id = azurerm_subnet.test.id
storage_account_id = azurerm_storage_account.test.id
enabled = true

retention_policy {
enabled = false
days = 0
}
}
`, r.prerequisites(data), data.RandomInteger, data.RandomInteger, data.RandomInteger)
}

func (r NetworkWatcherFlowLogResource) basicConfigWithNIC(data acceptance.TestData) string {
return fmt.Sprintf(`
%s

resource "azurerm_virtual_network" "test" {
name = "acctestvn-%d"
address_space = ["10.0.0.0/16"]
location = azurerm_resource_group.test.location
resource_group_name = azurerm_resource_group.test.name
}

resource "azurerm_subnet" "test" {
name = "acctestsubnet-%d"
resource_group_name = azurerm_resource_group.test.name
virtual_network_name = azurerm_virtual_network.test.name
address_prefixes = ["10.0.1.0/24"]
}

resource "azurerm_network_interface" "test" {
name = "acctestnic-%d"
location = azurerm_resource_group.test.location
resource_group_name = azurerm_resource_group.test.name

ip_configuration {
name = "internal"
subnet_id = azurerm_subnet.test.id
private_ip_address_allocation = "Dynamic"
}
}

resource "azurerm_network_watcher_flow_log" "test" {
network_watcher_name = azurerm_network_watcher.test.name
resource_group_name = azurerm_resource_group.test.name
name = "flowlog-%d"

target_resource_id = azurerm_network_interface.test.id
storage_account_id = azurerm_storage_account.test.id
enabled = true

retention_policy {
enabled = false
days = 0
}
}
`, r.prerequisites(data), data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger)
}

func (r NetworkWatcherFlowLogResource) requiresImport(data acceptance.TestData) string {
if !features.FivePointOhBeta() {
return fmt.Sprintf(`
Expand Down
2 changes: 2 additions & 0 deletions internal/services/network/network_watcher_resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ func TestAccNetworkWatcher(t *testing.T) {
"FlowLog": {
"basic": testAccNetworkWatcherFlowLog_basic,
"basicWithVirtualNetwork": testAccNetworkWatcherFlowLog_basicWithVirtualNetwork,
"basicWithSubnet": testAccNetworkWatcherFlowLog_basicWithSubnet,
"basicWithNIC": testAccNetworkWatcherFlowLog_basicWithNIC,
"requiresImport": testAccNetworkWatcherFlowLog_requiresImport,
"disabled": testAccNetworkWatcherFlowLog_disabled,
"reenabled": testAccNetworkWatcherFlowLog_reenabled,
Expand Down
2 changes: 1 addition & 1 deletion website/docs/d/mssql_managed_database.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,4 @@ A `point_in_time_restore` block exports the following:

The `timeouts` block allows you to specify [timeouts](https://www.terraform.io/language/resources/syntax#operation-timeouts) for certain actions:

* `read` - (Defaults to 5 minutes) Used when retrieving the Azure SQL Azure Managed Database.
* `read` - (Defaults to 5 minutes) Used when retrieving the Azure SQL Azure Managed Database.
6 changes: 3 additions & 3 deletions website/docs/r/network_watcher_flow_log.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ resource "azurerm_network_watcher_flow_log" "test" {
resource_group_name = azurerm_resource_group.example.name
name = "example-log"

network_security_group_id = azurerm_network_security_group.test.id
storage_account_id = azurerm_storage_account.test.id
enabled = true
target_resource_id = azurerm_network_security_group.test.id
storage_account_id = azurerm_storage_account.test.id
enabled = true

retention_policy {
enabled = true
Expand Down
Loading