2016-09-16 01:20:35 -05:00
|
|
|
package terraform
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2020-03-06 17:02:20 -06:00
|
|
|
"log"
|
2016-09-16 01:20:35 -05:00
|
|
|
|
2020-09-25 14:10:32 -05:00
|
|
|
"github.com/hashicorp/hcl/v2"
|
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
|
|
|
"github.com/hashicorp/terraform/addrs"
|
|
|
|
"github.com/hashicorp/terraform/configs"
|
2017-05-10 20:27:49 -05:00
|
|
|
"github.com/hashicorp/terraform/dag"
|
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
|
|
|
"github.com/hashicorp/terraform/lang"
|
2020-09-08 13:02:45 -05:00
|
|
|
"github.com/hashicorp/terraform/plans"
|
|
|
|
"github.com/hashicorp/terraform/states"
|
2020-10-09 10:09:36 -05:00
|
|
|
"github.com/hashicorp/terraform/tfdiags"
|
2020-09-08 13:02:45 -05:00
|
|
|
"github.com/zclconf/go-cty/cty"
|
2016-09-16 01:20:35 -05:00
|
|
|
)
|
|
|
|
|
2020-10-09 16:24:10 -05:00
|
|
|
// nodeExpandOutput is the placeholder for a non-root module output that has
|
|
|
|
// not yet had its module path expanded.
|
2020-05-12 09:44:45 -05:00
|
|
|
type nodeExpandOutput struct {
|
2020-10-09 10:09:36 -05:00
|
|
|
Addr addrs.OutputValue
|
|
|
|
Module addrs.Module
|
|
|
|
Config *configs.Output
|
|
|
|
Changes []*plans.OutputChangeSrc
|
|
|
|
Destroy bool
|
2020-02-24 16:42:32 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
var (
|
2020-05-12 09:44:45 -05:00
|
|
|
_ GraphNodeReferenceable = (*nodeExpandOutput)(nil)
|
|
|
|
_ GraphNodeReferencer = (*nodeExpandOutput)(nil)
|
2020-06-06 20:42:01 -05:00
|
|
|
_ GraphNodeReferenceOutside = (*nodeExpandOutput)(nil)
|
2020-05-12 09:44:45 -05:00
|
|
|
_ GraphNodeDynamicExpandable = (*nodeExpandOutput)(nil)
|
2020-05-18 19:59:17 -05:00
|
|
|
_ graphNodeTemporaryValue = (*nodeExpandOutput)(nil)
|
2020-05-21 21:11:58 -05:00
|
|
|
_ graphNodeExpandsInstances = (*nodeExpandOutput)(nil)
|
2020-02-24 16:42:32 -06:00
|
|
|
)
|
|
|
|
|
2020-05-21 21:11:58 -05:00
|
|
|
func (n *nodeExpandOutput) expandsInstances() {}
|
2020-05-18 19:59:17 -05:00
|
|
|
|
2020-05-12 09:44:45 -05:00
|
|
|
func (n *nodeExpandOutput) temporaryValue() bool {
|
2020-10-09 16:24:10 -05:00
|
|
|
// non root outputs are temporary
|
2020-04-02 12:26:53 -05:00
|
|
|
return !n.Module.IsRoot()
|
|
|
|
}
|
|
|
|
|
2020-05-12 09:44:45 -05:00
|
|
|
func (n *nodeExpandOutput) DynamicExpand(ctx EvalContext) (*Graph, error) {
|
2020-10-09 10:09:36 -05:00
|
|
|
if n.Destroy {
|
2020-10-09 16:24:10 -05:00
|
|
|
// if we're planning a destroy, we only need to handle the root outputs.
|
|
|
|
// The destroy plan doesn't evaluate any other config, so we can skip
|
|
|
|
// the rest of the outputs.
|
|
|
|
return n.planDestroyRootOutput(ctx)
|
2020-10-09 10:09:36 -05:00
|
|
|
}
|
|
|
|
|
2020-02-24 16:42:32 -06:00
|
|
|
expander := ctx.InstanceExpander()
|
2020-10-09 16:24:10 -05:00
|
|
|
|
|
|
|
var g Graph
|
2020-03-06 17:02:20 -06:00
|
|
|
for _, module := range expander.ExpandModule(n.Module) {
|
2020-10-09 10:09:36 -05:00
|
|
|
absAddr := n.Addr.Absolute(module)
|
|
|
|
|
|
|
|
// Find any recorded change for this output
|
|
|
|
var change *plans.OutputChangeSrc
|
|
|
|
for _, c := range n.Changes {
|
|
|
|
if c.Addr.String() == absAddr.String() {
|
|
|
|
change = c
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-24 16:42:32 -06:00
|
|
|
o := &NodeApplyableOutput{
|
2020-10-09 10:09:36 -05:00
|
|
|
Addr: absAddr,
|
|
|
|
Config: n.Config,
|
|
|
|
Change: change,
|
|
|
|
}
|
|
|
|
log.Printf("[TRACE] Expanding output: adding %s as %T", o.Addr.String(), o)
|
|
|
|
g.Add(o)
|
|
|
|
}
|
|
|
|
return &g, nil
|
|
|
|
}
|
|
|
|
|
2020-10-09 16:24:10 -05:00
|
|
|
// if we're planing a destroy operation, add a destroy node for any root output
|
|
|
|
func (n *nodeExpandOutput) planDestroyRootOutput(ctx EvalContext) (*Graph, error) {
|
2020-10-09 10:09:36 -05:00
|
|
|
if !n.Module.IsRoot() {
|
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
state := ctx.State()
|
|
|
|
if state == nil {
|
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
var g Graph
|
2020-10-09 16:24:10 -05:00
|
|
|
o := &NodeDestroyableOutput{
|
|
|
|
Addr: n.Addr.Absolute(addrs.RootModuleInstance),
|
|
|
|
Config: n.Config,
|
2020-02-24 16:42:32 -06:00
|
|
|
}
|
2020-10-09 16:24:10 -05:00
|
|
|
log.Printf("[TRACE] Expanding output: adding %s as %T", o.Addr.String(), o)
|
|
|
|
g.Add(o)
|
2020-10-09 10:09:36 -05:00
|
|
|
|
2020-02-24 16:42:32 -06:00
|
|
|
return &g, nil
|
|
|
|
}
|
|
|
|
|
2020-05-12 09:44:45 -05:00
|
|
|
func (n *nodeExpandOutput) Name() string {
|
2020-03-06 17:02:20 -06:00
|
|
|
path := n.Module.String()
|
2020-05-12 09:44:45 -05:00
|
|
|
addr := n.Addr.String() + " (expand)"
|
2020-03-06 17:02:20 -06:00
|
|
|
if path != "" {
|
|
|
|
return path + "." + addr
|
|
|
|
}
|
|
|
|
return addr
|
2020-02-24 16:42:32 -06:00
|
|
|
}
|
|
|
|
|
2020-03-04 20:00:16 -06:00
|
|
|
// GraphNodeModulePath
|
2020-05-12 09:44:45 -05:00
|
|
|
func (n *nodeExpandOutput) ModulePath() addrs.Module {
|
2020-03-04 20:00:16 -06:00
|
|
|
return n.Module
|
|
|
|
}
|
|
|
|
|
2020-02-24 16:42:32 -06:00
|
|
|
// GraphNodeReferenceable
|
2020-05-12 09:44:45 -05:00
|
|
|
func (n *nodeExpandOutput) ReferenceableAddrs() []addrs.Referenceable {
|
2020-02-24 16:42:32 -06:00
|
|
|
// An output in the root module can't be referenced at all.
|
|
|
|
if n.Module.IsRoot() {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// the output is referenced through the module call, and via the
|
|
|
|
// module itself.
|
|
|
|
_, call := n.Module.Call()
|
|
|
|
callOutput := addrs.ModuleCallOutput{
|
2020-03-20 11:18:48 -05:00
|
|
|
Call: call,
|
2020-02-24 16:42:32 -06:00
|
|
|
Name: n.Addr.Name,
|
|
|
|
}
|
|
|
|
|
|
|
|
// Otherwise, we can reference the output via the
|
|
|
|
// module call itself
|
|
|
|
return []addrs.Referenceable{call, callOutput}
|
|
|
|
}
|
|
|
|
|
|
|
|
// GraphNodeReferenceOutside implementation
|
2020-05-12 09:44:45 -05:00
|
|
|
func (n *nodeExpandOutput) ReferenceOutside() (selfPath, referencePath addrs.Module) {
|
2020-02-24 16:42:32 -06:00
|
|
|
// Output values have their expressions resolved in the context of the
|
|
|
|
// module where they are defined.
|
|
|
|
referencePath = n.Module
|
|
|
|
|
|
|
|
// ...but they are referenced in the context of their calling module.
|
|
|
|
selfPath = referencePath.Parent()
|
|
|
|
|
|
|
|
return // uses named return values
|
|
|
|
}
|
|
|
|
|
|
|
|
// GraphNodeReferencer
|
2020-05-12 09:44:45 -05:00
|
|
|
func (n *nodeExpandOutput) References() []*addrs.Reference {
|
2020-10-09 16:24:10 -05:00
|
|
|
// root outputs might be destroyable, and may not reference anything in
|
|
|
|
// that case
|
2020-07-17 17:48:35 -05:00
|
|
|
return referencesForOutput(n.Config)
|
2020-02-24 16:42:32 -06:00
|
|
|
}
|
|
|
|
|
2016-09-16 01:20:35 -05:00
|
|
|
// NodeApplyableOutput represents an output that is "applyable":
|
|
|
|
// it is ready to be applied.
|
|
|
|
type NodeApplyableOutput struct {
|
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
|
|
|
Addr addrs.AbsOutputValue
|
|
|
|
Config *configs.Output // Config is the output in the config
|
2020-10-09 10:09:36 -05:00
|
|
|
// If this is being evaluated during apply, we may have a change recorded already
|
|
|
|
Change *plans.OutputChangeSrc
|
2016-09-16 01:20:35 -05: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
|
|
|
var (
|
2020-03-05 15:13:54 -06:00
|
|
|
_ GraphNodeModuleInstance = (*NodeApplyableOutput)(nil)
|
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
|
|
|
_ GraphNodeReferenceable = (*NodeApplyableOutput)(nil)
|
|
|
|
_ GraphNodeReferencer = (*NodeApplyableOutput)(nil)
|
|
|
|
_ GraphNodeReferenceOutside = (*NodeApplyableOutput)(nil)
|
2020-09-08 13:02:45 -05:00
|
|
|
_ GraphNodeExecutable = (*NodeApplyableOutput)(nil)
|
2020-04-02 12:26:53 -05:00
|
|
|
_ graphNodeTemporaryValue = (*NodeApplyableOutput)(nil)
|
2018-05-02 21:55:53 -05:00
|
|
|
_ dag.GraphNodeDotter = (*NodeApplyableOutput)(nil)
|
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
|
|
|
)
|
2016-09-16 01:20:35 -05:00
|
|
|
|
2020-04-02 12:26:53 -05:00
|
|
|
func (n *NodeApplyableOutput) temporaryValue() bool {
|
|
|
|
// this must always be evaluated if it is a root module output
|
|
|
|
return !n.Addr.Module.IsRoot()
|
|
|
|
}
|
|
|
|
|
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
|
|
|
func (n *NodeApplyableOutput) Name() string {
|
|
|
|
return n.Addr.String()
|
2016-09-16 01:20:35 -05:00
|
|
|
}
|
|
|
|
|
2020-03-05 15:13:54 -06:00
|
|
|
// GraphNodeModuleInstance
|
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
|
|
|
func (n *NodeApplyableOutput) Path() addrs.ModuleInstance {
|
|
|
|
return n.Addr.Module
|
2016-09-16 01:20:35 -05:00
|
|
|
}
|
|
|
|
|
2020-03-04 20:00:16 -06:00
|
|
|
// GraphNodeModulePath
|
|
|
|
func (n *NodeApplyableOutput) ModulePath() addrs.Module {
|
|
|
|
return n.Addr.Module.Module()
|
|
|
|
}
|
|
|
|
|
2020-02-24 16:42:32 -06:00
|
|
|
func referenceOutsideForOutput(addr addrs.AbsOutputValue) (selfPath, referencePath addrs.Module) {
|
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
|
|
|
// Output values have their expressions resolved in the context of the
|
|
|
|
// module where they are defined.
|
2020-02-24 16:42:32 -06:00
|
|
|
referencePath = addr.Module.Module()
|
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
|
|
|
|
|
|
|
// ...but they are referenced in the context of their calling module.
|
2020-02-24 16:42:32 -06:00
|
|
|
selfPath = addr.Module.Parent().Module()
|
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
|
|
|
|
|
|
|
return // uses named return values
|
|
|
|
}
|
|
|
|
|
|
|
|
// GraphNodeReferenceOutside implementation
|
2020-02-24 16:42:32 -06:00
|
|
|
func (n *NodeApplyableOutput) ReferenceOutside() (selfPath, referencePath addrs.Module) {
|
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
|
|
|
return referenceOutsideForOutput(n.Addr)
|
|
|
|
}
|
|
|
|
|
|
|
|
func referenceableAddrsForOutput(addr addrs.AbsOutputValue) []addrs.Referenceable {
|
|
|
|
// An output in the root module can't be referenced at all.
|
|
|
|
if addr.Module.IsRoot() {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// Otherwise, we can be referenced via a reference to our output name
|
|
|
|
// on the parent module's call, or via a reference to the entire call.
|
|
|
|
// e.g. module.foo.bar or just module.foo .
|
|
|
|
// Note that our ReferenceOutside method causes these addresses to be
|
|
|
|
// relative to the calling module, not the module where the output
|
|
|
|
// was declared.
|
|
|
|
_, outp := addr.ModuleCallOutput()
|
|
|
|
_, call := addr.Module.CallInstance()
|
|
|
|
|
2020-02-24 16:42:32 -06:00
|
|
|
return []addrs.Referenceable{outp, call}
|
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
|
|
|
}
|
|
|
|
|
2016-09-16 01:20:35 -05:00
|
|
|
// GraphNodeReferenceable
|
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
|
|
|
func (n *NodeApplyableOutput) ReferenceableAddrs() []addrs.Referenceable {
|
|
|
|
return referenceableAddrsForOutput(n.Addr)
|
2016-09-16 01:20:35 -05: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
|
|
|
func referencesForOutput(c *configs.Output) []*addrs.Reference {
|
|
|
|
impRefs, _ := lang.ReferencesInExpr(c.Expr)
|
|
|
|
expRefs, _ := lang.References(c.DependsOn)
|
|
|
|
l := len(impRefs) + len(expRefs)
|
|
|
|
if l == 0 {
|
|
|
|
return nil
|
2016-10-12 20:43:26 -05: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
|
|
|
refs := make([]*addrs.Reference, 0, l)
|
|
|
|
refs = append(refs, impRefs...)
|
|
|
|
refs = append(refs, expRefs...)
|
|
|
|
return refs
|
2016-10-12 20:43:26 -05: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
|
|
|
}
|
|
|
|
|
|
|
|
// GraphNodeReferencer
|
|
|
|
func (n *NodeApplyableOutput) References() []*addrs.Reference {
|
2020-07-17 17:48:35 -05:00
|
|
|
return referencesForOutput(n.Config)
|
2016-09-16 01:20:35 -05:00
|
|
|
}
|
|
|
|
|
2020-09-08 13:02:45 -05:00
|
|
|
// GraphNodeExecutable
|
|
|
|
func (n *NodeApplyableOutput) Execute(ctx EvalContext, op walkOperation) error {
|
2020-10-09 10:09:36 -05:00
|
|
|
var diags tfdiags.Diagnostics
|
2020-10-06 16:14:53 -05:00
|
|
|
state := ctx.State()
|
|
|
|
if state == nil {
|
|
|
|
return nil
|
|
|
|
}
|
2020-09-21 08:36:50 -05:00
|
|
|
|
2020-10-06 16:14:53 -05:00
|
|
|
changes := ctx.Changes() // may be nil, if we're not working on a changeset
|
|
|
|
|
2020-10-09 10:09:36 -05:00
|
|
|
val := cty.UnknownVal(cty.DynamicPseudoType)
|
|
|
|
changeRecorded := n.Change != nil
|
|
|
|
// we we have a change recorded, we don't need to re-evaluate if the value
|
|
|
|
// was known
|
|
|
|
if changeRecorded {
|
|
|
|
var err error
|
|
|
|
val, err = n.Change.After.Decode(cty.DynamicPseudoType)
|
|
|
|
diags = diags.Append(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// If there was no change recorded, or the recorded change was not wholly
|
|
|
|
// known, then we need to re-evaluate the output
|
|
|
|
if !changeRecorded || !val.IsWhollyKnown() {
|
|
|
|
// This has to run before we have a state lock, since evaluation also
|
|
|
|
// reads the state
|
|
|
|
val, diags = ctx.EvaluateExpr(n.Config.Expr, cty.DynamicPseudoType, nil)
|
|
|
|
// We'll handle errors below, after we have loaded the module.
|
|
|
|
// Outputs don't have a separate mode for validation, so validate
|
|
|
|
// depends_on expressions here too
|
|
|
|
diags = diags.Append(validateDependsOn(ctx, n.Config.DependsOn))
|
|
|
|
|
|
|
|
// Ensure that non-sensitive outputs don't include sensitive values
|
|
|
|
_, marks := val.UnmarkDeep()
|
|
|
|
_, hasSensitive := marks["sensitive"]
|
|
|
|
if !n.Config.Sensitive && hasSensitive {
|
|
|
|
diags = diags.Append(&hcl.Diagnostic{
|
|
|
|
Severity: hcl.DiagError,
|
|
|
|
Summary: "Output refers to sensitive values",
|
|
|
|
Detail: "Expressions used in outputs can only refer to sensitive values if the sensitive attribute is true.",
|
|
|
|
Subject: n.Config.DeclRange.Ptr(),
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-06 16:14:53 -05:00
|
|
|
// handling the interpolation error
|
|
|
|
if diags.HasErrors() {
|
|
|
|
if flagWarnOutputErrors {
|
|
|
|
log.Printf("[ERROR] Output interpolation %q failed: %s", n.Addr, diags.Err())
|
|
|
|
// if we're continuing, make sure the output is included, and
|
|
|
|
// marked as unknown. If the evaluator was able to find a type
|
|
|
|
// for the value in spite of the error then we'll use it.
|
|
|
|
n.setValue(state, changes, cty.UnknownVal(val.Type()))
|
|
|
|
return EvalEarlyExitError{}
|
2020-09-21 08:36:50 -05:00
|
|
|
}
|
2020-10-06 16:14:53 -05:00
|
|
|
return diags.Err()
|
|
|
|
}
|
|
|
|
n.setValue(state, changes, val)
|
2020-09-21 08:36:50 -05:00
|
|
|
|
2020-10-06 16:14:53 -05:00
|
|
|
// If we were able to evaluate a new value, we can update that in the
|
|
|
|
// refreshed state as well.
|
|
|
|
if state = ctx.RefreshState(); state != nil && val.IsWhollyKnown() {
|
|
|
|
n.setValue(state, changes, val)
|
2016-09-16 01:20:35 -05:00
|
|
|
}
|
2020-10-06 16:14:53 -05:00
|
|
|
|
|
|
|
return nil
|
2016-09-16 01:20:35 -05:00
|
|
|
}
|
2018-01-29 18:17:31 -06:00
|
|
|
|
2018-05-02 21:55:53 -05:00
|
|
|
// dag.GraphNodeDotter impl.
|
|
|
|
func (n *NodeApplyableOutput) DotNode(name string, opts *dag.DotOpts) *dag.DotNode {
|
|
|
|
return &dag.DotNode{
|
|
|
|
Name: name,
|
|
|
|
Attrs: map[string]string{
|
|
|
|
"label": n.Name(),
|
|
|
|
"shape": "note",
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-09 10:09:36 -05:00
|
|
|
// NodeDestroyableOutput represents an output that is "destroyable":
|
2018-01-29 18:17:31 -06:00
|
|
|
// its application will remove the output from the state.
|
|
|
|
type NodeDestroyableOutput struct {
|
2020-03-20 14:19:01 -05:00
|
|
|
Addr addrs.AbsOutputValue
|
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
|
|
|
Config *configs.Output // Config is the output in the config
|
2018-01-29 18:17:31 -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
|
|
|
var (
|
2020-09-08 13:02:45 -05:00
|
|
|
_ GraphNodeExecutable = (*NodeDestroyableOutput)(nil)
|
2020-06-24 09:45:58 -05:00
|
|
|
_ dag.GraphNodeDotter = (*NodeDestroyableOutput)(nil)
|
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-01-29 18:17:31 -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
|
|
|
func (n *NodeDestroyableOutput) Name() string {
|
|
|
|
return fmt.Sprintf("%s (destroy)", n.Addr.String())
|
2018-01-29 18:17:31 -06:00
|
|
|
}
|
|
|
|
|
2020-03-04 20:00:16 -06:00
|
|
|
// GraphNodeModulePath
|
|
|
|
func (n *NodeDestroyableOutput) ModulePath() addrs.Module {
|
2020-03-20 14:19:01 -05:00
|
|
|
return n.Addr.Module.Module()
|
2020-03-04 20:00:16 -06:00
|
|
|
}
|
|
|
|
|
2020-06-24 09:22:10 -05:00
|
|
|
func (n *NodeDestroyableOutput) temporaryValue() bool {
|
|
|
|
// this must always be evaluated if it is a root module output
|
|
|
|
return !n.Addr.Module.IsRoot()
|
|
|
|
}
|
|
|
|
|
2020-09-08 13:02:45 -05:00
|
|
|
// GraphNodeExecutable
|
|
|
|
func (n *NodeDestroyableOutput) Execute(ctx EvalContext, op walkOperation) error {
|
|
|
|
state := ctx.State()
|
|
|
|
if state == nil {
|
|
|
|
return nil
|
2018-01-29 18:17:31 -06:00
|
|
|
}
|
2020-10-09 10:09:36 -05:00
|
|
|
|
|
|
|
changes := ctx.Changes()
|
|
|
|
if changes != nil {
|
|
|
|
change := &plans.OutputChange{
|
|
|
|
Addr: n.Addr,
|
|
|
|
Change: plans.Change{
|
|
|
|
// FIXME: Generate real planned changes for output values
|
|
|
|
// that include the old values.
|
|
|
|
Action: plans.Delete,
|
|
|
|
Before: cty.NullVal(cty.DynamicPseudoType),
|
|
|
|
After: cty.NullVal(cty.DynamicPseudoType),
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
cs, err := change.Encode()
|
|
|
|
if err != nil {
|
|
|
|
// Should never happen, since we just constructed this right above
|
|
|
|
panic(fmt.Sprintf("planned change for %s could not be encoded: %s", n.Addr, err))
|
|
|
|
}
|
2020-10-09 16:24:10 -05:00
|
|
|
log.Printf("[TRACE] NodeDestroyableOutput: Saving %s change for %s in changeset", change.Action, n.Addr)
|
2020-10-09 10:09:36 -05:00
|
|
|
changes.RemoveOutputChange(n.Addr) // remove any existing planned change, if present
|
|
|
|
changes.AppendOutputChange(cs) // add the new planned change
|
|
|
|
}
|
|
|
|
|
2020-09-08 13:02:45 -05:00
|
|
|
state.RemoveOutputValue(n.Addr)
|
|
|
|
return nil
|
2018-01-29 18:17:31 -06:00
|
|
|
}
|
2018-05-02 21:55:53 -05:00
|
|
|
|
|
|
|
// dag.GraphNodeDotter impl.
|
|
|
|
func (n *NodeDestroyableOutput) DotNode(name string, opts *dag.DotOpts) *dag.DotNode {
|
|
|
|
return &dag.DotNode{
|
|
|
|
Name: name,
|
|
|
|
Attrs: map[string]string{
|
|
|
|
"label": n.Name(),
|
|
|
|
"shape": "note",
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
2020-09-08 13:02:45 -05:00
|
|
|
|
|
|
|
func (n *NodeApplyableOutput) setValue(state *states.SyncState, changes *plans.ChangesSync, val cty.Value) {
|
|
|
|
if val.IsKnown() && !val.IsNull() {
|
|
|
|
// The state itself doesn't represent unknown values, so we null them
|
|
|
|
// out here and then we'll save the real unknown value in the planned
|
|
|
|
// changeset below, if we have one on this graph walk.
|
|
|
|
log.Printf("[TRACE] EvalWriteOutput: Saving value for %s in state", n.Addr)
|
2020-09-25 14:10:32 -05:00
|
|
|
unmarkedVal, _ := val.UnmarkDeep()
|
|
|
|
stateVal := cty.UnknownAsNull(unmarkedVal)
|
2020-09-08 13:02:45 -05:00
|
|
|
state.SetOutputValue(n.Addr, stateVal, n.Config.Sensitive)
|
|
|
|
} else {
|
|
|
|
log.Printf("[TRACE] EvalWriteOutput: Removing %s from state (it is now null)", n.Addr)
|
|
|
|
state.RemoveOutputValue(n.Addr)
|
|
|
|
}
|
|
|
|
|
|
|
|
// If we also have an active changeset then we'll replicate the value in
|
|
|
|
// there. This is used in preference to the state where present, since it
|
|
|
|
// *is* able to represent unknowns, while the state cannot.
|
|
|
|
if changes != nil {
|
|
|
|
// For the moment we are not properly tracking changes to output
|
|
|
|
// values, and just marking them always as "Create" or "Destroy"
|
|
|
|
// actions. A future release will rework the output lifecycle so we
|
|
|
|
// can track their changes properly, in a similar way to how we work
|
|
|
|
// with resource instances.
|
|
|
|
|
|
|
|
var change *plans.OutputChange
|
|
|
|
if !val.IsNull() {
|
|
|
|
change = &plans.OutputChange{
|
|
|
|
Addr: n.Addr,
|
|
|
|
Sensitive: n.Config.Sensitive,
|
|
|
|
Change: plans.Change{
|
|
|
|
Action: plans.Create,
|
|
|
|
Before: cty.NullVal(cty.DynamicPseudoType),
|
|
|
|
After: val,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
change = &plans.OutputChange{
|
|
|
|
Addr: n.Addr,
|
|
|
|
Sensitive: n.Config.Sensitive,
|
|
|
|
Change: plans.Change{
|
|
|
|
// This is just a weird placeholder delete action since
|
|
|
|
// we don't have an actual prior value to indicate.
|
|
|
|
// FIXME: Generate real planned changes for output values
|
|
|
|
// that include the old values.
|
|
|
|
Action: plans.Delete,
|
|
|
|
Before: cty.NullVal(cty.DynamicPseudoType),
|
|
|
|
After: cty.NullVal(cty.DynamicPseudoType),
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
cs, err := change.Encode()
|
|
|
|
if err != nil {
|
|
|
|
// Should never happen, since we just constructed this right above
|
|
|
|
panic(fmt.Sprintf("planned change for %s could not be encoded: %s", n.Addr, err))
|
|
|
|
}
|
|
|
|
log.Printf("[TRACE] ExecuteWriteOutput: Saving %s change for %s in changeset", change.Action, n.Addr)
|
|
|
|
changes.RemoveOutputChange(n.Addr) // remove any existing planned change, if present
|
|
|
|
changes.AppendOutputChange(cs) // add the new planned change
|
|
|
|
}
|
|
|
|
}
|