2015-02-09 13:15:54 -06:00
|
|
|
package terraform
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
terraform: ugly huge change to weave in new HCL2-oriented types
Due to how deeply the configuration types go into Terraform Core, there
isn't a great way to switch out to HCL2 gradually. As a consequence, this
huge commit gets us from the old state to a _compilable_ new state, but
does not yet attempt to fix any tests and has a number of known missing
parts and bugs. We will continue to iterate on this in forthcoming
commits, heading back towards passing tests and making Terraform
fully-functional again.
The three main goals here are:
- Use the configuration models from the "configs" package instead of the
older models in the "config" package, which is now deprecated and
preserved only to help us write our migration tool.
- Do expression inspection and evaluation using the functionality of the
new "lang" package, instead of the Interpolator type and related
functionality in the main "terraform" package.
- Represent addresses of various objects using types in the addrs package,
rather than hand-constructed strings. This is not critical to support
the above, but was a big help during the implementation of these other
points since it made it much more explicit what kind of address is
expected in each context.
Since our new packages are built to accommodate some future planned
features that are not yet implemented (e.g. the "for_each" argument on
resources, "count"/"for_each" on modules), and since there's still a fair
amount of functionality still using old-style APIs, there is a moderate
amount of shimming here to connect new assumptions with old, hopefully in
a way that makes it easier to find and eliminate these shims later.
I apologize in advance to the person who inevitably just found this huge
commit while spelunking through the commit history.
2018-04-30 12:33:53 -05:00
|
|
|
|
2018-07-05 12:33:29 -05:00
|
|
|
"github.com/hashicorp/terraform/configs/configschema"
|
2018-08-17 11:42:07 -05:00
|
|
|
"github.com/hashicorp/terraform/provisioners"
|
2015-02-09 13:15:54 -06:00
|
|
|
)
|
|
|
|
|
|
|
|
// EvalInitProvisioner is an EvalNode implementation that initializes a provisioner
|
|
|
|
// and returns nothing. The provisioner can be retrieved again with the
|
|
|
|
// EvalGetProvisioner node.
|
|
|
|
type EvalInitProvisioner struct {
|
|
|
|
Name string
|
|
|
|
}
|
|
|
|
|
2015-02-14 00:58:41 -06:00
|
|
|
func (n *EvalInitProvisioner) Eval(ctx EvalContext) (interface{}, error) {
|
2015-02-09 13:15:54 -06:00
|
|
|
return ctx.InitProvisioner(n.Name)
|
|
|
|
}
|
|
|
|
|
2015-06-19 14:52:50 -05:00
|
|
|
// EvalCloseProvisioner is an EvalNode implementation that closes provisioner
|
|
|
|
// connections that aren't needed anymore.
|
|
|
|
type EvalCloseProvisioner struct {
|
|
|
|
Name string
|
|
|
|
}
|
|
|
|
|
|
|
|
func (n *EvalCloseProvisioner) Eval(ctx EvalContext) (interface{}, error) {
|
|
|
|
ctx.CloseProvisioner(n.Name)
|
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
|
2015-02-09 13:15:54 -06:00
|
|
|
// EvalGetProvisioner is an EvalNode implementation that retrieves an already
|
|
|
|
// initialized provisioner instance for the given name.
|
|
|
|
type EvalGetProvisioner struct {
|
2015-02-14 00:58:41 -06:00
|
|
|
Name string
|
2018-08-17 11:42:07 -05:00
|
|
|
Output *provisioners.Interface
|
terraform: ugly huge change to weave in new HCL2-oriented types
Due to how deeply the configuration types go into Terraform Core, there
isn't a great way to switch out to HCL2 gradually. As a consequence, this
huge commit gets us from the old state to a _compilable_ new state, but
does not yet attempt to fix any tests and has a number of known missing
parts and bugs. We will continue to iterate on this in forthcoming
commits, heading back towards passing tests and making Terraform
fully-functional again.
The three main goals here are:
- Use the configuration models from the "configs" package instead of the
older models in the "config" package, which is now deprecated and
preserved only to help us write our migration tool.
- Do expression inspection and evaluation using the functionality of the
new "lang" package, instead of the Interpolator type and related
functionality in the main "terraform" package.
- Represent addresses of various objects using types in the addrs package,
rather than hand-constructed strings. This is not critical to support
the above, but was a big help during the implementation of these other
points since it made it much more explicit what kind of address is
expected in each context.
Since our new packages are built to accommodate some future planned
features that are not yet implemented (e.g. the "for_each" argument on
resources, "count"/"for_each" on modules), and since there's still a fair
amount of functionality still using old-style APIs, there is a moderate
amount of shimming here to connect new assumptions with old, hopefully in
a way that makes it easier to find and eliminate these shims later.
I apologize in advance to the person who inevitably just found this huge
commit while spelunking through the commit history.
2018-04-30 12:33:53 -05:00
|
|
|
Schema **configschema.Block
|
2015-02-09 13:15:54 -06:00
|
|
|
}
|
|
|
|
|
2015-02-14 00:58:41 -06:00
|
|
|
func (n *EvalGetProvisioner) Eval(ctx EvalContext) (interface{}, error) {
|
2015-02-09 13:15:54 -06:00
|
|
|
result := ctx.Provisioner(n.Name)
|
|
|
|
if result == nil {
|
|
|
|
return nil, fmt.Errorf("provisioner %s not initialized", n.Name)
|
|
|
|
}
|
|
|
|
|
2015-02-14 00:58:41 -06:00
|
|
|
if n.Output != nil {
|
|
|
|
*n.Output = result
|
|
|
|
}
|
2015-02-09 13:15:54 -06:00
|
|
|
|
terraform: ugly huge change to weave in new HCL2-oriented types
Due to how deeply the configuration types go into Terraform Core, there
isn't a great way to switch out to HCL2 gradually. As a consequence, this
huge commit gets us from the old state to a _compilable_ new state, but
does not yet attempt to fix any tests and has a number of known missing
parts and bugs. We will continue to iterate on this in forthcoming
commits, heading back towards passing tests and making Terraform
fully-functional again.
The three main goals here are:
- Use the configuration models from the "configs" package instead of the
older models in the "config" package, which is now deprecated and
preserved only to help us write our migration tool.
- Do expression inspection and evaluation using the functionality of the
new "lang" package, instead of the Interpolator type and related
functionality in the main "terraform" package.
- Represent addresses of various objects using types in the addrs package,
rather than hand-constructed strings. This is not critical to support
the above, but was a big help during the implementation of these other
points since it made it much more explicit what kind of address is
expected in each context.
Since our new packages are built to accommodate some future planned
features that are not yet implemented (e.g. the "for_each" argument on
resources, "count"/"for_each" on modules), and since there's still a fair
amount of functionality still using old-style APIs, there is a moderate
amount of shimming here to connect new assumptions with old, hopefully in
a way that makes it easier to find and eliminate these shims later.
I apologize in advance to the person who inevitably just found this huge
commit while spelunking through the commit history.
2018-04-30 12:33:53 -05:00
|
|
|
if n.Schema != nil {
|
|
|
|
*n.Schema = ctx.ProvisionerSchema(n.Name)
|
|
|
|
}
|
|
|
|
|
2015-02-14 00:58:41 -06:00
|
|
|
return result, nil
|
2015-02-09 13:15:54 -06:00
|
|
|
}
|