From b0f9eb5c139aa8983584a55058e05d38ee1a5847 Mon Sep 17 00:00:00 2001 From: James Nugent Date: Wed, 20 Jan 2016 09:58:20 -0500 Subject: [PATCH] provider/template: Allow update in `template_cloudinit_config` --- .../template/resource_cloudinit_config.go | 2 +- .../resource_cloudinit_config_test.go | 46 +++++++++++++++++++ 2 files changed, 47 insertions(+), 1 deletion(-) diff --git a/builtin/providers/template/resource_cloudinit_config.go b/builtin/providers/template/resource_cloudinit_config.go index 0082dde62..78efcecf4 100644 --- a/builtin/providers/template/resource_cloudinit_config.go +++ b/builtin/providers/template/resource_cloudinit_config.go @@ -19,6 +19,7 @@ func resourceCloudinitConfig() *schema.Resource { return &schema.Resource{ Create: resourceCloudinitConfigCreate, Delete: resourceCloudinitConfigDelete, + Update: resourceCloudinitConfigCreate, Exists: resourceCloudinitConfigExists, Read: resourceCloudinitConfigRead, @@ -26,7 +27,6 @@ func resourceCloudinitConfig() *schema.Resource { "part": &schema.Schema{ Type: schema.TypeList, Required: true, - ForceNew: true, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ "content_type": &schema.Schema{ diff --git a/builtin/providers/template/resource_cloudinit_config_test.go b/builtin/providers/template/resource_cloudinit_config_test.go index afaac1971..41cd23214 100644 --- a/builtin/providers/template/resource_cloudinit_config_test.go +++ b/builtin/providers/template/resource_cloudinit_config_test.go @@ -85,3 +85,49 @@ func TestRender(t *testing.T) { }) } } + +func TestCloudConfig_update(t *testing.T) { + r.Test(t, r.TestCase{ + Providers: testProviders, + Steps: []r.TestStep{ + r.TestStep{ + Config: testCloudInitConfig_basic, + Check: r.ComposeTestCheckFunc( + r.TestCheckResourceAttr("template_cloudinit_config.config", "rendered", testCloudInitConfig_basic_expected), + ), + }, + + r.TestStep{ + Config: testCloudInitConfig_update, + Check: r.ComposeTestCheckFunc( + r.TestCheckResourceAttr("template_cloudinit_config.config", "rendered", testCloudInitConfig_update_expected), + ), + }, + }, + }) +} + +var testCloudInitConfig_basic = ` +resource "template_cloudinit_config" "config" { + part { + content_type = "text/x-shellscript" + content = "baz" + } +}` + +var testCloudInitConfig_basic_expected = `Content-Type: multipart/mixed; boundary=\"MIMEBOUNDRY\"\nMIME-Version: 1.0\r\n--MIMEBOUNDRY\r\nContent-Transfer-Encoding: 7bit\r\nContent-Type: text/x-shellscript\r\nMime-Version: 1.0\r\n\r\nbaz\r\n--MIMEBOUNDRY--\r\n` + +var testCloudInitConfig_update = ` +resource "template_cloudinit_config" "config" { + part { + content_type = "text/x-shellscript" + content = "baz" + } + + part { + content_type = "text/x-shellscript" + content = "ffbaz" + } +}` + +var testCloudInitConfig_update_expected = `Content-Type: multipart/mixed; boundary=\"MIMEBOUNDRY\"\nMIME-Version: 1.0\r\n--MIMEBOUNDRY\r\nContent-Transfer-Encoding: 7bit\r\nContent-Type: text/x-shellscript\r\nMime-Version: 1.0\r\n\r\nbaz\r\n--MIMEBOUNDRY\r\nContent-Transfer-Encoding: 7bit\r\nContent-Type: text/x-shellscript\r\nMime-Version: 1.0\r\n\r\nffbaz\r\n--MIMEBOUNDRY--\r\n`