provider/terraform: remote state resource becomes a data source
As a first example of a real-world data source, the pre-existing terraform_remote_state resource is adapted to be a data source. The original resource is shimmed to wrap the data source for backward compatibility.
This commit is contained in:
parent
433fcb3046
commit
e455f0a9bb
|
@ -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
|
||||
}
|
|
@ -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(),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue