@@ -40,27 +40,29 @@ func TestAccCloudStackSecurityGroupRule_basic(t *testing.T) {
4040 Check : resource .ComposeTestCheckFunc (
4141 testAccCheckCloudStackSecurityGroupRulesExist ("cloudstack_security_group.foo" ),
4242 resource .TestCheckResourceAttr (
43- "cloudstack_security_group_rule.foo" , "rule.#" , "2" ),
44- resource .TestCheckResourceAttr (
45- "cloudstack_security_group_rule.foo" , "rule.0.cidr_list.0" , "172.18.100.0/24" ),
46- resource .TestCheckResourceAttr (
47- "cloudstack_security_group_rule.foo" , "rule.0.protocol" , "tcp" ),
48- resource .TestCheckResourceAttr (
49- "cloudstack_security_group_rule.foo" , "rule.0.ports.#" , "1" ),
50- resource .TestCheckResourceAttr (
51- "cloudstack_security_group_rule.foo" , "rule.0.ports.0" , "80" ),
52- resource .TestCheckResourceAttr (
53- "cloudstack_security_group_rule.foo" , "rule.0.traffic_type" , "ingress" ),
54- resource .TestCheckResourceAttr (
55- "cloudstack_security_group_rule.foo" , "rule.1.protocol" , "tcp" ),
56- resource .TestCheckResourceAttr (
57- "cloudstack_security_group_rule.foo" , "rule.1.ports.1" , "80" ),
58- resource .TestCheckResourceAttr (
59- "cloudstack_security_group_rule.foo" , "rule.1.ports.0" , "443" ),
60- resource .TestCheckResourceAttr (
61- "cloudstack_security_group_rule.foo" , "rule.1.traffic_type" , "egress" ),
62- resource .TestCheckResourceAttr (
63- "cloudstack_security_group_rule.foo" , "rule.1.user_security_group_list.0" , "terraform-security-group-bar" ),
43+ "cloudstack_security_group_rule.foo" , "rule.#" , "3" ),
44+ resource .TestCheckTypeSetElemNestedAttrs (
45+ "cloudstack_security_group_rule.foo" , "rule.*" , map [string ]string {
46+ "protocol" : "all" ,
47+ "traffic_type" : "egress" ,
48+ "cidr_list.#" : "1" ,
49+ "cidr_list.0" : "172.0.0.0/8" ,
50+ }),
51+ resource .TestCheckTypeSetElemNestedAttrs (
52+ "cloudstack_security_group_rule.foo" , "rule.*" , map [string ]string {
53+ "protocol" : "tcp" ,
54+ "traffic_type" : "ingress" ,
55+ "cidr_list.0" : "172.18.100.0/24" ,
56+ "ports.#" : "1" ,
57+ "ports.0" : "80" ,
58+ }),
59+ resource .TestCheckTypeSetElemNestedAttrs (
60+ "cloudstack_security_group_rule.foo" , "rule.*" , map [string ]string {
61+ "protocol" : "tcp" ,
62+ "traffic_type" : "egress" ,
63+ "ports.#" : "2" ,
64+ "user_security_group_list.0" : "terraform-security-group-bar" ,
65+ }),
6466 ),
6567 },
6668 },
@@ -78,27 +80,29 @@ func TestAccCloudStackSecurityGroupRule_update(t *testing.T) {
7880 Check : resource .ComposeTestCheckFunc (
7981 testAccCheckCloudStackSecurityGroupRulesExist ("cloudstack_security_group.foo" ),
8082 resource .TestCheckResourceAttr (
81- "cloudstack_security_group_rule.foo" , "rule.#" , "2" ),
82- resource .TestCheckResourceAttr (
83- "cloudstack_security_group_rule.foo" , "rule.0.cidr_list.0" , "172.18.100.0/24" ),
84- resource .TestCheckResourceAttr (
85- "cloudstack_security_group_rule.foo" , "rule.0.protocol" , "tcp" ),
86- resource .TestCheckResourceAttr (
87- "cloudstack_security_group_rule.foo" , "rule.0.ports.#" , "1" ),
88- resource .TestCheckResourceAttr (
89- "cloudstack_security_group_rule.foo" , "rule.0.ports.0" , "80" ),
90- resource .TestCheckResourceAttr (
91- "cloudstack_security_group_rule.foo" , "rule.0.traffic_type" , "ingress" ),
92- resource .TestCheckResourceAttr (
93- "cloudstack_security_group_rule.foo" , "rule.1.protocol" , "tcp" ),
94- resource .TestCheckResourceAttr (
95- "cloudstack_security_group_rule.foo" , "rule.1.ports.1" , "80" ),
96- resource .TestCheckResourceAttr (
97- "cloudstack_security_group_rule.foo" , "rule.1.ports.0" , "443" ),
98- resource .TestCheckResourceAttr (
99- "cloudstack_security_group_rule.foo" , "rule.1.traffic_type" , "egress" ),
100- resource .TestCheckResourceAttr (
101- "cloudstack_security_group_rule.foo" , "rule.1.user_security_group_list.0" , "terraform-security-group-bar" ),
83+ "cloudstack_security_group_rule.foo" , "rule.#" , "3" ),
84+ resource .TestCheckTypeSetElemNestedAttrs (
85+ "cloudstack_security_group_rule.foo" , "rule.*" , map [string ]string {
86+ "protocol" : "all" ,
87+ "traffic_type" : "egress" ,
88+ "cidr_list.#" : "1" ,
89+ "cidr_list.0" : "172.0.0.0/8" ,
90+ }),
91+ resource .TestCheckTypeSetElemNestedAttrs (
92+ "cloudstack_security_group_rule.foo" , "rule.*" , map [string ]string {
93+ "protocol" : "tcp" ,
94+ "traffic_type" : "ingress" ,
95+ "cidr_list.0" : "172.18.100.0/24" ,
96+ "ports.#" : "1" ,
97+ "ports.0" : "80" ,
98+ }),
99+ resource .TestCheckTypeSetElemNestedAttrs (
100+ "cloudstack_security_group_rule.foo" , "rule.*" , map [string ]string {
101+ "protocol" : "tcp" ,
102+ "traffic_type" : "egress" ,
103+ "ports.#" : "2" ,
104+ "user_security_group_list.0" : "terraform-security-group-bar" ,
105+ }),
102106 ),
103107 },
104108
@@ -107,35 +111,36 @@ func TestAccCloudStackSecurityGroupRule_update(t *testing.T) {
107111 Check : resource .ComposeTestCheckFunc (
108112 testAccCheckCloudStackSecurityGroupRulesExist ("cloudstack_security_group.foo" ),
109113 resource .TestCheckResourceAttr (
110- "cloudstack_security_group_rule.foo" , "rule.#" , "3" ),
111- resource .TestCheckResourceAttr (
112- "cloudstack_security_group_rule.foo" , "rule.0.cidr_list.0" , "172.18.100.0/24" ),
113- resource .TestCheckResourceAttr (
114- "cloudstack_security_group_rule.foo" , "rule.0.cidr_list.1" , "172.18.200.0/24" ),
115- resource .TestCheckResourceAttr (
116- "cloudstack_security_group_rule.foo" , "rule.0.protocol" , "tcp" ),
117- resource .TestCheckResourceAttr (
118- "cloudstack_security_group_rule.foo" , "rule.0.ports.1" , "80" ),
119- resource .TestCheckResourceAttr (
120- "cloudstack_security_group_rule.foo" , "rule.0.ports.0" , "443" ),
121- resource .TestCheckResourceAttr (
122- "cloudstack_security_group_rule.foo" , "rule.1.cidr_list.#" , "1" ),
123- resource .TestCheckResourceAttr (
124- "cloudstack_security_group_rule.foo" , "rule.1.cidr_list.0" , "172.18.100.0/24" ),
125- resource .TestCheckResourceAttr (
126- "cloudstack_security_group_rule.foo" , "rule.1.icmp_code" , "-1" ),
127- resource .TestCheckResourceAttr (
128- "cloudstack_security_group_rule.foo" , "rule.1.icmp_type" , "-1" ),
129- resource .TestCheckResourceAttr (
130- "cloudstack_security_group_rule.foo" , "rule.2.protocol" , "tcp" ),
131- resource .TestCheckResourceAttr (
132- "cloudstack_security_group_rule.foo" , "rule.2.ports.#" , "1" ),
133- resource .TestCheckResourceAttr (
134- "cloudstack_security_group_rule.foo" , "rule.2.ports.0" , "80" ),
135- resource .TestCheckResourceAttr (
136- "cloudstack_security_group_rule.foo" , "rule.2.traffic_type" , "egress" ),
137- resource .TestCheckResourceAttr (
138- "cloudstack_security_group_rule.foo" , "rule.2.user_security_group_list.0" , "terraform-security-group-bar" ),
114+ "cloudstack_security_group_rule.foo" , "rule.#" , "4" ),
115+ resource .TestCheckTypeSetElemNestedAttrs (
116+ "cloudstack_security_group_rule.foo" , "rule.*" , map [string ]string {
117+ "protocol" : "tcp" ,
118+ "cidr_list.#" : "2" ,
119+ "ports.#" : "2" ,
120+ }),
121+ resource .TestCheckTypeSetElemNestedAttrs (
122+ "cloudstack_security_group_rule.foo" , "rule.*" , map [string ]string {
123+ "protocol" : "icmp" ,
124+ "traffic_type" : "ingress" ,
125+ "cidr_list.#" : "1" ,
126+ "cidr_list.0" : "172.18.100.0/24" ,
127+ "icmp_code" : "-1" ,
128+ "icmp_type" : "-1" ,
129+ }),
130+ resource .TestCheckTypeSetElemNestedAttrs (
131+ "cloudstack_security_group_rule.foo" , "rule.*" , map [string ]string {
132+ "protocol" : "all" ,
133+ "traffic_type" : "ingress" ,
134+ "cidr_list.#" : "2" ,
135+ }),
136+ resource .TestCheckTypeSetElemNestedAttrs (
137+ "cloudstack_security_group_rule.foo" , "rule.*" , map [string ]string {
138+ "protocol" : "tcp" ,
139+ "traffic_type" : "egress" ,
140+ "ports.#" : "1" ,
141+ "ports.0" : "80" ,
142+ "user_security_group_list.0" : "terraform-security-group-bar" ,
143+ }),
139144 ),
140145 },
141146 },
@@ -238,6 +243,12 @@ resource "cloudstack_security_group" "bar" {
238243resource "cloudstack_security_group_rule" "foo" {
239244 security_group_id = cloudstack_security_group.foo.id
240245
246+ rule {
247+ protocol = "all"
248+ cidr_list = ["172.0.0.0/8"]
249+ traffic_type = "egress"
250+ }
251+
241252 rule {
242253 cidr_list = ["172.18.100.0/24"]
243254 protocol = "tcp"
@@ -268,6 +279,12 @@ resource "cloudstack_security_group" "bar" {
268279resource "cloudstack_security_group_rule" "foo" {
269280 security_group_id = cloudstack_security_group.foo.id
270281
282+ rule {
283+ protocol = "all"
284+ cidr_list = ["172.20.100.0/24", "192.168.0.0/32"]
285+ traffic_type = "ingress"
286+ }
287+
271288 rule {
272289 cidr_list = ["172.18.100.0/24", "172.18.200.0/24"]
273290 protocol = "tcp"
0 commit comments