@@ -2,15 +2,19 @@ package cloudstack
22
33import (
44 "fmt"
5+ "strconv"
56 "strings"
67 "testing"
78
89 "github.com/hashicorp/terraform/helper/resource"
10+ "github.com/hashicorp/terraform/helper/schema"
911 "github.com/hashicorp/terraform/terraform"
1012 "github.com/xanzy/go-cloudstack/cloudstack"
1113)
1214
1315func TestAccCloudStackEgressFirewall_basic (t * testing.T ) {
16+ hash := makeTestCloudStackEgressFirewallRuleHash ([]interface {}{"1000-2000" , "80" })
17+
1418 resource .Test (t , resource.TestCase {
1519 PreCheck : func () { testAccPreCheck (t ) },
1620 Providers : testAccProviders ,
@@ -24,23 +28,26 @@ func TestAccCloudStackEgressFirewall_basic(t *testing.T) {
2428 "cloudstack_egress_firewall.foo" , "network" , CLOUDSTACK_NETWORK_1 ),
2529 resource .TestCheckResourceAttr (
2630 "cloudstack_egress_firewall.foo" ,
27- "rule.411689741 .source_cidr" ,
31+ "rule." + hash + " .source_cidr" ,
2832 CLOUDSTACK_NETWORK_1_IPADDRESS + "/32" ),
2933 resource .TestCheckResourceAttr (
30- "cloudstack_egress_firewall.foo" , "rule.411689741 .protocol" , "tcp" ),
34+ "cloudstack_egress_firewall.foo" , "rule." + hash + " .protocol" , "tcp" ),
3135 resource .TestCheckResourceAttr (
32- "cloudstack_egress_firewall.foo" , "rule.411689741 .ports.#" , "2" ),
36+ "cloudstack_egress_firewall.foo" , "rule." + hash + " .ports.#" , "2" ),
3337 resource .TestCheckResourceAttr (
34- "cloudstack_egress_firewall.foo" , "rule.411689741 .ports.1209010669" , "1000-2000" ),
38+ "cloudstack_egress_firewall.foo" , "rule." + hash + " .ports.1209010669" , "1000-2000" ),
3539 resource .TestCheckResourceAttr (
36- "cloudstack_egress_firewall.foo" , "rule.411689741 .ports.1889509032" , "80" ),
40+ "cloudstack_egress_firewall.foo" , "rule." + hash + " .ports.1889509032" , "80" ),
3741 ),
3842 },
3943 },
4044 })
4145}
4246
4347func TestAccCloudStackEgressFirewall_update (t * testing.T ) {
48+ hash1 := makeTestCloudStackEgressFirewallRuleHash ([]interface {}{"1000-2000" , "80" })
49+ hash2 := makeTestCloudStackEgressFirewallRuleHash ([]interface {}{"443" })
50+
4451 resource .Test (t , resource.TestCase {
4552 PreCheck : func () { testAccPreCheck (t ) },
4653 Providers : testAccProviders ,
@@ -56,16 +63,16 @@ func TestAccCloudStackEgressFirewall_update(t *testing.T) {
5663 "cloudstack_egress_firewall.foo" , "rule.#" , "1" ),
5764 resource .TestCheckResourceAttr (
5865 "cloudstack_egress_firewall.foo" ,
59- "rule.411689741 .source_cidr" ,
66+ "rule." + hash1 + " .source_cidr" ,
6067 CLOUDSTACK_NETWORK_1_IPADDRESS + "/32" ),
6168 resource .TestCheckResourceAttr (
62- "cloudstack_egress_firewall.foo" , "rule.411689741 .protocol" , "tcp" ),
69+ "cloudstack_egress_firewall.foo" , "rule." + hash1 + " .protocol" , "tcp" ),
6370 resource .TestCheckResourceAttr (
64- "cloudstack_egress_firewall.foo" , "rule.411689741 .ports.#" , "2" ),
71+ "cloudstack_egress_firewall.foo" , "rule." + hash1 + " .ports.#" , "2" ),
6572 resource .TestCheckResourceAttr (
66- "cloudstack_egress_firewall.foo" , "rule.411689741 .ports.1209010669" , "1000-2000" ),
73+ "cloudstack_egress_firewall.foo" , "rule." + hash1 + " .ports.1209010669" , "1000-2000" ),
6774 resource .TestCheckResourceAttr (
68- "cloudstack_egress_firewall.foo" , "rule.411689741 .ports.1889509032" , "80" ),
75+ "cloudstack_egress_firewall.foo" , "rule." + hash1 + " .ports.1889509032" , "80" ),
6976 ),
7077 },
7178
@@ -79,26 +86,26 @@ func TestAccCloudStackEgressFirewall_update(t *testing.T) {
7986 "cloudstack_egress_firewall.foo" , "rule.#" , "2" ),
8087 resource .TestCheckResourceAttr (
8188 "cloudstack_egress_firewall.foo" ,
82- "rule.411689741 .source_cidr" ,
89+ "rule." + hash1 + " .source_cidr" ,
8390 CLOUDSTACK_NETWORK_1_IPADDRESS + "/32" ),
8491 resource .TestCheckResourceAttr (
85- "cloudstack_egress_firewall.foo" , "rule.411689741 .protocol" , "tcp" ),
92+ "cloudstack_egress_firewall.foo" , "rule." + hash1 + " .protocol" , "tcp" ),
8693 resource .TestCheckResourceAttr (
87- "cloudstack_egress_firewall.foo" , "rule.411689741 .ports.#" , "2" ),
94+ "cloudstack_egress_firewall.foo" , "rule." + hash1 + " .ports.#" , "2" ),
8895 resource .TestCheckResourceAttr (
89- "cloudstack_egress_firewall.foo" , "rule.411689741 .ports.1209010669" , "1000-2000" ),
96+ "cloudstack_egress_firewall.foo" , "rule." + hash1 + " .ports.1209010669" , "1000-2000" ),
9097 resource .TestCheckResourceAttr (
91- "cloudstack_egress_firewall.foo" , "rule.411689741 .ports.1889509032" , "80" ),
98+ "cloudstack_egress_firewall.foo" , "rule." + hash1 + " .ports.1889509032" , "80" ),
9299 resource .TestCheckResourceAttr (
93100 "cloudstack_egress_firewall.foo" ,
94- "rule.845479598 .source_cidr" ,
101+ "rule." + hash2 + " .source_cidr" ,
95102 CLOUDSTACK_NETWORK_1_IPADDRESS + "/32" ),
96103 resource .TestCheckResourceAttr (
97- "cloudstack_egress_firewall.foo" , "rule.845479598 .protocol" , "tcp" ),
104+ "cloudstack_egress_firewall.foo" , "rule." + hash2 + " .protocol" , "tcp" ),
98105 resource .TestCheckResourceAttr (
99- "cloudstack_egress_firewall.foo" , "rule.845479598 .ports.#" , "1" ),
106+ "cloudstack_egress_firewall.foo" , "rule." + hash2 + " .ports.#" , "1" ),
100107 resource .TestCheckResourceAttr (
101- "cloudstack_egress_firewall.foo" , "rule.845479598 .ports.3638101695" , "443" ),
108+ "cloudstack_egress_firewall.foo" , "rule." + hash2 + " .ports.3638101695" , "443" ),
102109 ),
103110 },
104111 },
@@ -164,6 +171,16 @@ func testAccCheckCloudStackEgressFirewallDestroy(s *terraform.State) error {
164171 return nil
165172}
166173
174+ func makeTestCloudStackEgressFirewallRuleHash (ports []interface {}) string {
175+ return strconv .Itoa (resourceCloudStackEgressFirewallRuleHash (map [string ]interface {}{
176+ "source_cidr" : CLOUDSTACK_NETWORK_1_IPADDRESS + "/32" ,
177+ "protocol" : "tcp" ,
178+ "ports" : schema .NewSet (schema .HashString , ports ),
179+ "icmp_type" : 0 ,
180+ "icmp_code" : 0 ,
181+ }))
182+ }
183+
167184var testAccCloudStackEgressFirewall_basic = fmt .Sprintf (`
168185resource "cloudstack_egress_firewall" "foo" {
169186 network = "%s"
0 commit comments