diff --git a/resource_state.go b/data_source_state.go similarity index 72% rename from resource_state.go rename to data_source_state.go index 8f5855573..68369eaae 100644 --- a/resource_state.go +++ b/data_source_state.go @@ -8,23 +8,19 @@ import ( "github.com/hashicorp/terraform/state/remote" ) -func resourceRemoteState() *schema.Resource { +func dataSourceRemoteState() *schema.Resource { return &schema.Resource{ - Create: resourceRemoteStateCreate, - Read: resourceRemoteStateRead, - Delete: resourceRemoteStateDelete, + Read: dataSourceRemoteStateRead, Schema: map[string]*schema.Schema{ "backend": &schema.Schema{ Type: schema.TypeString, Required: true, - ForceNew: true, }, "config": &schema.Schema{ Type: schema.TypeMap, Optional: true, - ForceNew: true, }, "output": &schema.Schema{ @@ -35,11 +31,7 @@ func resourceRemoteState() *schema.Resource { } } -func resourceRemoteStateCreate(d *schema.ResourceData, meta interface{}) error { - return resourceRemoteStateRead(d, meta) -} - -func resourceRemoteStateRead(d *schema.ResourceData, meta interface{}) error { +func dataSourceRemoteStateRead(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{}) { @@ -69,8 +61,3 @@ func resourceRemoteStateRead(d *schema.ResourceData, meta interface{}) error { d.Set("output", outputs) return nil } - -func resourceRemoteStateDelete(d *schema.ResourceData, meta interface{}) error { - d.SetId("") - return nil -} diff --git a/resource_state_test.go b/data_source_state_test.go similarity index 100% rename from resource_state_test.go rename to data_source_state_test.go diff --git a/provider.go b/provider.go index e71d5f40a..7e14f87d6 100644 --- a/provider.go +++ b/provider.go @@ -9,7 +9,12 @@ import ( func Provider() terraform.ResourceProvider { return &schema.Provider{ ResourcesMap: map[string]*schema.Resource{ - "terraform_remote_state": resourceRemoteState(), + "terraform_remote_state": schema.DataSourceResourceShim( + dataSourceRemoteState(), + ), + }, + DataSourcesMap: map[string]*schema.Resource{ + "terraform_remote_state": dataSourceRemoteState(), }, } }