diff --git a/builtin/providers/test/provider.go b/builtin/providers/test/provider.go index 948e82f87..7ccdfa5ff 100644 --- a/builtin/providers/test/provider.go +++ b/builtin/providers/test/provider.go @@ -29,6 +29,7 @@ func Provider() terraform.ResourceProvider { "test_resource_deprecated": testResourceDeprecated(), "test_resource_defaults": testResourceDefaults(), "test_resource_list": testResourceList(), + "test_resource_map": testResourceMap(), }, DataSourcesMap: map[string]*schema.Resource{ "test_data_source": testDataSource(), diff --git a/builtin/providers/test/resource_map.go b/builtin/providers/test/resource_map.go new file mode 100644 index 000000000..fe524f69f --- /dev/null +++ b/builtin/providers/test/resource_map.go @@ -0,0 +1,52 @@ +package test + +import ( + "fmt" + + "github.com/hashicorp/terraform/helper/schema" +) + +func testResourceMap() *schema.Resource { + return &schema.Resource{ + Create: testResourceMapCreate, + Read: testResourceMapRead, + Update: testResourceMapUpdate, + Delete: testResourceMapDelete, + + Schema: map[string]*schema.Schema{ + "name": { + Type: schema.TypeString, + Required: true, + }, + "map_of_three": { + Type: schema.TypeMap, + Optional: true, + Elem: &schema.Schema{Type: schema.TypeString}, + }, + }, + } +} + +func testResourceMapCreate(d *schema.ResourceData, meta interface{}) error { + // make sure all elements are passed to the map + m := d.Get("map_of_three").(map[string]interface{}) + if len(m) != 3 { + return fmt.Errorf("expected 3 map values, got %#v\n", m) + } + + d.SetId("testId") + return nil +} + +func testResourceMapRead(d *schema.ResourceData, meta interface{}) error { + return nil +} + +func testResourceMapUpdate(d *schema.ResourceData, meta interface{}) error { + return nil +} + +func testResourceMapDelete(d *schema.ResourceData, meta interface{}) error { + d.SetId("") + return nil +} diff --git a/builtin/providers/test/resource_map_test.go b/builtin/providers/test/resource_map_test.go new file mode 100644 index 000000000..800247eda --- /dev/null +++ b/builtin/providers/test/resource_map_test.go @@ -0,0 +1,32 @@ +package test + +import ( + "testing" + + "github.com/hashicorp/terraform/helper/resource" +) + +func TestResourceMap_basic(t *testing.T) { + resource.UnitTest(t, resource.TestCase{ + Providers: testAccProviders, + CheckDestroy: testAccCheckResourceDestroy, + Steps: []resource.TestStep{ + { + Config: ` +resource "test_resource_map" "foobar" { + name = "test" + map_of_three = { + one = "one" + two = "two" + empty = "" + } +}`, + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr( + "test_resource_map.foobar", "map_of_three.empty", "", + ), + ), + }, + }, + }) +}