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

Add implementation for vapp network static routing rules resource #520

Merged
merged 34 commits into from
Jun 26, 2020
Merged
Show file tree
Hide file tree
Changes from 22 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
524f25b
add changelog
vbauzys Jun 18, 2020
9c91e03
bump govcd
vbauzys Jun 23, 2020
4f40271
bump govcd
vbauzys Jun 23, 2020
344ed7d
Merge branch 'master' into vapp-routing
vbauzys Jun 23, 2020
3cb870b
Fixes after merge
vbauzys Jun 23, 2020
712e752
Fixes
vbauzys Jun 23, 2020
e49e8fa
Improve docs
vbauzys Jun 23, 2020
c6ce55d
Improve docs
vbauzys Jun 23, 2020
e5c094d
bump govcd andremove isVappNetwork
vbauzys Jun 25, 2020
c7a0446
add improvements
vbauzys Jun 25, 2020
f64b29f
improve docs
vbauzys Jun 25, 2020
bb5deaa
improve docs
vbauzys Jun 25, 2020
1aab621
improve docs
vbauzys Jun 25, 2020
a6c890c
improve docs
vbauzys Jun 25, 2020
ebb2800
improve docs
vbauzys Jun 25, 2020
71a6b09
improve docs
vbauzys Jun 25, 2020
686dd9c
improve docs
vbauzys Jun 25, 2020
6b5c19a
improve docs
vbauzys Jun 25, 2020
4856b61
Refactor: move NAT and FW enablement
vbauzys Jun 25, 2020
215fde7
improvements
vbauzys Jun 26, 2020
ff40132
bump govcd
vbauzys Jun 26, 2020
22e0ac6
bump govcd
vbauzys Jun 26, 2020
fd72a74
improve docs
vbauzys Jun 26, 2020
95e1f30
improve docs
vbauzys Jun 26, 2020
c11dfb9
Added warning for read
vbauzys Jun 26, 2020
b6f9337
Improve test
vbauzys Jun 26, 2020
cf0007b
bump govcd
vbauzys Jun 26, 2020
9b33ede
improve documentation
vbauzys Jun 26, 2020
be80a0a
improve documentation
vbauzys Jun 26, 2020
82d516a
improve comment
vbauzys Jun 26, 2020
2e99e6f
improve comment
vbauzys Jun 26, 2020
83ea0d0
improve comment
vbauzys Jun 26, 2020
9144dd2
improve comment
vbauzys Jun 26, 2020
d299703
bump govcd
vbauzys Jun 26, 2020
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ FEATURES:
* **New Resource:** `vcd_org_group` Org Group management [GH-513]
* **New Resource:** `resource/vcd_vapp_firewall_rules` vApp network firewall rules [GH-511]
* **New Resource:** `resource/vcd_vapp_nat_rules` vApp network NAT rules [GH-518]
* **New Resource:** `resource/vcd_vapp_static_routing` vApp network static routing rules [GH-520]

IMPROVEMENTS:

Expand Down
4 changes: 3 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ require (
github.com/hashicorp/hcl/v2 v2.3.0 // indirect
github.com/hashicorp/terraform-config-inspect v0.0.0-20191212124732-c6ae6269b9d7 // indirect
github.com/hashicorp/terraform-plugin-sdk v1.8.0
github.com/vmware/go-vcloud-director/v2 v2.8.0-beta.1
github.com/vmware/go-vcloud-director/v2 v2.8.0-alpha.8
golang.org/x/crypto v0.0.0-20200510223506-06a226fb4e37 // indirect
)

replace github.com/vmware/go-vcloud-director/v2 => github.com/vbauzysvmware/go-vcloud-director/v2 v2.0.0-20200626055020-86ee4364334d
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -207,12 +207,12 @@ github.com/stretchr/testify v1.5.1 h1:nOGnQDM7FYENwehXlg/kFVnos3rEvtKTjRvOWSzb6H
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
github.com/ulikunitz/xz v0.5.5 h1:pFrO0lVpTBXLpYw+pnLj6TbvHuyjXMfjGeCwSqCVwok=
github.com/ulikunitz/xz v0.5.5/go.mod h1:2bypXElzHzzJZwzH67Y6wb67pO62Rzfn7BSiF4ABRW8=
github.com/vbauzysvmware/go-vcloud-director/v2 v2.0.0-20200626055020-86ee4364334d h1:1K9cQwwIMb1mx4PoSPUFosY8FT8NSCvB9BYp6nqzSe4=
github.com/vbauzysvmware/go-vcloud-director/v2 v2.0.0-20200626055020-86ee4364334d/go.mod h1:QARPFI5EJce4Cs9g0gL5mlHGhdN7C40CyOqvh7c+RrA=
github.com/vmihailenco/msgpack v3.3.3+incompatible h1:wapg9xDUZDzGCNFlwc5SqI1rvcciqcxEHac4CYj89xI=
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.8.0-beta.1 h1:hP7wb+9A9jPxL2MYWgQlwyB0bOGzRnqK2q7PL/sa8Vc=
github.com/vmware/go-vcloud-director/v2 v2.8.0-beta.1/go.mod h1:QARPFI5EJce4Cs9g0gL5mlHGhdN7C40CyOqvh7c+RrA=
github.com/zclconf/go-cty v1.0.0/go.mod h1:xnAOWiHeOqg2nWS62VtQ7pbOu17FtxJNW8RLEih+O3s=
github.com/zclconf/go-cty v1.1.0/go.mod h1:xnAOWiHeOqg2nWS62VtQ7pbOu17FtxJNW8RLEih+O3s=
github.com/zclconf/go-cty v1.2.0/go.mod h1:hOPWgoHbaTUnI5k4D2ld+GRpFJSCe6bCM7m1q/N4PQ8=
Expand Down
10 changes: 0 additions & 10 deletions vcd/datasource_vcd_vapp_network.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,16 +73,6 @@ func datasourceVcdVappNetwork() *schema.Resource {
Computed: true,
Description: "org network name to which vapp network is connected",
},
"firewall_enabled": {
Type: schema.TypeBool,
Computed: true,
Description: "firewall service enabled or disabled. Default is true",
},
"nat_enabled": {
Type: schema.TypeBool,
Computed: true,
Description: "NAT service enabled or disabled. Default is true",
},
"retain_ip_mac_enabled": {
Type: schema.TypeBool,
Computed: true,
Expand Down
25 changes: 3 additions & 22 deletions vcd/datasource_vcd_vapp_network_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ func TestAccVcdVappNetworkDS(t *testing.T) {
const maxLeaseTime = 3500
const defaultLeaseTime = 2400
var guestVlanAllowed = true
var fwEnabled = false
var natEnabled = false
var retainIpMacEnabled = true

var params = StringMap{
Expand All @@ -52,8 +50,6 @@ func TestAccVcdVappNetworkDS(t *testing.T) {
"dhcpEnabled": "true",
"orgNetwork": "TestAccVcdVappNetworkDSOrgNetwork",
"EdgeGateway": testConfig.Networking.EdgeGateway,
"firewallEnabled": fwEnabled,
"natEnabled": natEnabled,
"retainIpMacEnabled": retainIpMacEnabled,
}
configText := templateFill(datasourceTestVappNetwork, params)
Expand Down Expand Up @@ -82,14 +78,14 @@ func TestAccVcdVappNetworkDS(t *testing.T) {
resource.TestCheckOutput("staticIpPoolStartAddress", startAddress),
resource.TestCheckOutput("staticIpPoolEndAddress", endAddress),
resource.TestCheckOutput("orgNetwork", params["orgNetwork"].(string)),
testCheckVappNetworkNonStringOutputs(guestVlanAllowed, fwEnabled, natEnabled, retainIpMacEnabled),
testCheckVappNetworkNonStringOutputs(guestVlanAllowed, retainIpMacEnabled),
),
},
},
})
}

func testCheckVappNetworkNonStringOutputs(guestVlanAllowed, firewallEnabled, natEnabled, retainIpMacEnabled bool) resource.TestCheckFunc {
func testCheckVappNetworkNonStringOutputs(guestVlanAllowed, retainIpMacEnabled bool) resource.TestCheckFunc {
return func(s *terraform.State) error {
outputs := s.RootModule().Outputs

Expand All @@ -101,13 +97,6 @@ func testCheckVappNetworkNonStringOutputs(guestVlanAllowed, firewallEnabled, nat
return fmt.Errorf("retain_ip_mac_enabled value didn't match")
}

if outputs["firewall_enabled"].Value != firewallEnabled {
return fmt.Errorf("retain_ip_mac_enabled value didn't match")
}

if outputs["nat_enabled"].Value != natEnabled {
return fmt.Errorf("retain_ip_mac_enabled value didn't match")
}
return nil
}
}
Expand Down Expand Up @@ -159,8 +148,6 @@ resource "vcd_vapp_network" "createdVappNetwork" {
}

org_network_name = vcd_network_routed.{{.orgNetwork}}.name
firewall_enabled = "{{.firewallEnabled}}"
nat_enabled = "{{.natEnabled}}"
retain_ip_mac_enabled = "{{.retainIpMacEnabled}}"
}

Expand Down Expand Up @@ -208,11 +195,5 @@ output "orgNetwork" {
}
output "retain_ip_mac_enabled" {
value = data.vcd_vapp_network.network-ds.retain_ip_mac_enabled
}
output "firewall_enabled" {
value = data.vcd_vapp_network.network-ds.firewall_enabled
}
output "nat_enabled" {
value = data.vcd_vapp_network.network-ds.nat_enabled
}
}
`
10 changes: 0 additions & 10 deletions vcd/datasource_vcd_vapp_org_network.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,6 @@ func datasourceVcdVappOrgNetwork() *schema.Resource {
Computed: true,
Description: "Specifies whether the network resources such as IP/MAC of router will be retained across deployments.",
},
"firewall_enabled": {
Type: schema.TypeBool,
Computed: true,
Description: "firewall service enabled or disabled. Default is true",
},
"nat_enabled": {
Type: schema.TypeBool,
Computed: true,
Description: "NAT service enabled or disabled. Default is true",
},
},
}
}
Expand Down
25 changes: 3 additions & 22 deletions vcd/datasource_vcd_vapp_org_network_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ import (

// TestAccVcdVappOrgNetworkDS tests a vApp org network data source if a vApp is found in the VDC
func TestAccVcdVappOrgNetworkDS(t *testing.T) {
var fwEnabled = false
var natEnabled = false
var retainIpMacEnabled = true

var params = StringMap{
Expand All @@ -23,8 +21,6 @@ func TestAccVcdVappOrgNetworkDS(t *testing.T) {
"vappName": "TestAccVcdVappOrgNetworkDS",
"orgNetwork": "TestAccVcdVappOrgNetworkDSOrgNetwork",
"EdgeGateway": testConfig.Networking.EdgeGateway,
"firewallEnabled": fwEnabled,
"natEnabled": natEnabled,
"retainIpMacEnabled": retainIpMacEnabled,
"isFenced": "true",

Expand All @@ -45,28 +41,21 @@ func TestAccVcdVappOrgNetworkDS(t *testing.T) {
resource.TestStep{
Config: configText,
Check: resource.ComposeTestCheckFunc(
testCheckVappOrgNetworkNonStringOutputs(fwEnabled, natEnabled, retainIpMacEnabled),
testCheckVappOrgNetworkNonStringOutputs(retainIpMacEnabled),
),
},
},
})
}

func testCheckVappOrgNetworkNonStringOutputs(firewallEnabled, natEnabled, retainIpMacEnabled bool) resource.TestCheckFunc {
func testCheckVappOrgNetworkNonStringOutputs(retainIpMacEnabled bool) resource.TestCheckFunc {
return func(s *terraform.State) error {
outputs := s.RootModule().Outputs

if outputs["retain_ip_mac_enabled"].Value != retainIpMacEnabled {
return fmt.Errorf("retain_ip_mac_enabled value didn't match")
}

if outputs["firewall_enabled"].Value != firewallEnabled {
return fmt.Errorf("retain_ip_mac_enabled value didn't match")
}

if outputs["nat_enabled"].Value != natEnabled {
return fmt.Errorf("retain_ip_mac_enabled value didn't match")
}
return nil
}
}
Expand Down Expand Up @@ -99,8 +88,6 @@ resource "vcd_vapp_org_network" "createVappOrgNetwork" {

is_fenced = "{{.isFenced}}"

firewall_enabled = "{{.firewallEnabled}}"
nat_enabled = "{{.natEnabled}}"
retain_ip_mac_enabled = "{{.retainIpMacEnabled}}"
}

Expand All @@ -111,11 +98,5 @@ data "vcd_vapp_org_network" "network-ds" {

output "retain_ip_mac_enabled" {
value = data.vcd_vapp_org_network.network-ds.retain_ip_mac_enabled
}
output "firewall_enabled" {
value = data.vcd_vapp_org_network.network-ds.firewall_enabled
}
output "nat_enabled" {
value = data.vcd_vapp_org_network.network-ds.nat_enabled
}
}
`
75 changes: 38 additions & 37 deletions vcd/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,43 +56,44 @@ var globalDataSourceMap = map[string]*schema.Resource{

var globalResourceMap = map[string]*schema.Resource{

"vcd_network": resourceVcdNetwork(), // 1.0 DEPRECATED: replaced by vcd_network_routed
"vcd_network_routed": resourceVcdNetworkRouted(), // 2.0
"vcd_network_direct": resourceVcdNetworkDirect(), // 2.0
"vcd_network_isolated": resourceVcdNetworkIsolated(), // 2.0
"vcd_vapp_network": resourceVcdVappNetwork(), // 2.1
"vcd_vapp": resourceVcdVApp(), // 1.0
"vcd_firewall_rules": resourceVcdFirewallRules(), // 1.0 DEPRECATED: Use only for non-advanced edge gateway. Replaced by vcd_nsxv_firewall_rule
"vcd_dnat": resourceVcdDNAT(), // 1.0 DEPRECATED: Use only for non-advanced edge gateway. Replaced by vcd_nsxv_dnat
"vcd_snat": resourceVcdSNAT(), // 1.0 DEPRECATED: Use only for non-advanced edge gateway. Replaced by vcd_nsxv_snat
"vcd_edgegateway": resourceVcdEdgeGateway(), // 2.4
"vcd_edgegateway_vpn": resourceVcdEdgeGatewayVpn(), // 1.0
"vcd_vapp_vm": resourceVcdVAppVm(), // 1.0
"vcd_org": resourceOrg(), // 2.0
"vcd_org_vdc": resourceVcdOrgVdc(), // 2.2
"vcd_org_user": resourceVcdOrgUser(), // 2.4
"vcd_catalog": resourceVcdCatalog(), // 2.0
"vcd_catalog_item": resourceVcdCatalogItem(), // 2.0
"vcd_catalog_media": resourceVcdCatalogMedia(), // 2.0
"vcd_inserted_media": resourceVcdInsertedMedia(), // 2.1
"vcd_independent_disk": resourceVcdIndependentDisk(), // 2.1
"vcd_external_network": resourceVcdExternalNetwork(), // 2.2
"vcd_lb_service_monitor": resourceVcdLbServiceMonitor(), // 2.4
"vcd_lb_server_pool": resourceVcdLBServerPool(), // 2.4
"vcd_lb_app_profile": resourceVcdLBAppProfile(), // 2.4
"vcd_lb_app_rule": resourceVcdLBAppRule(), // 2.4
"vcd_lb_virtual_server": resourceVcdLBVirtualServer(), // 2.4
"vcd_nsxv_dnat": resourceVcdNsxvDnat(), // 2.5
"vcd_nsxv_snat": resourceVcdNsxvSnat(), // 2.5
"vcd_nsxv_firewall_rule": resourceVcdNsxvFirewallRule(), // 2.5
"vcd_nsxv_dhcp_relay": resourceVcdNsxvDhcpRelay(), // 2.6
"vcd_nsxv_ip_set": resourceVcdIpSet(), // 2.6
"vcd_vm_internal_disk": resourceVmInternalDisk(), // 2.7
"vcd_vapp_org_network": resourceVcdVappOrgNetwork(), // 2.7
"vcd_org_group": resourceVcdOrgGroup(), // 2.9
"vcd_vapp_firewall_rules": resourceVcdVappFirewallRules(), // 2.9
"vcd_vapp_nat_rules": resourceVcdVappNetworkNatRules(), // 2.9
"vcd_vm_affinity_rule": resourceVcdVmAffinityRule(), // 2.9
"vcd_network": resourceVcdNetwork(), // 1.0 DEPRECATED: replaced by vcd_network_routed
"vcd_network_routed": resourceVcdNetworkRouted(), // 2.0
"vcd_network_direct": resourceVcdNetworkDirect(), // 2.0
"vcd_network_isolated": resourceVcdNetworkIsolated(), // 2.0
"vcd_vapp_network": resourceVcdVappNetwork(), // 2.1
"vcd_vapp": resourceVcdVApp(), // 1.0
"vcd_firewall_rules": resourceVcdFirewallRules(), // 1.0 DEPRECATED: Use only for non-advanced edge gateway. Replaced by vcd_nsxv_firewall_rule
"vcd_dnat": resourceVcdDNAT(), // 1.0 DEPRECATED: Use only for non-advanced edge gateway. Replaced by vcd_nsxv_dnat
"vcd_snat": resourceVcdSNAT(), // 1.0 DEPRECATED: Use only for non-advanced edge gateway. Replaced by vcd_nsxv_snat
"vcd_edgegateway": resourceVcdEdgeGateway(), // 2.4
"vcd_edgegateway_vpn": resourceVcdEdgeGatewayVpn(), // 1.0
"vcd_vapp_vm": resourceVcdVAppVm(), // 1.0
"vcd_org": resourceOrg(), // 2.0
"vcd_org_vdc": resourceVcdOrgVdc(), // 2.2
"vcd_org_user": resourceVcdOrgUser(), // 2.4
"vcd_catalog": resourceVcdCatalog(), // 2.0
"vcd_catalog_item": resourceVcdCatalogItem(), // 2.0
"vcd_catalog_media": resourceVcdCatalogMedia(), // 2.0
"vcd_inserted_media": resourceVcdInsertedMedia(), // 2.1
"vcd_independent_disk": resourceVcdIndependentDisk(), // 2.1
"vcd_external_network": resourceVcdExternalNetwork(), // 2.2
"vcd_lb_service_monitor": resourceVcdLbServiceMonitor(), // 2.4
"vcd_lb_server_pool": resourceVcdLBServerPool(), // 2.4
"vcd_lb_app_profile": resourceVcdLBAppProfile(), // 2.4
"vcd_lb_app_rule": resourceVcdLBAppRule(), // 2.4
"vcd_lb_virtual_server": resourceVcdLBVirtualServer(), // 2.4
"vcd_nsxv_dnat": resourceVcdNsxvDnat(), // 2.5
"vcd_nsxv_snat": resourceVcdNsxvSnat(), // 2.5
"vcd_nsxv_firewall_rule": resourceVcdNsxvFirewallRule(), // 2.5
"vcd_nsxv_dhcp_relay": resourceVcdNsxvDhcpRelay(), // 2.6
"vcd_nsxv_ip_set": resourceVcdIpSet(), // 2.6
"vcd_vm_internal_disk": resourceVmInternalDisk(), // 2.7
"vcd_vapp_org_network": resourceVcdVappOrgNetwork(), // 2.7
"vcd_org_group": resourceVcdOrgGroup(), // 2.9
"vcd_vapp_firewall_rules": resourceVcdVappFirewallRules(), // 2.9
"vcd_vapp_nat_rules": resourceVcdVappNetworkNatRules(), // 2.9
"vcd_vapp_static_routing": resourceVcdVappNetworkStaticRouting(), // 2.9
"vcd_vm_affinity_rule": resourceVcdVmAffinityRule(), // 2.9
}

// Provider returns a terraform.ResourceProvider.
Expand Down
9 changes: 8 additions & 1 deletion vcd/resource_vcd_vapp_firewall_rules.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@ func resourceVcdVappFirewallRules() *schema.Resource {
ForceNew: true,
Description: "vApp network identifier",
},
"enabled": &schema.Schema{
Type: schema.TypeBool,
Optional: true,
Default: true,
Description: "Enable or disable firewall service.",
lvirbalas marked this conversation as resolved.
Show resolved Hide resolved
},
"default_action": &schema.Schema{
Type: schema.TypeString,
Required: true,
Expand Down Expand Up @@ -174,7 +180,7 @@ func resourceVcdVappFirewallRulesUpdate(d *schema.ResourceData, meta interface{}
return fmt.Errorf("error expanding firewall rules: %s", err)
}

vappNetwork, err := vapp.UpdateNetworkFirewallRules(networkId, firewallRules,
vappNetwork, err := vapp.UpdateNetworkFirewallRules(networkId, firewallRules, d.Get("enabled").(bool),
d.Get("default_action").(string), d.Get("log_default_action").(bool))
if err != nil {
log.Printf("[INFO] Error setting firewall rules: %s", err)
Expand Down Expand Up @@ -260,6 +266,7 @@ func resourceVappFirewallRulesRead(d *schema.ResourceData, meta interface{}) err
if err != nil {
return err
}
_ = d.Set("enabled", vappNetwork.Configuration.Features.FirewallService.IsEnabled)
_ = d.Set("default_action", vappNetwork.Configuration.Features.FirewallService.DefaultAction)
_ = d.Set("log_default_action", vappNetwork.Configuration.Features.FirewallService.LogDefaultAction)

Expand Down
Loading