Skip to content

Commit

Permalink
Fixes post code review
Browse files Browse the repository at this point in the history
  • Loading branch information
cventr-agilelab committed Jul 5, 2020
1 parent 77579e3 commit b7a46a9
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ func TestAccAzureRMVirtualNetworkGatewayConnection_ipsecpolicy(t *testing.T) {
})
}

func TestAccAzureRMVirtualNetworkGatewayConnection_trafficselectorpolicy(t *testing.T) {
func TestAccAzureRMVirtualNetworkGatewayConnection_trafficSelectorPolicy(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_virtual_network_gateway_connection", "test")

resource.ParallelTest(t, resource.TestCase{
Expand All @@ -125,9 +125,9 @@ func TestAccAzureRMVirtualNetworkGatewayConnection_trafficselectorpolicy(t *test
Config: testAccAzureRMVirtualNetworkGatewayConnection_trafficselectorpolicy(data),
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMVirtualNetworkGatewayConnectionExists(data.ResourceName),
resource.TestCheckResourceAttr(data.ResourceName, "traffic_selector_policy.0.local_address_ranges.0", "10.66.18.0/24"),
resource.TestCheckResourceAttr(data.ResourceName, "traffic_selector_policy.0.local_address_ranges.1", "10.66.17.0/24"),
resource.TestCheckResourceAttr(data.ResourceName, "traffic_selector_policy.0.remote_address_ranges.0", "10.1.1.0/24"),
resource.TestCheckResourceAttr(data.ResourceName, "traffic_selector_policy.0.local_address_cidrs.0", "10.66.18.0/24"),
resource.TestCheckResourceAttr(data.ResourceName, "traffic_selector_policy.0.local_address_cidrs.1", "10.66.17.0/24"),
resource.TestCheckResourceAttr(data.ResourceName, "traffic_selector_policy.0.remote_address_cidrs.0", "10.1.1.0/24"),
),
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -284,10 +284,11 @@ func flattenArmVirtualNetworkGatewayConnectionDataSourcePolicyTrafficSelectors(t

if trafficSelectorPolicies != nil {
for _, trafficSelectorPolicy := range *trafficSelectorPolicies {
schemaTrafficSelectorPolicy := make(map[string]interface{})
schemaTrafficSelectorPolicy["local_address_cidrs"] = trafficSelectorPolicy.LocalAddressRanges
schemaTrafficSelectorPolicy["remote_address_cidrs"] = trafficSelectorPolicy.RemoteAddressRanges
schemaTrafficSelectorPolicies = append(schemaTrafficSelectorPolicies, schemaTrafficSelectorPolicy)
schemaTrafficSelectorPolicies = append(schemaTrafficSelectorPolicies, map[string]interface{}{
"local_address_cidrs": utils.FlattenStringSlice(trafficSelectorPolicy.LocalAddressRanges),
"remote_address_cidrs": utils.FlattenStringSlice(trafficSelectorPolicy.RemoteAddressRanges),
})

}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -418,11 +418,9 @@ func resourceArmVirtualNetworkGatewayConnectionRead(d *schema.ResourceData, meta
}
}

if conn.TrafficSelectorPolicies != nil {
trafficSelectorPolicies := flattenArmVirtualNetworkGatewayConnectionTrafficSelectorPolicies(conn.TrafficSelectorPolicies)
if err := d.Set("traffic_selector_policy", trafficSelectorPolicies); err != nil {
return fmt.Errorf("Error setting `traffic_selector_policy`: %+v", err)
}
trafficSelectorPolicies := flattenArmVirtualNetworkGatewayConnectionTrafficSelectorPolicies(conn.TrafficSelectorPolicies)
if err := d.Set("traffic_selector_policy", trafficSelectorPolicies); err != nil {
return fmt.Errorf("Error setting `traffic_selector_policy`: %+v", err)
}

return tags.FlattenAndSet(d, resp.Tags)
Expand Down Expand Up @@ -629,18 +627,10 @@ func expandArmVirtualNetworkGatewayConnectionTrafficSelectorPolicies(schemaTraff
schemaTrafficSelectorPolicy := d.(map[string]interface{})
trafficSelectorPolicy := &network.TrafficSelectorPolicy{}
if localAddressRanges, ok := schemaTrafficSelectorPolicy["local_address_cidrs"].([]interface{}); ok {
localAddressRangesArr := make([]string, 0, len(localAddressRanges))
for _, l := range localAddressRanges {
localAddressRangesArr = append(localAddressRangesArr, l.(string))
}
trafficSelectorPolicy.LocalAddressRanges = &localAddressRangesArr
trafficSelectorPolicy.LocalAddressRanges = utils.ExpandStringSlice(localAddressRanges)
}
if remoteAddressRanges, ok := schemaTrafficSelectorPolicy["remote_address_cidrs"].([]interface{}); ok {
remoteAddressRangesArr := make([]string, 0, len(remoteAddressRanges))
for _, l := range remoteAddressRanges {
remoteAddressRangesArr = append(remoteAddressRangesArr, l.(string))
}
trafficSelectorPolicy.RemoteAddressRanges = &remoteAddressRangesArr
trafficSelectorPolicy.RemoteAddressRanges = utils.ExpandStringSlice(remoteAddressRanges)
}

trafficSelectorPolicies = append(trafficSelectorPolicies, *trafficSelectorPolicy)
Expand Down Expand Up @@ -683,10 +673,12 @@ func flattenArmVirtualNetworkGatewayConnectionTrafficSelectorPolicies(trafficSel

if trafficSelectorPolicies != nil {
for _, trafficSelectorPolicy := range *trafficSelectorPolicies {
schemaTrafficSelectorPolicy := make(map[string]interface{})
schemaTrafficSelectorPolicy["local_address_cidrs"] = trafficSelectorPolicy.LocalAddressRanges
schemaTrafficSelectorPolicy["remote_address_cidrs"] = trafficSelectorPolicy.RemoteAddressRanges
schemaTrafficSelectorPolicies = append(schemaTrafficSelectorPolicies, schemaTrafficSelectorPolicy)

schemaTrafficSelectorPolicies = append(schemaTrafficSelectorPolicies, map[string]interface{}{
"local_address_cidrs": utils.FlattenStringSlice(trafficSelectorPolicy.LocalAddressRanges),
"remote_address_cidrs": utils.FlattenStringSlice(trafficSelectorPolicy.RemoteAddressRanges),
})

}
}

Expand Down
1 change: 1 addition & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ github.com/hashicorp/terraform-config-inspect v0.0.0-20191115094559-17f92b0546e8
github.com/hashicorp/terraform-config-inspect v0.0.0-20191115094559-17f92b0546e8/go.mod h1:p+ivJws3dpqbp1iP84+npOyAmTTOLMgCzrXd3GSdn/A=
github.com/hashicorp/terraform-plugin-sdk v1.6.0 h1:Um5hsAL7kKsfTHtan8lybY/d03F2bHu4fjRB1H6Ag4U=
github.com/hashicorp/terraform-plugin-sdk v1.6.0/go.mod h1:H5QLx/uhwfxBZ59Bc5SqT19M4i+fYt7LZjHTpbLZiAg=
github.com/hashicorp/terraform-plugin-sdk v1.12.0 h1:HPp65ShSsKUMPf6jD50UQn/xAjyrGVO4FxI63bvu+pc=
github.com/hashicorp/terraform-svchost v0.0.0-20191011084731-65d371908596 h1:hjyO2JsNZUKT1ym+FAdlBEkGPevazYsmVgIMw7dVELg=
github.com/hashicorp/terraform-svchost v0.0.0-20191011084731-65d371908596/go.mod h1:kNDNcF7sN4DocDLBkQYz73HGKwN1ANB1blq4lIYLYvg=
github.com/hashicorp/yamux v0.0.0-20180604194846-3520598351bb/go.mod h1:+NfK9FKeTrX5uv1uIXGdwYDTeHna2qgaIlx54MXqjAM=
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ output "virtual_network_gateway_connection_id" {
Only a single policy can be defined for a connection. For details on
custom policies refer to [the relevant section in the Azure documentation](https://docs.microsoft.com/en-us/azure/vpn-gateway/vpn-gateway-ipsecikepolicy-rm-powershell).

* `traffic_selector_policy` (Optional) A `traffic_selector_policy` which allows to specify traffic selector policy proposal to be used in a virtual network gateway connection.
* `traffic_selector_policy` A `traffic_selector_policy` which allows to specify traffic selector policy proposal to be used in a virtual network gateway connection.
Only one block can be defined for a connection.
For details about traffic selectors refer to [the relevant section in the Azure documentation](https://docs.microsoft.com/en-us/azure/vpn-gateway/vpn-gateway-connect-multiple-policybased-rm-ps).

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,10 @@ The following arguments are supported:
Only a single policy can be defined for a connection. For details on
custom policies refer to [the relevant section in the Azure documentation](https://docs.microsoft.com/en-us/azure/vpn-gateway/vpn-gateway-ipsecikepolicy-rm-powershell).

* `traffic_selector_policy` A `traffic_selector_policy` which allows to specify traffic selector policy proposal to be used in a virtual network gateway connection.
Only one block can be defined for a connection.
For details about traffic selectors refer to [the relevant section in the Azure documentation](https://docs.microsoft.com/en-us/azure/vpn-gateway/vpn-gateway-connect-multiple-policybased-rm-ps).

* `tags` - (Optional) A mapping of tags to assign to the resource.

The `ipsec_policy` block supports:
Expand Down

0 comments on commit b7a46a9

Please sign in to comment.