diff --git a/cloudstack/resource_cloudstack_private_gateway.go b/cloudstack/resource_cloudstack_private_gateway.go index 6d4e0078..db4aa186 100644 --- a/cloudstack/resource_cloudstack_private_gateway.go +++ b/cloudstack/resource_cloudstack_private_gateway.go @@ -85,6 +85,12 @@ func resourceCloudStackPrivateGateway() *schema.Resource { Required: true, ForceNew: true, }, + + "bypass_vlan_overlap_check": { + Type: schema.TypeBool, + Optional: true, + Default: false, + }, }, } } @@ -119,6 +125,11 @@ func resourceCloudStackPrivateGatewayCreate(d *schema.ResourceData, meta interfa p.SetAclid(aclid.(string)) } + // Set bypass_vlan_overlap_check if specified + if bypassVlanOverlapCheck, ok := d.GetOk("bypass_vlan_overlap_check"); ok { + p.SetBypassvlanoverlapcheck(bypassVlanOverlapCheck.(bool)) + } + // Create the new private gateway r, err := cs.VPC.CreatePrivateGateway(p) if err != nil { diff --git a/cloudstack/resource_cloudstack_private_gateway_test.go b/cloudstack/resource_cloudstack_private_gateway_test.go index a20a8141..058cce90 100644 --- a/cloudstack/resource_cloudstack_private_gateway_test.go +++ b/cloudstack/resource_cloudstack_private_gateway_test.go @@ -59,9 +59,52 @@ func TestAccCloudStackPrivateGateway_import(t *testing.T) { }, { - ResourceName: "cloudstack_private_gateway.foo", - ImportState: true, - ImportStateVerify: true, + ResourceName: "cloudstack_private_gateway.foo", + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"bypass_vlan_overlap_check"}, + }, + }, + }) +} + +func TestAccCloudStackPrivateGateway_bypassVlanOverlapCheck(t *testing.T) { + var gateway cloudstack.PrivateGateway + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckCloudStackPrivateGatewayDestroy, + Steps: []resource.TestStep{ + { + Config: testAccCloudStackPrivateGateway_bypassVlanOverlapCheck, + Check: resource.ComposeTestCheckFunc( + testAccCheckCloudStackPrivateGatewayExists( + "cloudstack_private_gateway.bar", &gateway), + resource.TestCheckResourceAttr( + "cloudstack_private_gateway.bar", "bypass_vlan_overlap_check", "true"), + ), + }, + }, + }) +} + +func TestAccCloudStackPrivateGateway_bypassVlanOverlapCheckDefault(t *testing.T) { + var gateway cloudstack.PrivateGateway + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckCloudStackPrivateGatewayDestroy, + Steps: []resource.TestStep{ + { + Config: testAccCloudStackPrivateGateway_basic, + Check: resource.ComposeTestCheckFunc( + testAccCheckCloudStackPrivateGatewayExists( + "cloudstack_private_gateway.foo", &gateway), + resource.TestCheckResourceAttr( + "cloudstack_private_gateway.foo", "bypass_vlan_overlap_check", "false"), + ), }, }, }) @@ -160,3 +203,28 @@ resource "cloudstack_private_gateway" "foo" { acl_id = cloudstack_network_acl.foo.id depends_on = ["cloudstack_vpc.foo","cloudstack_network_acl.foo"] }` + +const testAccCloudStackPrivateGateway_bypassVlanOverlapCheck = ` +resource "cloudstack_vpc" "bar" { + name = "terraform-vpc-bypass" + cidr = "10.0.0.0/8" + vpc_offering = "Default VPC offering" + zone = "Sandbox-simulator" +} + +resource "cloudstack_network_acl" "bar" { + name = "terraform-acl-bypass" + vpc_id = cloudstack_vpc.bar.id + depends_on = ["cloudstack_vpc.bar"] +} + +resource "cloudstack_private_gateway" "bar" { + gateway = "10.1.1.254" + ip_address = "192.168.0.2" + netmask = "255.255.255.0" + vlan = "2" + vpc_id = cloudstack_vpc.bar.id + acl_id = cloudstack_network_acl.bar.id + bypass_vlan_overlap_check = true + depends_on = ["cloudstack_vpc.bar","cloudstack_network_acl.bar"] +}` diff --git a/website/docs/r/private_gateway.html.markdown b/website/docs/r/private_gateway.html.markdown index b5a32435..77db0990 100644 --- a/website/docs/r/private_gateway.html.markdown +++ b/website/docs/r/private_gateway.html.markdown @@ -25,6 +25,20 @@ resource "cloudstack_private_gateway" "default" { } ``` +Example with VLAN overlap check bypass: + +```hcl +resource "cloudstack_private_gateway" "with_bypass" { + gateway = "10.0.0.1" + ip_address = "10.0.0.2" + netmask = "255.255.255.252" + vlan = "200" + vpc_id = "76f6e8dc-07e3-4971-b2a2-8831b0cc4cb4" + acl_id = "cf4f1dad-aade-4ccd-866c-0a2166e5be3d" + bypass_vlan_overlap_check = true +} +``` + ## Argument Reference The following arguments are supported: @@ -51,6 +65,11 @@ The following arguments are supported: * `vpc_id` - (Required) The VPC ID in which to create this Private gateway. Changing this forces a new resource to be created. +* `bypass_vlan_overlap_check` - (Optional) When set to true, bypasses the VLAN overlap + check during private gateway creation. This allows creating private gateways with + VLANs that may overlap with existing VLANs in the physical network. Defaults to + false. + ## Attributes Reference The following attributes are exported: