terraform: Passthrough provisioner level connection info
This commit is contained in:
parent
36b1a2b9e8
commit
94c95afa48
|
@ -555,6 +555,13 @@ func (c *Context) applyWalkFn() depgraph.WalkFunc {
|
||||||
// defined after the resource creation has already completed.
|
// defined after the resource creation has already completed.
|
||||||
func (c *Context) applyProvisioners(r *Resource, rs *ResourceState) (*ResourceState, error) {
|
func (c *Context) applyProvisioners(r *Resource, rs *ResourceState) (*ResourceState, error) {
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
|
// Store the original connection info, restore later
|
||||||
|
origConnInfo := rs.ConnInfo
|
||||||
|
defer func() {
|
||||||
|
rs.ConnInfo = origConnInfo
|
||||||
|
}()
|
||||||
|
|
||||||
for _, prov := range r.Provisioners {
|
for _, prov := range r.Provisioners {
|
||||||
// Interpolate since we may have variables that depend on the
|
// Interpolate since we may have variables that depend on the
|
||||||
// local resource.
|
// local resource.
|
||||||
|
@ -562,6 +569,24 @@ func (c *Context) applyProvisioners(r *Resource, rs *ResourceState) (*ResourceSt
|
||||||
return rs, err
|
return rs, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Interpolate the conn info, since it may contain variables
|
||||||
|
connInfo := NewResourceConfig(prov.ConnInfo)
|
||||||
|
if err := connInfo.interpolate(c); err != nil {
|
||||||
|
return rs, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Merge the connection information
|
||||||
|
overlay := make(map[string]interface{})
|
||||||
|
if origConnInfo != nil {
|
||||||
|
for k, v := range origConnInfo.Raw {
|
||||||
|
overlay[k] = v
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for k, v := range connInfo.Config {
|
||||||
|
overlay[k] = v
|
||||||
|
}
|
||||||
|
rs.ConnInfo = &ResourceConnectionInfo{Raw: overlay}
|
||||||
|
|
||||||
// Invoke the Provisioner
|
// Invoke the Provisioner
|
||||||
rs, err = prov.Provisioner.Apply(rs, prov.Config)
|
rs, err = prov.Provisioner.Apply(rs, prov.Config)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -546,6 +546,9 @@ func graphAddVariableDeps(g *depgraph.Graph) {
|
||||||
for _, p := range m.Resource.Provisioners {
|
for _, p := range m.Resource.Provisioners {
|
||||||
vars = p.RawConfig.Variables
|
vars = p.RawConfig.Variables
|
||||||
nounAddVariableDeps(g, n, vars)
|
nounAddVariableDeps(g, n, vars)
|
||||||
|
|
||||||
|
vars = p.ConnInfo.Variables
|
||||||
|
nounAddVariableDeps(g, n, vars)
|
||||||
}
|
}
|
||||||
|
|
||||||
case *GraphNodeResourceProvider:
|
case *GraphNodeResourceProvider:
|
||||||
|
@ -774,6 +777,7 @@ func graphMapResourceProvisioners(g *depgraph.Graph,
|
||||||
Provisioner: provisioner,
|
Provisioner: provisioner,
|
||||||
Config: NewResourceConfig(p.RawConfig),
|
Config: NewResourceConfig(p.RawConfig),
|
||||||
RawConfig: p.RawConfig,
|
RawConfig: p.RawConfig,
|
||||||
|
ConnInfo: p.ConnInfo,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,6 +18,7 @@ type ResourceProvisionerConfig struct {
|
||||||
Provisioner ResourceProvisioner
|
Provisioner ResourceProvisioner
|
||||||
Config *ResourceConfig
|
Config *ResourceConfig
|
||||||
RawConfig *config.RawConfig
|
RawConfig *config.RawConfig
|
||||||
|
ConnInfo *config.RawConfig
|
||||||
}
|
}
|
||||||
|
|
||||||
// Resource encapsulates a resource, its configuration, its provider,
|
// Resource encapsulates a resource, its configuration, its provider,
|
||||||
|
|
|
@ -250,14 +250,10 @@ func WriteState(d *State, dst io.Writer) error {
|
||||||
// by a provider so that provisioners can connect and run on the
|
// by a provider so that provisioners can connect and run on the
|
||||||
// resource.
|
// resource.
|
||||||
type ResourceConnectionInfo struct {
|
type ResourceConnectionInfo struct {
|
||||||
// Type is set so that an appropriate connection can be formed.
|
// Raw is used to store any relevant keys for the given 'type'
|
||||||
// As an example, for a Linux machine, the Type may be "ssh"
|
|
||||||
Type string
|
|
||||||
|
|
||||||
// Raw is used to store any relevant keys for the given Type
|
|
||||||
// so that a provisioner can connect to the resource. This could
|
// so that a provisioner can connect to the resource. This could
|
||||||
// contain credentials or address information.
|
// contain credentials or address information.
|
||||||
Raw map[string]string
|
Raw map[string]interface{}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ResourceState holds the state of a resource that is used so that
|
// ResourceState holds the state of a resource that is used so that
|
||||||
|
|
|
@ -99,8 +99,8 @@ func TestReadWriteState(t *testing.T) {
|
||||||
"foo": &ResourceState{
|
"foo": &ResourceState{
|
||||||
ID: "bar",
|
ID: "bar",
|
||||||
ConnInfo: &ResourceConnectionInfo{
|
ConnInfo: &ResourceConnectionInfo{
|
||||||
Type: "ssh",
|
Raw: map[string]interface{}{
|
||||||
Raw: map[string]string{
|
"type": "ssh",
|
||||||
"user": "root",
|
"user": "root",
|
||||||
"password": "supersecret",
|
"password": "supersecret",
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in New Issue