providers/terraform: name it terraform_remote_state
This commit is contained in:
parent
693f688b49
commit
5a6766b702
|
@ -9,7 +9,7 @@ import (
|
||||||
func Provider() terraform.ResourceProvider {
|
func Provider() terraform.ResourceProvider {
|
||||||
return &schema.Provider{
|
return &schema.Provider{
|
||||||
ResourcesMap: map[string]*schema.Resource{
|
ResourcesMap: map[string]*schema.Resource{
|
||||||
"terraform_state": resourceState(),
|
"terraform_remote_state": resourceRemoteState(),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,11 +8,11 @@ import (
|
||||||
"github.com/hashicorp/terraform/state/remote"
|
"github.com/hashicorp/terraform/state/remote"
|
||||||
)
|
)
|
||||||
|
|
||||||
func resourceState() *schema.Resource {
|
func resourceRemoteState() *schema.Resource {
|
||||||
return &schema.Resource{
|
return &schema.Resource{
|
||||||
Create: resourceStateCreate,
|
Create: resourceRemoteStateCreate,
|
||||||
Read: resourceStateRead,
|
Read: resourceRemoteStateRead,
|
||||||
Delete: resourceStateDelete,
|
Delete: resourceRemoteStateDelete,
|
||||||
|
|
||||||
Schema: map[string]*schema.Schema{
|
Schema: map[string]*schema.Schema{
|
||||||
"backend": &schema.Schema{
|
"backend": &schema.Schema{
|
||||||
|
@ -35,11 +35,11 @@ func resourceState() *schema.Resource {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func resourceStateCreate(d *schema.ResourceData, meta interface{}) error {
|
func resourceRemoteStateCreate(d *schema.ResourceData, meta interface{}) error {
|
||||||
return resourceStateRead(d, meta)
|
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)
|
backend := d.Get("backend").(string)
|
||||||
config := make(map[string]string)
|
config := make(map[string]string)
|
||||||
for k, v := range d.Get("config").(map[string]interface{}) {
|
for k, v := range d.Get("config").(map[string]interface{}) {
|
||||||
|
@ -60,12 +60,17 @@ func resourceStateRead(d *schema.ResourceData, meta interface{}) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var outputs map[string]string
|
||||||
|
if !state.State().Empty() {
|
||||||
|
outputs = state.State().RootModule().Outputs
|
||||||
|
}
|
||||||
|
|
||||||
d.SetId(time.Now().UTC().String())
|
d.SetId(time.Now().UTC().String())
|
||||||
d.Set("output", state.State().RootModule().Outputs)
|
d.Set("output", outputs)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func resourceStateDelete(d *schema.ResourceData, meta interface{}) error {
|
func resourceRemoteStateDelete(d *schema.ResourceData, meta interface{}) error {
|
||||||
d.SetId("")
|
d.SetId("")
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,7 +17,7 @@ func TestAccState_basic(t *testing.T) {
|
||||||
Config: testAccState_basic,
|
Config: testAccState_basic,
|
||||||
Check: resource.ComposeTestCheckFunc(
|
Check: resource.ComposeTestCheckFunc(
|
||||||
testAccCheckStateValue(
|
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 = `
|
const testAccState_basic = `
|
||||||
resource "terraform_state" "foo" {
|
resource "terraform_remote_state" "foo" {
|
||||||
backend = "_local"
|
backend = "_local"
|
||||||
|
|
||||||
config {
|
config {
|
||||||
|
|
Loading…
Reference in New Issue