@@ -19,48 +19,82 @@ func init() {
19
19
})
20
20
}
21
21
22
- func TestAccFloatingIP_Server (t * testing.T ) {
22
+ func TestAccHcloudFloatingIP_AssignAndUpdateDescription (t * testing.T ) {
23
23
var floatingIP hcloud.FloatingIP
24
24
rInt := acctest .RandInt ()
25
25
26
26
resource .Test (t , resource.TestCase {
27
- PreCheck : func () { testAccPreCheck (t ) },
27
+ PreCheck : func () { testAccHcloudPreCheck (t ) },
28
28
Providers : testAccProviders ,
29
- CheckDestroy : testAccCheckFloatingIPDestroy ,
29
+ CheckDestroy : testAccHcloudCheckFloatingIPDestroy ,
30
30
Steps : []resource.TestStep {
31
31
{
32
- Config : testAccCheckFloatingIPConfig_server (rInt ),
32
+ Config : testAccHcloudCheckFloatingIPConfig_server (rInt ),
33
33
Check : resource .ComposeTestCheckFunc (
34
- testAccCheckFloatingIPExists ("hcloud_floating_ip.foobar " , & floatingIP ),
34
+ testAccHcloudCheckFloatingIPExists ("hcloud_floating_ip.floating_ip " , & floatingIP ),
35
35
resource .TestCheckResourceAttr (
36
- "hcloud_floating_ip.foobar" , "home_location" , "fsn1" ),
36
+ "hcloud_floating_ip.floating_ip" , "home_location" , "fsn1" ),
37
+ resource .TestCheckResourceAttr (
38
+ "hcloud_floating_ip.floating_ip" , "description" , "test" ),
39
+ ),
40
+ },
41
+ {
42
+ Config : testAccHcloudCheckFloatingIPConfig_updateDescription (rInt ),
43
+ Check : resource .ComposeTestCheckFunc (
44
+ testAccHcloudCheckFloatingIPExists ("hcloud_floating_ip.floating_ip" , & floatingIP ),
45
+ resource .TestCheckResourceAttr (
46
+ "hcloud_floating_ip.floating_ip" , "home_location" , "fsn1" ),
47
+ resource .TestCheckResourceAttr (
48
+ "hcloud_floating_ip.floating_ip" , "description" , "updated test" ),
37
49
),
38
50
},
39
51
},
40
52
})
41
53
}
42
54
43
- func testAccCheckFloatingIPConfig_server (rInt int ) string {
55
+ func testAccHcloudCheckFloatingIPConfig_server (rInt int ) string {
44
56
return fmt .Sprintf (`
45
- resource "hcloud_ssh_key" "foobar " {
46
- name = "foobar -%d"
57
+ resource "hcloud_ssh_key" "floating_ip " {
58
+ name = "floating-ip -%d"
47
59
public_key = "%s"
48
60
}
49
- resource "hcloud_server" "foobar " {
50
- name = "foo -%d"
61
+ resource "hcloud_server" "floating_ip1 " {
62
+ name = "floating-ip-1 -%d"
51
63
server_type = "cx11"
52
64
image = "debian-9"
53
65
datacenter = "fsn1-dc8"
54
- ssh_keys = ["${hcloud_ssh_key.foobar .id}"]
66
+ ssh_keys = ["${hcloud_ssh_key.floating_ip .id}"]
55
67
}
56
68
57
- resource "hcloud_floating_ip" "foobar" {
58
- server_id = "${hcloud_server.foobar.id}"
59
- type = "ipv4"
69
+ resource "hcloud_floating_ip" "floating_ip" {
70
+ server_id = "${hcloud_server.floating_ip1.id}"
71
+ type = "ipv4"
72
+ description = "test"
60
73
}` , rInt , testAccSSHPublicKey , rInt )
61
74
}
62
75
63
- func testAccCheckFloatingIPDestroy (s * terraform.State ) error {
76
+ func testAccHcloudCheckFloatingIPConfig_updateDescription (rInt int ) string {
77
+ return fmt .Sprintf (`
78
+ resource "hcloud_ssh_key" "floating_ip" {
79
+ name = "floating-ip-%d"
80
+ public_key = "%s"
81
+ }
82
+ resource "hcloud_server" "floating_ip1" {
83
+ name = "floating-ip-1-%d"
84
+ server_type = "cx11"
85
+ image = "debian-9"
86
+ datacenter = "fsn1-dc8"
87
+ ssh_keys = ["${hcloud_ssh_key.floating_ip.id}"]
88
+ }
89
+
90
+ resource "hcloud_floating_ip" "floating_ip" {
91
+ server_id = "${hcloud_server.floating_ip1.id}"
92
+ type = "ipv4"
93
+ description = "updated test"
94
+ }` , rInt , testAccSSHPublicKey , rInt )
95
+ }
96
+
97
+ func testAccHcloudCheckFloatingIPDestroy (s * terraform.State ) error {
64
98
client := testAccProvider .Meta ().(* hcloud.Client )
65
99
66
100
for _ , rs := range s .RootModule ().Resources {
@@ -72,18 +106,22 @@ func testAccCheckFloatingIPDestroy(s *terraform.State) error {
72
106
if err != nil {
73
107
return fmt .Errorf ("Floating IP id is no int: %v" , err )
74
108
}
75
- _ , _ , err = client .FloatingIP .GetByID (context .Background (), id )
109
+ var floatingIP * hcloud.FloatingIP
110
+ floatingIP , _ , err = client .FloatingIP .GetByID (context .Background (), id )
76
111
if err != nil {
77
112
return fmt .Errorf (
78
- "Error waiting for floating ip (%s) to be destroyed : %v" ,
113
+ "Error checking if floating ip (%s) is deleted : %v" ,
79
114
rs .Primary .ID , err )
80
115
}
116
+ if floatingIP != nil {
117
+ return fmt .Errorf ("Floating ip (%s) has not been deleted" , rs .Primary .ID )
118
+ }
81
119
}
82
120
83
121
return nil
84
122
}
85
123
86
- func testAccCheckFloatingIPExists (n string , floatingIP * hcloud.FloatingIP ) resource.TestCheckFunc {
124
+ func testAccHcloudCheckFloatingIPExists (n string , floatingIP * hcloud.FloatingIP ) resource.TestCheckFunc {
87
125
return func (s * terraform.State ) error {
88
126
rs , ok := s .RootModule ().Resources [n ]
89
127
if ! ok {
0 commit comments