diff --git a/internal/services/devtestlabs/dev_test_virtual_network_resource.go b/internal/services/devtestlabs/dev_test_virtual_network_resource.go index 0540d0264f05..ee52cc219292 100644 --- a/internal/services/devtestlabs/dev_test_virtual_network_resource.go +++ b/internal/services/devtestlabs/dev_test_virtual_network_resource.go @@ -99,6 +99,37 @@ func resourceArmDevTestVirtualNetwork() *pluginsdk.Resource { Default: string(virtualnetworks.UsagePermissionTypeAllow), ValidateFunc: validate.DevTestVirtualNetworkUsagePermissionType(), }, + + "shared_public_ip_address": { + Type: pluginsdk.TypeList, + Optional: true, + MaxItems: 1, + Elem: &pluginsdk.Resource{ + Schema: map[string]*pluginsdk.Schema{ + "allowed_ports": { + Type: pluginsdk.TypeList, + Optional: true, + Elem: &pluginsdk.Resource{ + Schema: map[string]*pluginsdk.Schema{ + "backend_port": { + Type: pluginsdk.TypeInt, + Optional: true, + }, + + "transport_protocol": { + Type: pluginsdk.TypeString, + Optional: true, + ValidateFunc: validation.StringInSlice([]string{ + string(virtualnetworks.TransportProtocolTcp), + string(virtualnetworks.TransportProtocolUdp), + }, false), + }, + }, + }, + }, + }, + }, + }, }, }, }, @@ -305,11 +336,13 @@ func expandDevTestVirtualNetworkSubnets(input []interface{}, subscriptionId, res for _, val := range input { v := val.(map[string]interface{}) + subnet := virtualnetworks.SubnetOverride{ - ResourceId: pointer.To(subnetId.ID()), - LabSubnetName: pointer.To(name), - UsePublicIPAddressPermission: pointer.To(virtualnetworks.UsagePermissionType(v["use_public_ip_address"].(string))), - UseInVMCreationPermission: pointer.To(virtualnetworks.UsagePermissionType(v["use_in_virtual_machine_creation"].(string))), + ResourceId: pointer.To(subnetId.ID()), + LabSubnetName: pointer.To(name), + UsePublicIPAddressPermission: pointer.To(virtualnetworks.UsagePermissionType(v["use_public_ip_address"].(string))), + UseInVMCreationPermission: pointer.To(virtualnetworks.UsagePermissionType(v["use_in_virtual_machine_creation"].(string))), + SharedPublicIPAddressConfiguration: expandDevTestVirtualNetworkSubnetIpAddressConfiguration(v["shared_public_ip_address"].([]interface{})), } results = append(results, subnet) } @@ -317,6 +350,34 @@ func expandDevTestVirtualNetworkSubnets(input []interface{}, subscriptionId, res return &results } +func expandDevTestVirtualNetworkSubnetIpAddressConfiguration(input []interface{}) *virtualnetworks.SubnetSharedPublicIPAddressConfiguration { + if len(input) == 0 { + return nil + } + + v := input[0].(map[string]interface{}) + + return &virtualnetworks.SubnetSharedPublicIPAddressConfiguration{ + AllowedPorts: expandDevTestVirtualNetworkSubnetAllowedPorts(v["allowed_ports"].([]interface{})), + } +} + +func expandDevTestVirtualNetworkSubnetAllowedPorts(input []interface{}) *[]virtualnetworks.Port { + results := make([]virtualnetworks.Port, 0) + + for _, val := range input { + v := val.(map[string]interface{}) + + allowedPort := virtualnetworks.Port{ + BackendPort: pointer.To(int64(v["backend_port"].(int))), + TransportProtocol: pointer.To(virtualnetworks.TransportProtocol(v["transport_protocol"].(string))), + } + results = append(results, allowedPort) + } + + return &results +} + func flattenDevTestVirtualNetworkSubnets(input *[]virtualnetworks.SubnetOverride) []interface{} { outputs := make([]interface{}, 0) if input == nil { @@ -330,9 +391,41 @@ func flattenDevTestVirtualNetworkSubnets(input *[]virtualnetworks.SubnetOverride } output["use_public_ip_address"] = v.UsePublicIPAddressPermission output["use_in_virtual_machine_creation"] = v.UseInVMCreationPermission + output["shared_public_ip_address"] = flattenDevTestVirtualNetworkSubnetIpAddressConfiguration(v.SharedPublicIPAddressConfiguration) outputs = append(outputs, output) } return outputs } + +func flattenDevTestVirtualNetworkSubnetIpAddressConfiguration(input *virtualnetworks.SubnetSharedPublicIPAddressConfiguration) []interface{} { + outputs := make([]interface{}, 0) + + if input == nil { + return outputs + } + + output := make(map[string]interface{}) + if input.AllowedPorts != nil { + output["allowed_ports"] = flattenDevTestVirtualNetworkSubnetAllowedPorts(input.AllowedPorts) + } + outputs = append(outputs, output) + return outputs +} + +func flattenDevTestVirtualNetworkSubnetAllowedPorts(input *[]virtualnetworks.Port) []interface{} { + outputs := make([]interface{}, 0) + if input == nil { + return outputs + } + + for _, v := range *input { + output := make(map[string]interface{}) + output["backend_port"] = pointer.From(v.BackendPort) + output["transport_protocol"] = pointer.From(v.TransportProtocol) + outputs = append(outputs, output) + } + + return outputs +} diff --git a/internal/services/devtestlabs/dev_test_virtual_network_resource_test.go b/internal/services/devtestlabs/dev_test_virtual_network_resource_test.go index f2232c4118ea..a6a22f8f1889 100644 --- a/internal/services/devtestlabs/dev_test_virtual_network_resource_test.go +++ b/internal/services/devtestlabs/dev_test_virtual_network_resource_test.go @@ -203,6 +203,16 @@ resource "azurerm_dev_test_virtual_network" "test" { subnet { use_public_ip_address = "Deny" use_in_virtual_machine_creation = "Allow" + shared_public_ip_address { + allowed_ports { + backend_port = 22 + transport_protocol = "Tcp" + } + allowed_ports { + backend_port = 80 + transport_protocol = "Tcp" + } + } } } `, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) diff --git a/website/docs/r/dev_test_virtual_network.html.markdown b/website/docs/r/dev_test_virtual_network.html.markdown index 256aedd1a5d2..2e3c748a205b 100644 --- a/website/docs/r/dev_test_virtual_network.html.markdown +++ b/website/docs/r/dev_test_virtual_network.html.markdown @@ -64,6 +64,22 @@ A `subnet` block supports the following: * `use_in_virtual_machine_creation` - (Optional) Can this subnet be used for creating Virtual Machines? Possible values are `Allow`, `Default` and `Deny`. Defaults to `Allow`. +* `shared_public_ip_address` - (Optional) A `shared_public_ip_address` block as defined below. + +--- + +A `shared_public_ip_address` block supports the following: + +* `allowed_ports` - (Optional) A list of `allowed_ports` blocks as defined below. + +--- + +An `allowed_ports` block supports the following: + +* `backend_port` - (Optional) The port on the Virtual Machine that the traffic will be sent to. + +* `transport_protocol` - (Optional) The transport protocol that the traffic will use. Possible values are `TCP` and `UDP`. + ## Attributes Reference In addition to the Arguments listed above - the following Attributes are exported: