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

Fix for protocol upper/lower case handling #293

Merged
merged 59 commits into from
Jul 29, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
59 commits
Select commit Hold shift + click to select a range
18db1f2
Adding meta data creation with update support
vbauzys Jun 20, 2019
72722b6
Merge branch 'master' into vdc-metadata
vbauzys Jul 4, 2019
cd550d4
Add metadata functionality
vbauzys Jul 5, 2019
6eb7ea7
Address comments
vbauzys Jul 5, 2019
1ff0368
Change func names
vbauzys Jul 5, 2019
55009eb
Fix naming
vbauzys Jul 8, 2019
bd71e0b
Improve error message
vbauzys Jul 8, 2019
71df2ab
git push origin masterMerge branch 'master' of github.com:terraform-p…
vbauzys Jul 8, 2019
6dd5640
bump govcd version to PR
vbauzys Jul 15, 2019
6828239
Add implementation for support network type and handling IDs.
vbauzys Jul 15, 2019
6585559
Add missing file
vbauzys Jul 15, 2019
e247d25
Merge branch 'master' of github.com:terraform-providers/terraform-pro…
vbauzys Jul 15, 2019
6e8b128
Merge branch 'master' into nat_extNet_support
vbauzys Jul 15, 2019
e2f9b15
Improve changelog
vbauzys Jul 15, 2019
2607d2c
Fix
vbauzys Jul 16, 2019
4df154d
Improve comments
vbauzys Jul 17, 2019
b1bf437
Add update unit tests
vbauzys Jul 17, 2019
a8b5121
bump govcd to latest version
vbauzys Jul 18, 2019
24c4dc4
Changes according latest govcd changes
vbauzys Jul 18, 2019
3ee3b67
Add improvements
vbauzys Jul 19, 2019
668ccb1
Add comment fix
vbauzys Jul 19, 2019
89028b2
Add improvements in comments
vbauzys Jul 19, 2019
72a10b4
Add comment fix
vbauzys Jul 19, 2019
103a0f5
Add comment fix
vbauzys Jul 19, 2019
43cba68
Removed comments
vbauzys Jul 19, 2019
6d2d64a
Bump govcd version
vbauzys Jul 19, 2019
05b96e6
Change test timeout from 90m to 120m
vbauzys Jul 22, 2019
300c845
Add check for case when two diff type netw has same name
vbauzys Jul 22, 2019
0a4bd77
Add comment fix
vbauzys Jul 22, 2019
cf1e7c2
git push origin masterMerge branch 'master' of github.com:terraform-p…
vbauzys Jul 23, 2019
be6790f
Merge branch 'master' of github.com:terraform-providers/terraform-pro…
vbauzys Jul 24, 2019
6f4c5cb
Merge branch 'master' of github.com:terraform-providers/terraform-pro…
vbauzys Jul 25, 2019
c73d402
Merge branch 'master' of github.com:terraform-providers/terraform-pro…
vbauzys Jul 26, 2019
c5573fc
Add comment fix
vbauzys Jul 26, 2019
efa0717
Fix issue with dnat rule read
vbauzys Jul 26, 2019
a75e244
Add check when network_type missing
vbauzys Jul 26, 2019
d2860c9
Improve check
vbauzys Jul 26, 2019
82c6dcb
Add fix to solve upper/lower case issue with protocol
vbauzys Jul 26, 2019
68f54a8
git push origin master
vbauzys Jul 26, 2019
09da96b
Fix example in documentation
vbauzys Jul 26, 2019
9b57423
Fix issue with dnat rule read
vbauzys Jul 26, 2019
fb22039
Add new version to doc
vbauzys Jul 26, 2019
456bcff
Improve doc
vbauzys Jul 26, 2019
9eac1b8
Improve doc
vbauzys Jul 26, 2019
c1a4539
Fix test, add protocol check
vbauzys Jul 26, 2019
a98c1b0
Improve doc
vbauzys Jul 26, 2019
860d39c
Improve test
vbauzys Jul 26, 2019
798f82c
Improve change log
vbauzys Jul 26, 2019
8dbd27a
Fix issue with dnat rule read
vbauzys Jul 26, 2019
d5a9079
Improve doc
vbauzys Jul 26, 2019
1faea3e
Improve change log
vbauzys Jul 26, 2019
5cb4349
Improve change log
vbauzys Jul 26, 2019
90b0dac
Improve change log
vbauzys Jul 26, 2019
18e43ad
Improve change log
vbauzys Jul 26, 2019
7f6ac08
Improve doc
vbauzys Jul 26, 2019
4b85b9b
Improve doc
vbauzys Jul 26, 2019
a8c7881
Fix issue with reading org netw Nat rule, add check for sys admin whe…
vbauzys Jul 26, 2019
394b6d4
Add improvements
vbauzys Jul 26, 2019
32c0daf
bump govcd version
vbauzys Jul 26, 2019
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
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,23 @@ FEATURES:
* `resource/vcd_org_vdc` added Org VDC update and full state read - [GH-275]
* `resource/vcd_org_vdc` added Org VDC metadata support - [GH-276]
* `resource/vcd_snat` added ability to choose network name and type. [GH-282]
* `resource/vcd_dnat` added ability to choose network name and type. [GH-282]
* `resource/vcd_dnat` added ability to choose network name and type. [GH-282, GH-292, GH-293]

IMPROVEMENTS:
* `resource/vcd_org_vdc`: Fix ignoring of resource guarantee values - [GH-265]
* `resource/vcd_org_vdc`: Org VDC state ID changed from name to vCD ID - [GH-275]
* Change resource handling to use locking mechanism when resource parallel handling is not supported by vCD. [GH-255]
* Fix issue when vApp is power cycled during member VM deletion. [GH-261]
* `resource/vcd_dnat`, `resource/vcd_snat` has got full read functionality. This means that on the next `plan/apply` it will detect if configuration has changed in vCD and propose to update it.

BUG FIXES:

* `resource/vcd_dnat and resource/vcd_snat` - fix resource destroy as it would still leave NAT rule in edge gateway. Fix works if network_name and network_type is used. [GH-282]

NOTES:
* `resource/vcd_dnat` `protocol` requires lower case values to be consistent with the underlying NSX API. This may result in invalid configuration if upper case was used previously!
* `resource/vcd_dnat` default value for `protocol` field changed from upper case `TCP` to lower case `tcp`, which may result in a single update when running `plan` on a configuration with a state file from an older version.

## 2.3.0 (May 29, 2019)

IMPROVEMENTS:
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ go 1.12

require (
github.com/hashicorp/terraform v0.12.0
github.com/vmware/go-vcloud-director/v2 v2.3.0-rc.2
github.com/vmware/go-vcloud-director/v2 v2.3.0
)
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -301,8 +301,8 @@ github.com/ulikunitz/xz v0.5.5/go.mod h1:2bypXElzHzzJZwzH67Y6wb67pO62Rzfn7BSiF4A
github.com/vmihailenco/msgpack v3.3.3+incompatible/go.mod h1:fy3FlTQTDXWkZ7Bh6AcGMlsjHatGryHQYUTf1ShIgkk=
github.com/vmihailenco/msgpack v4.0.1+incompatible h1:RMF1enSPeKTlXrXdOcqjFUElywVZjjC6pqse21bKbEU=
github.com/vmihailenco/msgpack v4.0.1+incompatible/go.mod h1:fy3FlTQTDXWkZ7Bh6AcGMlsjHatGryHQYUTf1ShIgkk=
github.com/vmware/go-vcloud-director/v2 v2.3.0-rc.2 h1:8Uh2iKTlsr8aBjgRCoFSYLBVN+oSMEpoye2lr9vP3u0=
github.com/vmware/go-vcloud-director/v2 v2.3.0-rc.2/go.mod h1:+Hq7ryFfgZqsO6mXH29RQFnpIMSujCOMI57otHoXHhQ=
github.com/vmware/go-vcloud-director/v2 v2.3.0 h1:o2iZxqZB4j1V/9oEaQYYwG5H+3/t8iqkTBziP05XpuE=
github.com/vmware/go-vcloud-director/v2 v2.3.0/go.mod h1:+Hq7ryFfgZqsO6mXH29RQFnpIMSujCOMI57otHoXHhQ=
github.com/xanzy/ssh-agent v0.2.1/go.mod h1:mLlQY/MoOhWBj+gOGMQkOeiEvkx+8pJSI+0Bx9h2kr4=
github.com/xiang90/probing v0.0.0-20160813154853-07dd2e8dfe18/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU=
github.com/xlab/treeprint v0.0.0-20161029104018-1d6e34225557/go.mod h1:ce1O1j6UtZfjr22oyGxGLbauSBp2YVXpARAosm7dHBg=
Expand Down
148 changes: 0 additions & 148 deletions v2Plan.md

This file was deleted.

27 changes: 20 additions & 7 deletions vcd/resource_vcd_dnat.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,10 @@ func resourceVcdDNAT() *schema.Resource {
Required: true,
},
"protocol": &schema.Schema{
Type: schema.TypeString,
Optional: true,
Default: "TCP", // keep back compatibility as was hardcoded previously
Type: schema.TypeString,
Optional: true,
Default: "tcp", // keep back compatibility as was hardcoded previously
ValidateFunc: validateCase("lower"),
},
"icmp_sub_type": &schema.Schema{
Type: schema.TypeString,
Expand Down Expand Up @@ -130,6 +131,10 @@ func resourceVcdDNATCreate(d *schema.ResourceData, meta interface{}) error {
return fmt.Errorf("error creating DNAT rule: %#v", err)
}
} else if networkName != "" && networkType == "ext" {
if !vcdClient.Client.IsSysAdmin {
return fmt.Errorf("functionality requires system administrator privileges")
}

externalNetwork, err := govcd.GetExternalNetwork(vcdClient.VCDClient, networkName)
if err != nil {
return fmt.Errorf("unable to find external network: %s, err: %s", networkName, err)
Expand Down Expand Up @@ -204,22 +209,29 @@ func resourceVcdDNATRead(d *schema.ResourceData, meta interface{}) error {
d.Set("icmp_sub_type", natRule.GatewayNatRule.IcmpSubType)
d.Set("network_name", natRule.GatewayNatRule.Interface.Name)

orgVdcNetwork, _ := getOrgVdcNetwork(d, vcdClient, natRule.GatewayNatRule.Interface.Name)
orgVdcNetwork, err := getOrgVdcNetwork(d, vcdClient, natRule.GatewayNatRule.Interface.Name)
if orgVdcNetwork != nil {
d.Set("network_type", "org")
found = true
} else {
log.Printf("[DEBUG] didn't find org VDC network with name: %s, %#v", natRule.GatewayNatRule.Interface.Name, err)
}

_, extNetwErr := govcd.GetExternalNetwork(vcdClient.VCDClient, natRule.GatewayNatRule.Interface.Name)
if extNetwErr == nil {
d.Set("network_type", "ext")
found = true
} else {
log.Printf("[DEBUG] didn't find external network with name: %s, %#v", natRule.GatewayNatRule.Interface.Name, extNetwErr)
found = false
}

if orgVdcNetwork != nil && extNetwErr == nil {
return fmt.Errorf("found external network or org VCD network with same name: %s", natRule.GatewayNatRule.Interface.Name)
}

if orgVdcNetwork == nil && extNetwErr != nil {
return fmt.Errorf("issue updating resource state. Didn't find external network or org VCD network with name: %s", natRule.GatewayNatRule.Interface.Name)
}

return nil
} else {
// TODO remove when major release is done
for _, r := range edgeGateway.EdgeGateway.Configuration.EdgeGatewayServiceConfiguration.NatService.NatRule {
Expand All @@ -233,6 +245,7 @@ func resourceVcdDNATRead(d *schema.ResourceData, meta interface{}) error {
}

if !found {
log.Printf("[INFO] Removing from state.")
d.SetId("")
}

Expand Down
18 changes: 11 additions & 7 deletions vcd/resource_vcd_dnat_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ package vcd

import (
"fmt"
"regexp"
"testing"

"github.com/hashicorp/terraform/helper/resource"
Expand Down Expand Up @@ -49,8 +48,7 @@ func TestAccVcdDNAT_WithOrgNetw(t *testing.T) {
CheckDestroy: testAccCheckVcdDNATDestroy,
Steps: []resource.TestStep{
resource.TestStep{
Config: configText,
ExpectError: regexp.MustCompile(`After applying this step and refreshing, the plan was not empty:`),
Config: configText,
Check: resource.ComposeTestCheckFunc(
testAccCheckVcdDNATExists("vcd_dnat."+dnatName, &e),
resource.TestCheckResourceAttr(
Expand All @@ -61,6 +59,8 @@ func TestAccVcdDNAT_WithOrgNetw(t *testing.T) {
"vcd_dnat."+dnatName, "external_ip", testConfig.Networking.ExternalIp),
resource.TestCheckResourceAttr(
"vcd_dnat."+dnatName, "port", "7777"),
resource.TestCheckResourceAttr(
"vcd_dnat."+dnatName, "protocol", "tcp"),
resource.TestCheckResourceAttr(
"vcd_dnat."+dnatName, "internal_ip", "10.10.102.60"),
resource.TestCheckResourceAttr(
Expand Down Expand Up @@ -108,8 +108,7 @@ func TestAccVcdDNAT_WithExtNetw(t *testing.T) {
CheckDestroy: testAccCheckVcdDNATDestroy,
Steps: []resource.TestStep{
resource.TestStep{
Config: configText,
ExpectError: regexp.MustCompile(`After applying this step and refreshing, the plan was not empty:`),
Config: configText,
Check: resource.ComposeTestCheckFunc(
testAccCheckVcdDNATExists("vcd_dnat."+dnatName, &e),
resource.TestCheckResourceAttr(
Expand All @@ -120,6 +119,8 @@ func TestAccVcdDNAT_WithExtNetw(t *testing.T) {
"vcd_dnat."+dnatName, "external_ip", testConfig.Networking.ExternalIp),
resource.TestCheckResourceAttr(
"vcd_dnat."+dnatName, "port", "7777"),
resource.TestCheckResourceAttr(
"vcd_dnat."+dnatName, "protocol", "tcp"),
resource.TestCheckResourceAttr(
"vcd_dnat."+dnatName, "internal_ip", "10.10.102.60"),
resource.TestCheckResourceAttr(
Expand All @@ -129,8 +130,7 @@ func TestAccVcdDNAT_WithExtNetw(t *testing.T) {
),
},
resource.TestStep{
Config: updateText,
ExpectError: regexp.MustCompile(`After applying this step and refreshing, the plan was not empty:`),
Config: updateText,
Check: resource.ComposeTestCheckFunc(
testAccCheckVcdDNATExists("vcd_dnat."+dnatName, &e),
resource.TestCheckResourceAttr(
Expand All @@ -141,6 +141,8 @@ func TestAccVcdDNAT_WithExtNetw(t *testing.T) {
"vcd_dnat."+dnatName, "external_ip", testConfig.Networking.ExternalIp),
resource.TestCheckResourceAttr(
"vcd_dnat."+dnatName, "port", "8888"),
resource.TestCheckResourceAttr(
"vcd_dnat."+dnatName, "protocol", "udp"),
resource.TestCheckResourceAttr(
"vcd_dnat."+dnatName, "internal_ip", "10.10.102.80"),
resource.TestCheckResourceAttr(
Expand Down Expand Up @@ -379,6 +381,7 @@ resource "vcd_dnat" "{{.DnatName}}" {
edge_gateway = "{{.EdgeGateway}}"
external_ip = "{{.ExternalIp}}"
port = 7777
protocol = "tcp"
internal_ip = "10.10.102.60"
translated_port = 77
description = "{{.Description}}"
Expand All @@ -393,6 +396,7 @@ resource "vcd_dnat" "{{.DnatName}}" {
network_type = "ext"
edge_gateway = "{{.EdgeGateway}}"
external_ip = "{{.ExternalIp}}"
protocol = "udp"
port = 8888
internal_ip = "10.10.102.80"
translated_port = 88
Expand Down
2 changes: 1 addition & 1 deletion vendor/modules.txt
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ github.com/ulikunitz/xz/internal/hash
# github.com/vmihailenco/msgpack v4.0.1+incompatible
github.com/vmihailenco/msgpack
github.com/vmihailenco/msgpack/codes
# github.com/vmware/go-vcloud-director/v2 v2.3.0-rc.2
# github.com/vmware/go-vcloud-director/v2 v2.3.0
github.com/vmware/go-vcloud-director/v2/govcd
github.com/vmware/go-vcloud-director/v2/types/v56
github.com/vmware/go-vcloud-director/v2/util
Expand Down
2 changes: 1 addition & 1 deletion website/docs/index.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ The VMware vCloud Director provider is used to interact with the resources suppo

Use the navigation to the left to read about the available resources.

~> **NOTE:** The VMware vCloud Director Provider went through a refresh at the beginning of 2019 and some semantic changes were made compared to the previously available initial version. Please check docs for *v2.0+*, *v2.1+*, *v2.2+* labels and your existing .tf configuration files carefully when shifting to this new version.
~> **NOTE:** The VMware vCloud Director Provider went through a refresh at the beginning of 2019 and some semantic changes were made compared to the previously available initial version. Please check docs for *v2.0+*, *v2.1+*, *v2.2+*, *v2.4+* labels and your existing .tf configuration files carefully when shifting to this new version.

## Supported vCD Versions

Expand Down
13 changes: 8 additions & 5 deletions website/docs/r/dnat.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ description: |-
Provides a vCloud Director DNAT resource. This can be used to create, modify,
and delete destination NATs to map an external IP/port to an internal IP/port.

!> **Warning:** When advanced edge gateway is used and the rule is updated using UI, then Id mapping will be lost and terraform won't find the rule anymore and remove it from state.
~> **Note:** From v2.4+ `protocol` requires lower case values. This may result in invalid configuration if upper case was used previously.

!> **Warning:** When advanced edge gateway is used and the rule is updated using UI, then ID mapping will be lost and Terraform won't find the rule anymore and remove it from state.

## Example Usage

Expand All @@ -38,7 +40,7 @@ resource "vcd_dnat" "forIcmp" {
external_ip = "78.101.10.20"
port = -1 # "-1" == "any"
internal_ip = "10.10.0.5"
protocol = "ICMP"
protocol = "icmp"
icmp_sub_type = "router-solicitation"
}
```
Expand All @@ -52,9 +54,10 @@ The following arguments are supported:
* `port` - (Required) The port number to map. -1 translates to "any"
* `translated_port` - (Optional) The port number to map
* `internal_ip` - (Required) The IP of the VM to map to
* `protocol` - (Optional; *v2.0+*) The protocol type. Possible values are TCP, UDP, TCPUDP, ICMP, ANY. TCP is default to be backward compatible with previous version
* `protocol` - (Optional; *v2.0+*) The protocol type. Possible values are `tcp`, `udp`, `tcpupd`, `icmp`, `any`. `tcp` is default to be backward compatible with previous version
* `icmp_sub_type` - (Optional; *v2.0+*) The name of ICMP type. Possible values are address-mask-request, destination-unreachable, echo-request, echo-reply, parameter-problem, redirect, router-advertisement, router-solicitation, source-quench, time-exceeded, timestamp-request, timestamp-reply, any
* `network_type` - (Optional; *v2.4+*) Type of the network on which to apply the NAT rule. Possible values org or ext. *`network_type` will be a required field in the next major version.*
* `network_type` - (Optional; *v2.4+*) Type of the network on which to apply the NAT rule. Possible values `org` or `ext`. `ext` requires system administrator privileges. *`network_type` will be a required field in the next major version.*
* `network_name` - (Optional; *v2.4+*) The name of the network on which to apply the SNAT. *`network_name` will be a required field in the next major version.*
* `org` - (Optional; *v2.0+*) The name of organization to use, optional if defined at provider level. Useful when connected as sysadmin working across different organisations
* `vdc` - (Optional; *v2.0+*) The name of VDC to use, optional if defined at provider level
* `vdc` - (Optional; *v2.0+*) The name of VDC to use, optional if defined at provider level
* `description` - (Optional; *v2.4+*) - Description of item
Loading