From 5a6766b702edae5f3a4459e681b735d1c4c50ac0 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Wed, 1 Apr 2015 22:49:05 -0700 Subject: [PATCH] providers/terraform: name it terraform_remote_state --- provider.go | 2 +- resource_state.go | 23 ++++++++++++++--------- resource_state_test.go | 4 ++-- 3 files changed, 17 insertions(+), 12 deletions(-) diff --git a/provider.go b/provider.go index 0330ce775..e71d5f40a 100644 --- a/provider.go +++ b/provider.go @@ -9,7 +9,7 @@ import ( func Provider() terraform.ResourceProvider { return &schema.Provider{ ResourcesMap: map[string]*schema.Resource{ - "terraform_state": resourceState(), + "terraform_remote_state": resourceRemoteState(), }, } } diff --git a/resource_state.go b/resource_state.go index 85de3990d..fb0e85ee2 100644 --- a/resource_state.go +++ b/resource_state.go @@ -8,11 +8,11 @@ import ( "github.com/hashicorp/terraform/state/remote" ) -func resourceState() *schema.Resource { +func resourceRemoteState() *schema.Resource { return &schema.Resource{ - Create: resourceStateCreate, - Read: resourceStateRead, - Delete: resourceStateDelete, + Create: resourceRemoteStateCreate, + Read: resourceRemoteStateRead, + Delete: resourceRemoteStateDelete, Schema: map[string]*schema.Schema{ "backend": &schema.Schema{ @@ -35,11 +35,11 @@ func resourceState() *schema.Resource { } } -func resourceStateCreate(d *schema.ResourceData, meta interface{}) error { - return resourceStateRead(d, meta) +func resourceRemoteStateCreate(d *schema.ResourceData, meta interface{}) error { + return resourceRemoteStateRead(d, meta) } -func resourceStateRead(d *schema.ResourceData, meta interface{}) error { +func resourceRemoteStateRead(d *schema.ResourceData, meta interface{}) error { backend := d.Get("backend").(string) config := make(map[string]string) for k, v := range d.Get("config").(map[string]interface{}) { @@ -60,12 +60,17 @@ func resourceStateRead(d *schema.ResourceData, meta interface{}) error { return err } + var outputs map[string]string + if !state.State().Empty() { + outputs = state.State().RootModule().Outputs + } + d.SetId(time.Now().UTC().String()) - d.Set("output", state.State().RootModule().Outputs) + d.Set("output", outputs) return nil } -func resourceStateDelete(d *schema.ResourceData, meta interface{}) error { +func resourceRemoteStateDelete(d *schema.ResourceData, meta interface{}) error { d.SetId("") return nil } diff --git a/resource_state_test.go b/resource_state_test.go index 6db173503..42ad55ada 100644 --- a/resource_state_test.go +++ b/resource_state_test.go @@ -17,7 +17,7 @@ func TestAccState_basic(t *testing.T) { Config: testAccState_basic, Check: resource.ComposeTestCheckFunc( testAccCheckStateValue( - "terraform_state.foo", "foo", "bar"), + "terraform_remote_state.foo", "foo", "bar"), ), }, }, @@ -45,7 +45,7 @@ func testAccCheckStateValue(id, name, value string) resource.TestCheckFunc { } const testAccState_basic = ` -resource "terraform_state" "foo" { +resource "terraform_remote_state" "foo" { backend = "_local" config {