Skip to content

Commit 5e6af8e

Browse files
author
Sander van Harmelen
committed
Merge pull request hashicorp#6010 from svanharmelen/f-deprecate-ipaddress
provider/cloudstack: make the CloudStack provider more inline with the other providers
2 parents 0f25016 + fddf3ec commit 5e6af8e

22 files changed

Lines changed: 231 additions & 151 deletions

builtin/providers/cloudstack/resource_cloudstack_firewall.go

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package cloudstack
22

33
import (
4+
"errors"
45
"fmt"
56
"strconv"
67
"strings"
@@ -20,10 +21,19 @@ func resourceCloudStackFirewall() *schema.Resource {
2021
Delete: resourceCloudStackFirewallDelete,
2122

2223
Schema: map[string]*schema.Schema{
24+
"ip_address": &schema.Schema{
25+
Type: schema.TypeString,
26+
Optional: true,
27+
ForceNew: true,
28+
ConflictsWith: []string{"ipaddress"},
29+
},
30+
2331
"ipaddress": &schema.Schema{
24-
Type: schema.TypeString,
25-
Required: true,
26-
ForceNew: true,
32+
Type: schema.TypeString,
33+
Optional: true,
34+
ForceNew: true,
35+
Deprecated: "Please use the `ip_address` field instead",
36+
ConflictsWith: []string{"ip_address"},
2737
},
2838

2939
"managed": &schema.Schema{
@@ -99,8 +109,16 @@ func resourceCloudStackFirewallCreate(d *schema.ResourceData, meta interface{})
99109
return err
100110
}
101111

112+
ipaddress, ok := d.GetOk("ip_address")
113+
if !ok {
114+
ipaddress, ok = d.GetOk("ipaddress")
115+
}
116+
if !ok {
117+
return errors.New("Either `ip_address` or [deprecated] `ipaddress` must be provided.")
118+
}
119+
102120
// Retrieve the ipaddress ID
103-
ipaddressid, e := retrieveID(cs, "ipaddress", d.Get("ipaddress").(string))
121+
ipaddressid, e := retrieveID(cs, "ip_address", ipaddress.(string))
104122
if e != nil {
105123
return e.Error()
106124
}

builtin/providers/cloudstack/resource_cloudstack_firewall_test.go

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ func TestAccCloudStackFirewall_basic(t *testing.T) {
2121
Check: resource.ComposeTestCheckFunc(
2222
testAccCheckCloudStackFirewallRulesExist("cloudstack_firewall.foo"),
2323
resource.TestCheckResourceAttr(
24-
"cloudstack_firewall.foo", "ipaddress", CLOUDSTACK_PUBLIC_IPADDRESS),
24+
"cloudstack_firewall.foo", "ip_address", CLOUDSTACK_PUBLIC_IPADDRESS),
2525
resource.TestCheckResourceAttr(
2626
"cloudstack_firewall.foo", "rule.#", "2"),
2727
resource.TestCheckResourceAttr(
@@ -31,13 +31,13 @@ func TestAccCloudStackFirewall_basic(t *testing.T) {
3131
resource.TestCheckResourceAttr(
3232
"cloudstack_firewall.foo", "rule.60926170.ports.32925333", "8080"),
3333
resource.TestCheckResourceAttr(
34-
"cloudstack_firewall.foo", "rule.716592205.source_cidr", "10.0.0.0/24"),
34+
"cloudstack_firewall.foo", "rule.3832507136.cidr_list.3482919157", "10.0.0.0/24"),
3535
resource.TestCheckResourceAttr(
36-
"cloudstack_firewall.foo", "rule.716592205.protocol", "tcp"),
36+
"cloudstack_firewall.foo", "rule.3832507136.protocol", "tcp"),
3737
resource.TestCheckResourceAttr(
38-
"cloudstack_firewall.foo", "rule.716592205.ports.1209010669", "1000-2000"),
38+
"cloudstack_firewall.foo", "rule.3832507136.ports.1209010669", "1000-2000"),
3939
resource.TestCheckResourceAttr(
40-
"cloudstack_firewall.foo", "rule.716592205.ports.1889509032", "80"),
40+
"cloudstack_firewall.foo", "rule.3832507136.ports.1889509032", "80"),
4141
),
4242
},
4343
},
@@ -55,7 +55,7 @@ func TestAccCloudStackFirewall_update(t *testing.T) {
5555
Check: resource.ComposeTestCheckFunc(
5656
testAccCheckCloudStackFirewallRulesExist("cloudstack_firewall.foo"),
5757
resource.TestCheckResourceAttr(
58-
"cloudstack_firewall.foo", "ipaddress", CLOUDSTACK_PUBLIC_IPADDRESS),
58+
"cloudstack_firewall.foo", "ip_address", CLOUDSTACK_PUBLIC_IPADDRESS),
5959
resource.TestCheckResourceAttr(
6060
"cloudstack_firewall.foo", "rule.#", "2"),
6161
resource.TestCheckResourceAttr(
@@ -65,13 +65,13 @@ func TestAccCloudStackFirewall_update(t *testing.T) {
6565
resource.TestCheckResourceAttr(
6666
"cloudstack_firewall.foo", "rule.60926170.ports.32925333", "8080"),
6767
resource.TestCheckResourceAttr(
68-
"cloudstack_firewall.foo", "rule.716592205.source_cidr", "10.0.0.0/24"),
68+
"cloudstack_firewall.foo", "rule.3832507136.cidr_list.3482919157", "10.0.0.0/24"),
6969
resource.TestCheckResourceAttr(
70-
"cloudstack_firewall.foo", "rule.716592205.protocol", "tcp"),
70+
"cloudstack_firewall.foo", "rule.3832507136.protocol", "tcp"),
7171
resource.TestCheckResourceAttr(
72-
"cloudstack_firewall.foo", "rule.716592205.ports.1209010669", "1000-2000"),
72+
"cloudstack_firewall.foo", "rule.3832507136.ports.1209010669", "1000-2000"),
7373
resource.TestCheckResourceAttr(
74-
"cloudstack_firewall.foo", "rule.716592205.ports.1889509032", "80"),
74+
"cloudstack_firewall.foo", "rule.3832507136.ports.1889509032", "80"),
7575
),
7676
},
7777

@@ -80,33 +80,33 @@ func TestAccCloudStackFirewall_update(t *testing.T) {
8080
Check: resource.ComposeTestCheckFunc(
8181
testAccCheckCloudStackFirewallRulesExist("cloudstack_firewall.foo"),
8282
resource.TestCheckResourceAttr(
83-
"cloudstack_firewall.foo", "ipaddress", CLOUDSTACK_PUBLIC_IPADDRESS),
83+
"cloudstack_firewall.foo", "ip_address", CLOUDSTACK_PUBLIC_IPADDRESS),
8484
resource.TestCheckResourceAttr(
8585
"cloudstack_firewall.foo", "rule.#", "3"),
8686
resource.TestCheckResourceAttr(
87-
"cloudstack_firewall.foo", "rule.2207610982.cidr_list.80081744", "10.0.1.0/24"),
87+
"cloudstack_firewall.foo", "rule.2144925929.cidr_list.80081744", "10.0.1.0/24"),
8888
resource.TestCheckResourceAttr(
89-
"cloudstack_firewall.foo", "rule.2207610982.cidr_list.3482919157", "10.0.0.0/24"),
89+
"cloudstack_firewall.foo", "rule.2144925929.cidr_list.3482919157", "10.0.0.0/24"),
9090
resource.TestCheckResourceAttr(
91-
"cloudstack_firewall.foo", "rule.2207610982.protocol", "tcp"),
91+
"cloudstack_firewall.foo", "rule.2144925929.protocol", "tcp"),
9292
resource.TestCheckResourceAttr(
93-
"cloudstack_firewall.foo", "rule.2207610982.ports.32925333", "8080"),
93+
"cloudstack_firewall.foo", "rule.2144925929.ports.32925333", "8080"),
9494
resource.TestCheckResourceAttr(
95-
"cloudstack_firewall.foo", "rule.716592205.source_cidr", "10.0.0.0/24"),
95+
"cloudstack_firewall.foo", "rule.3832507136.cidr_list.3482919157", "10.0.0.0/24"),
9696
resource.TestCheckResourceAttr(
97-
"cloudstack_firewall.foo", "rule.716592205.protocol", "tcp"),
97+
"cloudstack_firewall.foo", "rule.3832507136.protocol", "tcp"),
9898
resource.TestCheckResourceAttr(
99-
"cloudstack_firewall.foo", "rule.716592205.ports.1209010669", "1000-2000"),
99+
"cloudstack_firewall.foo", "rule.3832507136.ports.1209010669", "1000-2000"),
100100
resource.TestCheckResourceAttr(
101-
"cloudstack_firewall.foo", "rule.716592205.ports.1889509032", "80"),
101+
"cloudstack_firewall.foo", "rule.3832507136.ports.1889509032", "80"),
102102
resource.TestCheckResourceAttr(
103-
"cloudstack_firewall.foo", "rule.4449157.source_cidr", "172.16.100.0/24"),
103+
"cloudstack_firewall.foo", "rule.302279047.cidr_list.2835005819", "172.16.100.0/24"),
104104
resource.TestCheckResourceAttr(
105-
"cloudstack_firewall.foo", "rule.4449157.protocol", "tcp"),
105+
"cloudstack_firewall.foo", "rule.302279047.protocol", "tcp"),
106106
resource.TestCheckResourceAttr(
107-
"cloudstack_firewall.foo", "rule.4449157.ports.1889509032", "80"),
107+
"cloudstack_firewall.foo", "rule.302279047.ports.1889509032", "80"),
108108
resource.TestCheckResourceAttr(
109-
"cloudstack_firewall.foo", "rule.4449157.ports.3638101695", "443"),
109+
"cloudstack_firewall.foo", "rule.302279047.ports.3638101695", "443"),
110110
),
111111
},
112112
},
@@ -174,7 +174,7 @@ func testAccCheckCloudStackFirewallDestroy(s *terraform.State) error {
174174

175175
var testAccCloudStackFirewall_basic = fmt.Sprintf(`
176176
resource "cloudstack_firewall" "foo" {
177-
ipaddress = "%s"
177+
ip_address = "%s"
178178
179179
rule {
180180
cidr_list = ["10.0.0.0/24"]
@@ -183,15 +183,15 @@ resource "cloudstack_firewall" "foo" {
183183
}
184184
185185
rule {
186-
source_cidr = "10.0.0.0/24"
186+
cidr_list = ["10.0.0.0/24"]
187187
protocol = "tcp"
188188
ports = ["80", "1000-2000"]
189189
}
190190
}`, CLOUDSTACK_PUBLIC_IPADDRESS)
191191

192192
var testAccCloudStackFirewall_update = fmt.Sprintf(`
193193
resource "cloudstack_firewall" "foo" {
194-
ipaddress = "%s"
194+
ip_address = "%s"
195195
196196
rule {
197197
cidr_list = ["10.0.0.0/24", "10.0.1.0/24"]
@@ -200,13 +200,13 @@ resource "cloudstack_firewall" "foo" {
200200
}
201201
202202
rule {
203-
source_cidr = "10.0.0.0/24"
203+
cidr_list = ["10.0.0.0/24"]
204204
protocol = "tcp"
205205
ports = ["80", "1000-2000"]
206206
}
207207
208208
rule {
209-
source_cidr = "172.16.100.0/24"
209+
cidr_list = ["172.16.100.0/24"]
210210
protocol = "tcp"
211211
ports = ["80", "443"]
212212
}

builtin/providers/cloudstack/resource_cloudstack_instance.go

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,21 @@ func resourceCloudStackInstance() *schema.Resource {
4343
ForceNew: true,
4444
},
4545

46-
"ipaddress": &schema.Schema{
46+
"ip_address": &schema.Schema{
4747
Type: schema.TypeString,
4848
Optional: true,
4949
Computed: true,
5050
ForceNew: true,
5151
},
5252

53+
"ipaddress": &schema.Schema{
54+
Type: schema.TypeString,
55+
Optional: true,
56+
Computed: true,
57+
ForceNew: true,
58+
Deprecated: "Please use the `ip_address` field instead",
59+
},
60+
5361
"template": &schema.Schema{
5462
Type: schema.TypeString,
5563
Required: true,
@@ -151,8 +159,12 @@ func resourceCloudStackInstanceCreate(d *schema.ResourceData, meta interface{})
151159
}
152160

153161
// If there is a ipaddres supplied, add it to the parameter struct
154-
if ipaddres, ok := d.GetOk("ipaddress"); ok {
155-
p.SetIpaddress(ipaddres.(string))
162+
ipaddress, ok := d.GetOk("ip_address")
163+
if !ok {
164+
ipaddress, ok = d.GetOk("ipaddress")
165+
}
166+
if ok {
167+
p.SetIpaddress(ipaddress.(string))
156168
}
157169

158170
// If there is a project supplied, we retrieve and set the project id
@@ -228,7 +240,7 @@ func resourceCloudStackInstanceRead(d *schema.ResourceData, meta interface{}) er
228240
// Update the config
229241
d.Set("name", vm.Name)
230242
d.Set("display_name", vm.Displayname)
231-
d.Set("ipaddress", vm.Nic[0].Ipaddress)
243+
d.Set("ip_address", vm.Nic[0].Ipaddress)
232244
//NB cloudstack sometimes sends back the wrong keypair name, so dont update it
233245

234246
setValueOrID(d, "network", vm.Nic[0].Networkname, vm.Nic[0].Networkid)

builtin/providers/cloudstack/resource_cloudstack_instance_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ func TestAccCloudStackInstance_fixedIP(t *testing.T) {
8282
testAccCheckCloudStackInstanceExists(
8383
"cloudstack_instance.foobar", &instance),
8484
resource.TestCheckResourceAttr(
85-
"cloudstack_instance.foobar", "ipaddress", CLOUDSTACK_NETWORK_1_IPADDRESS1),
85+
"cloudstack_instance.foobar", "ip_address", CLOUDSTACK_NETWORK_1_IPADDRESS1),
8686
),
8787
},
8888
},
@@ -267,7 +267,7 @@ resource "cloudstack_instance" "foobar" {
267267
display_name = "terraform-test"
268268
service_offering= "%s"
269269
network = "%s"
270-
ipaddress = "%s"
270+
ip_address = "%s"
271271
template = "%s"
272272
zone = "%s"
273273
expunge = true
@@ -288,7 +288,7 @@ resource "cloudstack_instance" "foobar" {
288288
display_name = "terraform-test"
289289
service_offering= "%s"
290290
network = "%s"
291-
ipaddress = "%s"
291+
ip_address = "%s"
292292
template = "%s"
293293
zone = "%s"
294294
keypair = "${cloudstack_ssh_keypair.foo.name}"

builtin/providers/cloudstack/resource_cloudstack_ipaddress.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ func resourceCloudStackIPAddress() *schema.Resource {
3434
ForceNew: true,
3535
},
3636

37-
"ipaddress": &schema.Schema{
37+
"ip_address": &schema.Schema{
3838
Type: schema.TypeString,
3939
Computed: true,
4040
},
@@ -100,7 +100,7 @@ func resourceCloudStackIPAddressRead(d *schema.ResourceData, meta interface{}) e
100100
cs := meta.(*cloudstack.CloudStackClient)
101101

102102
// Get the IP address details
103-
f, count, err := cs.Address.GetPublicIpAddressByID(d.Id())
103+
ip, count, err := cs.Address.GetPublicIpAddressByID(d.Id())
104104
if err != nil {
105105
if count == 0 {
106106
log.Printf(
@@ -113,29 +113,29 @@ func resourceCloudStackIPAddressRead(d *schema.ResourceData, meta interface{}) e
113113
}
114114

115115
// Updated the IP address
116-
d.Set("ipaddress", f.Ipaddress)
116+
d.Set("ip_address", ip.Ipaddress)
117117

118118
if _, ok := d.GetOk("network"); ok {
119119
// Get the network details
120-
n, _, err := cs.Network.GetNetworkByID(f.Associatednetworkid)
120+
n, _, err := cs.Network.GetNetworkByID(ip.Associatednetworkid)
121121
if err != nil {
122122
return err
123123
}
124124

125-
setValueOrID(d, "network", n.Name, f.Associatednetworkid)
125+
setValueOrID(d, "network", n.Name, ip.Associatednetworkid)
126126
}
127127

128128
if _, ok := d.GetOk("vpc"); ok {
129129
// Get the VPC details
130-
v, _, err := cs.VPC.GetVPCByID(f.Vpcid)
130+
v, _, err := cs.VPC.GetVPCByID(ip.Vpcid)
131131
if err != nil {
132132
return err
133133
}
134134

135-
setValueOrID(d, "vpc", v.Name, f.Vpcid)
135+
setValueOrID(d, "vpc", v.Name, ip.Vpcid)
136136
}
137137

138-
setValueOrID(d, "project", f.Project, f.Projectid)
138+
setValueOrID(d, "project", ip.Project, ip.Projectid)
139139

140140
return nil
141141
}

builtin/providers/cloudstack/resource_cloudstack_loadbalancer.go renamed to builtin/providers/cloudstack/resource_cloudstack_loadbalancer_rule.go

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package cloudstack
22

33
import (
4+
"errors"
45
"fmt"
56
"log"
67
"strings"
@@ -28,10 +29,19 @@ func resourceCloudStackLoadBalancerRule() *schema.Resource {
2829
Computed: true,
2930
},
3031

32+
"ip_address": &schema.Schema{
33+
Type: schema.TypeString,
34+
Optional: true,
35+
ForceNew: true,
36+
ConflictsWith: []string{"ipaddress"},
37+
},
38+
3139
"ipaddress": &schema.Schema{
32-
Type: schema.TypeString,
33-
Required: true,
34-
ForceNew: true,
40+
Type: schema.TypeString,
41+
Optional: true,
42+
ForceNew: true,
43+
Deprecated: "Please use the `ip_address` field instead",
44+
ConflictsWith: []string{"ip_address"},
3545
},
3646

3747
"network": &schema.Schema{
@@ -100,8 +110,16 @@ func resourceCloudStackLoadBalancerRuleCreate(d *schema.ResourceData, meta inter
100110
p.SetNetworkid(networkid)
101111
}
102112

113+
ipaddress, ok := d.GetOk("ip_address")
114+
if !ok {
115+
ipaddress, ok = d.GetOk("ipaddress")
116+
}
117+
if !ok {
118+
return errors.New("Either `ip_address` or [deprecated] `ipaddress` must be provided.")
119+
}
120+
103121
// Retrieve the ipaddress ID
104-
ipaddressid, e := retrieveID(cs, "ipaddress", d.Get("ipaddress").(string))
122+
ipaddressid, e := retrieveID(cs, "ip_address", ipaddress.(string))
105123
if e != nil {
106124
return e.Error()
107125
}
@@ -117,7 +135,7 @@ func resourceCloudStackLoadBalancerRuleCreate(d *schema.ResourceData, meta inter
117135
d.SetId(r.Id)
118136
d.SetPartial("name")
119137
d.SetPartial("description")
120-
d.SetPartial("ipaddress")
138+
d.SetPartial("ip_address")
121139
d.SetPartial("network")
122140
d.SetPartial("algorithm")
123141
d.SetPartial("private_port")
@@ -163,7 +181,7 @@ func resourceCloudStackLoadBalancerRuleRead(d *schema.ResourceData, meta interfa
163181
d.Set("public_port", lb.Publicport)
164182
d.Set("private_port", lb.Privateport)
165183

166-
setValueOrID(d, "ipaddress", lb.Publicip, lb.Publicipid)
184+
setValueOrID(d, "ip_address", lb.Publicip, lb.Publicipid)
167185

168186
// Only set network if user specified it to avoid spurious diffs
169187
if _, ok := d.GetOk("network"); ok {

0 commit comments

Comments
 (0)