Handle Scaleway tags correctly (#7682)

This commit is contained in:
Raphael Randschau 2016-07-18 11:12:15 +02:00 committed by Paul Stack
parent 9dbf998d23
commit 697828f81f
2 changed files with 18 additions and 2 deletions

View File

@ -82,8 +82,10 @@ func resourceScalewayServerCreate(d *schema.ResourceData, m interface{}) error {
server.Bootscript = String(bootscript.(string)) server.Bootscript = String(bootscript.(string))
} }
if tags, ok := d.GetOk("tags"); ok { if raw, ok := d.GetOk("tags"); ok {
server.Tags = tags.([]string) for _, tag := range raw.([]interface{}) {
server.Tags = append(server.Tags, tag.(string))
}
} }
id, err := scaleway.PostServer(server) id, err := scaleway.PostServer(server)
@ -129,6 +131,7 @@ func resourceScalewayServerRead(d *schema.ResourceData, m interface{}) error {
d.Set("ipv4_address_public", server.PublicAddress.IP) d.Set("ipv4_address_public", server.PublicAddress.IP)
d.Set("state", server.State) d.Set("state", server.State)
d.Set("state_detail", server.StateDetail) d.Set("state_detail", server.StateDetail)
d.Set("tags", server.Tags)
d.SetConnInfo(map[string]string{ d.SetConnInfo(map[string]string{
"type": "ssh", "type": "ssh",
@ -148,6 +151,16 @@ func resourceScalewayServerUpdate(d *schema.ResourceData, m interface{}) error {
req.Name = &name req.Name = &name
} }
if d.HasChange("tags") {
if raw, ok := d.GetOk("tags"); ok {
var tags []string
for _, tag := range raw.([]interface{}) {
tags = append(tags, tag.(string))
}
req.Tags = &tags
}
}
if d.HasChange("dynamic_ip_required") { if d.HasChange("dynamic_ip_required") {
req.DynamicIPRequired = Bool(d.Get("dynamic_ip_required").(bool)) req.DynamicIPRequired = Bool(d.Get("dynamic_ip_required").(bool))
} }

View File

@ -23,6 +23,8 @@ func TestAccScalewayServer_Basic(t *testing.T) {
"scaleway_server.base", "type", "C1"), "scaleway_server.base", "type", "C1"),
resource.TestCheckResourceAttr( resource.TestCheckResourceAttr(
"scaleway_server.base", "name", "test"), "scaleway_server.base", "name", "test"),
resource.TestCheckResourceAttr(
"scaleway_server.base", "tags.0", "terraform-test"),
), ),
}, },
}, },
@ -110,4 +112,5 @@ resource "scaleway_server" "base" {
# ubuntu 14.04 # ubuntu 14.04
image = "%s" image = "%s"
type = "C1" type = "C1"
tags = [ "terraform-test" ]
}`, armImageIdentifier) }`, armImageIdentifier)