2024-02-08 03:48:59 -06:00
// Copyright (c) The OpenTofu Authors
// SPDX-License-Identifier: MPL-2.0
// Copyright (c) 2023 HashiCorp, Inc.
2023-05-02 10:33:06 -05:00
// SPDX-License-Identifier: MPL-2.0
2023-09-20 07:16:53 -05:00
package tofu
2016-09-21 16:30:41 -05:00
import (
2016-11-08 11:35:57 -06:00
"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
"log"
2016-11-08 11:35:57 -06:00
2024-04-15 05:06:35 -05:00
"github.com/hashicorp/hcl/v2"
"github.com/hashicorp/hcl/v2/hclsyntax"
2023-09-20 06:35:35 -05:00
"github.com/opentofu/opentofu/internal/addrs"
"github.com/opentofu/opentofu/internal/configs"
"github.com/opentofu/opentofu/internal/configs/configschema"
"github.com/opentofu/opentofu/internal/dag"
"github.com/opentofu/opentofu/internal/lang"
"github.com/opentofu/opentofu/internal/states"
"github.com/opentofu/opentofu/internal/tfdiags"
2016-09-21 16:30:41 -05:00
)
// ConcreteResourceNodeFunc is a callback type used to convert an
// abstract resource to a concrete one of some type.
type ConcreteResourceNodeFunc func ( * NodeAbstractResource ) dag . Vertex
2020-03-15 10:32:06 -05:00
// GraphNodeConfigResource is implemented by any nodes that represent a resource.
2016-09-21 18:37:41 -05:00
// The type of operation cannot be assumed, only that this node represents
// the given resource.
2020-03-15 10:32:06 -05:00
type GraphNodeConfigResource interface {
ResourceAddr ( ) addrs . ConfigResource
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
}
// ConcreteResourceInstanceNodeFunc is a callback type used to convert an
// abstract resource instance to a concrete one of some type.
type ConcreteResourceInstanceNodeFunc func ( * NodeAbstractResourceInstance ) dag . Vertex
// GraphNodeResourceInstance is implemented by any nodes that represent
// a resource instance. A single resource may have multiple instances if,
// for example, the "count" or "for_each" argument is used for it in
// configuration.
type GraphNodeResourceInstance interface {
ResourceInstanceAddr ( ) addrs . AbsResourceInstance
2019-10-30 14:59:34 -05:00
// StateDependencies returns any inter-resource dependencies that are
// stored in the state.
2020-03-23 14:26:18 -05:00
StateDependencies ( ) [ ] addrs . ConfigResource
2016-09-21 18:37:41 -05:00
}
2016-09-21 16:30:41 -05:00
// NodeAbstractResource represents a resource that has no associated
// operations. It registers all the interfaces for a resource that common
// across multiple operation types.
type NodeAbstractResource struct {
2020-03-12 13:47:28 -05:00
Addr addrs . ConfigResource
2016-09-21 16:30:41 -05:00
// The fields below will be automatically set using the Attach
// interfaces if you're running those transforms, but also be explicitly
// set if you already have that information.
2018-11-27 17:30:18 -06:00
Schema * configschema . Block // Schema for processing the configuration body
SchemaVersion uint64 // Schema version of "Schema", as decided by the provider
Config * configs . Resource // Config is the resource in the config
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
2020-03-05 18:53:24 -06:00
// ProviderMetas is the provider_meta configs for the module this resource belongs to
ProviderMetas map [ addrs . Provider ] * configs . ProviderMeta
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
ProvisionerSchemas map [ string ] * configschema . Block
2016-10-20 20:59:02 -05:00
2020-05-01 09:22:50 -05:00
// Set from GraphNodeTargetable
Targets [ ] addrs . Targetable
2024-11-05 09:16:00 -06:00
// Set from GraphNodeTargetable
Excludes [ ] addrs . Targetable
2021-03-08 12:46:28 -06:00
// Set from AttachDataResourceDependsOn
2020-06-04 11:39:36 -05:00
dependsOn [ ] addrs . ConfigResource
forceDependsOn bool
2017-11-01 17:34:18 -05:00
// The address of the provider this resource will use
2024-11-05 17:08:23 -06:00
ResolvedProvider ResolvedProvider
2022-11-21 09:38:25 -06:00
// storedProviderConfig is the provider address retrieved from the
// state. This is defined here for access within the ProvidedBy method, but
// will be set from the embedding instance type when the state is attached.
2024-11-05 17:08:23 -06:00
storedProviderConfig ResolvedProvider
2022-06-06 13:46:59 -05:00
// This resource may expand into instances which need to be imported.
importTargets [ ] * ImportTarget
2023-05-12 17:05:00 -05:00
2023-05-24 06:58:26 -05:00
// generateConfigPath tells this node which file to write generated config
// into. If empty, then config should not be generated.
generateConfigPath string
2016-09-21 16:30:41 -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 (
2021-03-08 12:46:28 -06:00
_ GraphNodeReferenceable = ( * NodeAbstractResource ) ( nil )
_ GraphNodeReferencer = ( * NodeAbstractResource ) ( nil )
_ GraphNodeProviderConsumer = ( * NodeAbstractResource ) ( nil )
_ GraphNodeProvisionerConsumer = ( * NodeAbstractResource ) ( nil )
_ GraphNodeConfigResource = ( * NodeAbstractResource ) ( nil )
_ GraphNodeAttachResourceConfig = ( * NodeAbstractResource ) ( nil )
_ GraphNodeAttachResourceSchema = ( * NodeAbstractResource ) ( nil )
_ GraphNodeAttachProvisionerSchema = ( * NodeAbstractResource ) ( nil )
_ GraphNodeAttachProviderMetaConfigs = ( * NodeAbstractResource ) ( nil )
_ GraphNodeTargetable = ( * NodeAbstractResource ) ( nil )
_ graphNodeAttachDataResourceDependsOn = ( * NodeAbstractResource ) ( nil )
_ dag . GraphNodeDotter = ( * NodeAbstractResource ) ( 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
)
// NewNodeAbstractResource creates an abstract resource graph node for
// the given absolute resource address.
2020-03-20 16:07:46 -05:00
func NewNodeAbstractResource ( addr addrs . ConfigResource ) * NodeAbstractResource {
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 & NodeAbstractResource {
2020-03-20 16:07:46 -05:00
Addr : addr ,
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-21 16:30:41 -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 = ( * NodeAbstractResourceInstance ) ( nil )
2020-03-05 18:53:24 -06:00
_ GraphNodeReferenceable = ( * NodeAbstractResourceInstance ) ( nil )
_ GraphNodeReferencer = ( * NodeAbstractResourceInstance ) ( nil )
2024-01-12 06:23:25 -06:00
_ GraphNodeRootReferencer = ( * NodeAbstractResourceInstance ) ( nil )
2020-03-05 18:53:24 -06:00
_ GraphNodeProviderConsumer = ( * NodeAbstractResourceInstance ) ( nil )
_ GraphNodeProvisionerConsumer = ( * NodeAbstractResourceInstance ) ( nil )
2020-03-15 10:32:06 -05:00
_ GraphNodeConfigResource = ( * NodeAbstractResourceInstance ) ( nil )
2020-03-05 18:53:24 -06:00
_ GraphNodeResourceInstance = ( * NodeAbstractResourceInstance ) ( nil )
_ GraphNodeAttachResourceState = ( * NodeAbstractResourceInstance ) ( nil )
_ GraphNodeAttachResourceConfig = ( * NodeAbstractResourceInstance ) ( nil )
_ GraphNodeAttachResourceSchema = ( * NodeAbstractResourceInstance ) ( nil )
_ GraphNodeAttachProvisionerSchema = ( * NodeAbstractResourceInstance ) ( nil )
_ GraphNodeAttachProviderMetaConfigs = ( * NodeAbstractResourceInstance ) ( nil )
_ GraphNodeTargetable = ( * NodeAbstractResourceInstance ) ( nil )
_ dag . GraphNodeDotter = ( * NodeAbstractResourceInstance ) ( 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
)
func ( n * NodeAbstractResource ) Name ( ) string {
return n . ResourceAddr ( ) . String ( )
}
2016-11-08 11:35:57 -06:00
2020-03-04 20:00:16 -06:00
// GraphNodeModulePath
func ( n * NodeAbstractResource ) ModulePath ( ) addrs . Module {
2020-03-12 13:47:28 -05:00
return n . Addr . Module
2020-03-04 20:00:16 -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
// GraphNodeReferenceable
func ( n * NodeAbstractResource ) ReferenceableAddrs ( ) [ ] addrs . Referenceable {
2020-03-12 13:47:28 -05:00
return [ ] addrs . Referenceable { n . Addr . Resource }
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-11-08 11:35:57 -06:00
2016-09-21 16:30:41 -05:00
// GraphNodeReferencer
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 * NodeAbstractResource ) References ( ) [ ] * addrs . Reference {
2023-08-02 04:20:27 -05:00
var result [ ] * addrs . Reference
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 we have a config then we prefer to use that.
2016-09-21 16:30:41 -05:00
if c := n . Config ; c != nil {
2020-05-01 09:22:50 -05:00
result = append ( result , n . DependsOn ( ) ... )
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-05-02 22:16:22 -05:00
if n . Schema == nil {
2020-06-02 08:01:12 -05:00
// Should never happen, but we'll log if it does so that we can
2018-05-02 22:16:22 -05:00
// see this easily when debugging.
2018-12-07 17:38:11 -06:00
log . Printf ( "[WARN] no schema is attached to %s, so config references cannot be detected" , n . Name ( ) )
2018-05-02 22:16:22 -05:00
}
2023-06-28 02:47:24 -05:00
refs , _ := lang . ReferencesInExpr ( addrs . ParseRef , c . Count )
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
result = append ( result , refs ... )
2023-06-28 02:47:24 -05:00
refs , _ = lang . ReferencesInExpr ( addrs . ParseRef , c . ForEach )
2019-06-12 10:07:32 -05:00
result = append ( result , refs ... )
2020-06-02 08:01:12 -05:00
2022-04-12 14:57:16 -05:00
for _ , expr := range c . TriggersReplacement {
2023-06-28 02:47:24 -05:00
refs , _ = lang . ReferencesInExpr ( addrs . ParseRef , expr )
2022-04-12 14:57:16 -05:00
result = append ( result , refs ... )
}
2020-06-02 08:01:12 -05:00
// ReferencesInBlock() requires a schema
if n . Schema != nil {
2023-06-28 02:47:24 -05:00
refs , _ = lang . ReferencesInBlock ( addrs . ParseRef , c . Config , n . Schema )
2022-04-12 14:57:16 -05:00
result = append ( result , refs ... )
2020-06-02 08:01:12 -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
if c . Managed != nil {
2019-12-12 11:47:08 -06:00
if c . Managed . Connection != nil {
2023-06-28 02:47:24 -05:00
refs , _ = lang . ReferencesInBlock ( addrs . ParseRef , c . Managed . Connection . Config , connectionBlockSupersetSchema )
2019-12-12 11:47:08 -06:00
result = append ( result , refs ... )
}
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
for _ , p := range c . Managed . Provisioners {
if p . When != configs . ProvisionerWhenCreate {
continue
}
2018-05-04 21:56:40 -05:00
if p . Connection != nil {
2023-06-28 02:47:24 -05:00
refs , _ = lang . ReferencesInBlock ( addrs . ParseRef , p . Connection . Config , connectionBlockSupersetSchema )
2018-05-04 21:56:40 -05:00
result = append ( result , refs ... )
}
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 := n . ProvisionerSchemas [ p . Type ]
2018-05-24 18:00:26 -05:00
if schema == nil {
log . Printf ( "[WARN] no schema for provisioner %q is attached to %s, so provisioner block references cannot be detected" , p . Type , n . Name ( ) )
}
2023-06-28 02:47:24 -05:00
refs , _ = lang . ReferencesInBlock ( addrs . ParseRef , p . Config , schema )
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
result = append ( result , refs ... )
2017-02-17 16:29:22 -06:00
}
2016-09-21 16:30:41 -05:00
}
2020-11-20 17:10:08 -06:00
for _ , check := range c . Preconditions {
2023-06-28 02:47:24 -05:00
refs , _ := lang . ReferencesInExpr ( addrs . ParseRef , check . Condition )
2020-11-20 17:10:08 -06:00
result = append ( result , refs ... )
2023-06-28 02:47:24 -05:00
refs , _ = lang . ReferencesInExpr ( addrs . ParseRef , check . ErrorMessage )
core: Check rule error message expressions
Error messages for preconditions, postconditions, and custom variable
validations have until now been string literals. This commit changes
this to treat the field as an HCL expression, which must evaluate to a
string. Most commonly this will either be a string literal or a template
expression.
When the check rule condition is evaluated, we also evaluate the error
message. This means that the error message should always evaluate to a
string value, even if the condition passes. If it does not, this will
result in an error diagnostic.
If the condition fails, and the error message also fails to evaluate, we
fall back to a default error message. This means that the check rule
failure will still be reported, alongside diagnostics explaining why the
custom error message failed to render.
As part of this change, we also necessarily remove the heuristic about
the error message format. This guidance can be readded in future as part
of a configuration hint system.
2022-02-03 13:14:21 -06:00
result = append ( result , refs ... )
2020-11-20 17:10:08 -06:00
}
for _ , check := range c . Postconditions {
2023-06-28 02:47:24 -05:00
refs , _ := lang . ReferencesInExpr ( addrs . ParseRef , check . Condition )
2020-11-20 17:10:08 -06:00
result = append ( result , refs ... )
2023-06-28 02:47:24 -05:00
refs , _ = lang . ReferencesInExpr ( addrs . ParseRef , check . ErrorMessage )
core: Check rule error message expressions
Error messages for preconditions, postconditions, and custom variable
validations have until now been string literals. This commit changes
this to treat the field as an HCL expression, which must evaluate to a
string. Most commonly this will either be a string literal or a template
expression.
When the check rule condition is evaluated, we also evaluate the error
message. This means that the error message should always evaluate to a
string value, even if the condition passes. If it does not, this will
result in an error diagnostic.
If the condition fails, and the error message also fails to evaluate, we
fall back to a default error message. This means that the check rule
failure will still be reported, alongside diagnostics explaining why the
custom error message failed to render.
As part of this change, we also necessarily remove the heuristic about
the error message format. This guidance can be readded in future as part
of a configuration hint system.
2022-02-03 13:14:21 -06:00
result = append ( result , refs ... )
2020-11-20 17:10:08 -06:00
}
2023-08-02 04:20:27 -05:00
}
2020-11-20 17:10:08 -06:00
2024-01-12 06:23:25 -06:00
return result
}
2024-04-15 05:06:35 -05:00
// referencesInImportAddress find all references relevant to the node in an import target address expression.
// The only references we care about here are the references that exist in the keys of hclsyntax.IndexExpr.
// For example, if the address is module.my_module1[expression1].aws_s3_bucket.bucket[expression2], then we would only
// consider references in expression1 and expression2, as the rest of the expression is the static part of the current
// resource's address
func referencesInImportAddress ( expr hcl . Expression ) ( refs [ ] * addrs . Reference , diags tfdiags . Diagnostics ) {
switch e := expr . ( type ) {
case * hclsyntax . IndexExpr :
r , d := referencesInImportAddress ( e . Collection )
diags = diags . Append ( d )
refs = append ( refs , r ... )
r , _ = lang . ReferencesInExpr ( addrs . ParseRef , e . Key )
refs = append ( refs , r ... )
case * hclsyntax . RelativeTraversalExpr :
r , d := referencesInImportAddress ( e . Source )
refs = append ( refs , r ... )
diags = diags . Append ( d )
// We don't care about the traversal part of the relative expression
// as it should not contain any references in the index keys
case * hclsyntax . ScopeTraversalExpr :
// Static traversals should not contain any references in the index keys
default :
// This should not happen, as it should have failed validation earlier, in config.absTraversalForImportToExpr
diags = diags . Append ( & hcl . Diagnostic {
Severity : hcl . DiagError ,
Summary : "Invalid import address expression" ,
Detail : "Import address must be a reference to a resource's address, and only allows for indexing with dynamic keys. For example: module.my_module[expression1].aws_s3_bucket.my_buckets[expression2] for resources inside of modules, or simply aws_s3_bucket.my_bucket for a resource in the root module" ,
Subject : expr . Range ( ) . Ptr ( ) ,
} )
}
return
}
2024-01-12 06:23:25 -06:00
func ( n * NodeAbstractResource ) RootReferences ( ) [ ] * addrs . Reference {
var root [ ] * addrs . Reference
2023-08-02 04:20:27 -05:00
for _ , importTarget := range n . importTargets {
2024-02-08 08:05:12 -06:00
// References are only possible in import targets originating from an import block
if ! importTarget . IsFromImportBlock ( ) {
continue
}
2024-04-15 05:06:35 -05:00
refs , _ := referencesInImportAddress ( importTarget . Config . To )
2024-04-17 09:12:10 -05:00
root = append ( root , refs ... )
2024-04-15 05:06:35 -05:00
2024-04-17 09:12:10 -05:00
refs , _ = lang . ReferencesInExpr ( addrs . ParseRef , importTarget . Config . ForEach )
2024-04-15 05:06:35 -05:00
root = append ( root , refs ... )
refs , _ = lang . ReferencesInExpr ( addrs . ParseRef , importTarget . Config . ID )
2024-01-12 06:23:25 -06:00
root = append ( root , refs ... )
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-21 16:30:41 -05:00
2024-01-12 06:23:25 -06:00
return root
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
}
2020-05-01 09:22:50 -05:00
func ( n * NodeAbstractResource ) DependsOn ( ) [ ] * addrs . Reference {
var result [ ] * addrs . Reference
if c := n . Config ; c != nil {
for _ , traversal := range c . DependsOn {
ref , diags := addrs . ParseRef ( traversal )
if diags . HasErrors ( ) {
// We ignore this here, because this isn't a suitable place to return
// errors. This situation should be caught and rejected during
// validation.
log . Printf ( "[ERROR] Can't parse %#v from depends_on as reference: %s" , traversal , diags . Err ( ) )
continue
}
result = append ( result , ref )
}
}
return result
}
2024-11-05 17:08:23 -06:00
// GraphNodeProviderConsumer
func ( n * NodeAbstractResource ) SetProvider ( resolved ResolvedProvider ) {
n . ResolvedProvider = resolved
2017-11-01 17:34:18 -05:00
}
2016-09-21 16:30:41 -05:00
// GraphNodeProviderConsumer
2024-11-05 17:08:23 -06:00
func ( n * NodeAbstractResource ) ProvidedBy ( ) RequestedProvider {
2022-11-21 09:38:25 -06:00
// Once the provider is fully resolved, we can return the known value.
2024-11-05 17:08:23 -06:00
if n . ResolvedProvider . ProviderConfig . Provider . Type != "" {
return RequestedProvider {
ProviderConfig : n . ResolvedProvider . ProviderConfig ,
KeyExpression : n . ResolvedProvider . KeyExpression ,
KeyModule : n . ResolvedProvider . KeyModule ,
KeyResource : n . ResolvedProvider . KeyResource ,
KeyExact : n . ResolvedProvider . KeyExact ,
}
2022-11-21 09:38:25 -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 we have a config we prefer that above all else
if n . Config != nil {
2024-11-05 17:08:23 -06:00
result := RequestedProvider {
ProviderConfig : n . Config . ProviderConfigAddr ( ) ,
}
if n . Config . ProviderConfigRef != nil && n . Config . ProviderConfigRef . KeyExpression != nil {
result . KeyResource = true
result . KeyExpression = n . Config . ProviderConfigRef . KeyExpression
}
return result
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
}
2022-11-21 09:38:25 -06:00
// See if we have a valid provider config from the state.
2024-11-05 17:08:23 -06:00
if n . storedProviderConfig . ProviderConfig . Provider . Type != "" {
2022-11-21 09:38:25 -06:00
// An address from the state must match exactly, since we must ensure
// we refresh/destroy a resource with the same provider configuration
// that created it.
2024-11-05 17:08:23 -06:00
return RequestedProvider {
ProviderConfig : n . storedProviderConfig . ProviderConfig ,
KeyExpression : n . storedProviderConfig . KeyExpression ,
KeyModule : n . storedProviderConfig . KeyModule ,
KeyResource : n . storedProviderConfig . KeyResource ,
KeyExact : n . storedProviderConfig . KeyExact ,
}
2022-11-21 09:38:25 -06:00
}
2023-05-11 02:04:39 -05:00
// We might have an import target that is providing a specific provider,
// this is okay as we know there is nothing else potentially providing a
// provider configuration.
if len ( n . importTargets ) > 0 {
// The import targets should either all be defined via config or none
// of them should be. They should also all have the same provider, so it
// shouldn't matter which we check here, as they'll all give the same.
if n . importTargets [ 0 ] . Config != nil && n . importTargets [ 0 ] . Config . ProviderConfigRef != nil {
2024-11-05 17:08:23 -06:00
return RequestedProvider {
ProviderConfig : addrs . LocalProviderConfig {
LocalName : n . importTargets [ 0 ] . Config . ProviderConfigRef . Name ,
Alias : n . importTargets [ 0 ] . Config . ProviderConfigRef . Alias ,
} ,
// This is where we would specify a key expression if that was supported for import blocks
2024-10-16 07:44:40 -05:00
}
2023-05-11 02:04:39 -05:00
}
}
2020-03-18 07:58:20 -05:00
// No provider configuration found; return a default address
2024-11-05 17:08:23 -06:00
return RequestedProvider {
ProviderConfig : addrs . LocalProviderConfig {
LocalName : n . Addr . Resource . ImpliedProvider ( ) , // Unused, see ProviderTransformer
} ,
2024-10-16 07:44:40 -05:00
}
2020-03-10 13:43:57 -05:00
}
// GraphNodeProviderConsumer
2020-03-18 07:58:20 -05:00
func ( n * NodeAbstractResource ) Provider ( ) addrs . Provider {
2024-11-05 17:08:23 -06:00
if n . ResolvedProvider . ProviderConfig . Provider . Type != "" {
return n . ResolvedProvider . ProviderConfig . Provider
2024-10-16 07:44:40 -05:00
}
2020-03-18 07:58:20 -05:00
if n . Config != nil {
return n . Config . Provider
}
2024-11-05 17:08:23 -06:00
if n . storedProviderConfig . ProviderConfig . Provider . Type != "" {
return n . storedProviderConfig . ProviderConfig . Provider
2022-11-21 09:38:25 -06:00
}
2023-05-11 02:04:39 -05:00
if len ( n . importTargets ) > 0 {
// The import targets should either all be defined via config or none
// of them should be. They should also all have the same provider, so it
// shouldn't matter which we check here, as they'll all give the same.
if n . importTargets [ 0 ] . Config != nil {
return n . importTargets [ 0 ] . Config . Provider
}
}
2020-04-01 18:11:15 -05:00
return addrs . ImpliedProviderForUnqualifiedType ( n . Addr . Resource . ImpliedProvider ( ) )
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-21 16:30:41 -05:00
// GraphNodeProvisionerConsumer
func ( n * NodeAbstractResource ) ProvisionedBy ( ) [ ] string {
// If we have no configuration, then we have no provisioners
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 . Config == nil || n . Config . Managed == nil {
2016-09-21 16:30:41 -05:00
return nil
}
// Build the list of provisioners we need based on the configuration.
// It is okay to have duplicates here.
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
result := make ( [ ] string , len ( n . Config . Managed . Provisioners ) )
for i , p := range n . Config . Managed . Provisioners {
2016-09-21 16:30:41 -05:00
result [ i ] = p . Type
}
return result
}
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
// GraphNodeProvisionerConsumer
2018-05-02 22:16:22 -05:00
func ( n * NodeAbstractResource ) AttachProvisionerSchema ( name string , schema * configschema . Block ) {
2018-05-24 18:00:26 -05:00
if n . ProvisionerSchemas == nil {
n . ProvisionerSchemas = make ( map [ string ] * configschema . Block )
}
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
n . ProvisionerSchemas [ name ] = schema
}
// GraphNodeResource
2020-03-15 10:32:06 -05:00
func ( n * NodeAbstractResource ) ResourceAddr ( ) addrs . ConfigResource {
return n . Addr
2016-09-21 16:30:41 -05:00
}
2016-10-20 20:59:02 -05:00
// GraphNodeTargetable
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 * NodeAbstractResource ) SetTargets ( targets [ ] addrs . Targetable ) {
2016-10-20 20:59:02 -05:00
n . Targets = targets
}
2024-11-05 09:16:00 -06:00
// GraphNodeTargetable
func ( n * NodeAbstractResource ) SetExcludes ( excludes [ ] addrs . Targetable ) {
n . Excludes = excludes
}
2021-03-08 12:46:28 -06:00
// graphNodeAttachDataResourceDependsOn
func ( n * NodeAbstractResource ) AttachDataResourceDependsOn ( deps [ ] addrs . ConfigResource , force bool ) {
2020-05-01 09:22:50 -05:00
n . dependsOn = deps
2020-06-04 11:39:36 -05:00
n . forceDependsOn = force
2020-05-01 09:22:50 -05:00
}
2016-09-21 16:30:41 -05:00
// GraphNodeAttachResourceConfig
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 * NodeAbstractResource ) AttachResourceConfig ( c * configs . Resource ) {
2016-09-21 16:30:41 -05:00
n . Config = c
}
2016-12-02 21:26:40 -06:00
2018-05-02 22:16:22 -05:00
// GraphNodeAttachResourceSchema impl
2018-11-27 17:30:18 -06:00
func ( n * NodeAbstractResource ) AttachResourceSchema ( schema * configschema . Block , version uint64 ) {
2018-05-02 22:16:22 -05:00
n . Schema = schema
2018-11-27 17:30:18 -06:00
n . SchemaVersion = version
2018-05-02 22:16:22 -05:00
}
2020-03-05 18:53:24 -06:00
// GraphNodeAttachProviderMetaConfigs impl
func ( n * NodeAbstractResource ) AttachProviderMetaConfigs ( c map [ addrs . Provider ] * configs . ProviderMeta ) {
n . ProviderMetas = c
}
2016-12-02 21:26:40 -06:00
// GraphNodeDotter impl.
func ( n * NodeAbstractResource ) DotNode ( name string , opts * dag . DotOpts ) * dag . DotNode {
return & dag . DotNode {
Name : name ,
Attrs : map [ string ] string {
"label" : n . Name ( ) ,
"shape" : "box" ,
} ,
}
}
2020-07-16 18:11:08 -05:00
2020-10-01 07:12:10 -05:00
// writeResourceState ensures that a suitable resource-level state record is
2020-09-25 10:15:53 -05:00
// present in the state, if that's required for the "each mode" of that
// resource.
2020-09-25 11:37:23 -05:00
//
2020-09-25 10:15:53 -05:00
// This is important primarily for the situation where count = 0, since this
// eval is the only change we get to set the resource "each mode" to list
// in that case, allowing expression evaluation to see it as a zero-element list
// rather than as not set at all.
2020-10-28 12:47:04 -05:00
func ( n * NodeAbstractResource ) writeResourceState ( ctx EvalContext , addr addrs . AbsResource ) ( diags tfdiags . Diagnostics ) {
2020-09-25 10:15:53 -05:00
state := ctx . State ( )
// We'll record our expansion decision in the shared "expander" object
// so that later operations (i.e. DynamicExpand and expression evaluation)
// can refer to it. Since this node represents the abstract module, we need
// to expand the module here to create all resources.
expander := ctx . InstanceExpander ( )
switch {
2023-05-11 01:38:37 -05:00
case n . Config != nil && n . Config . Count != nil :
2020-09-25 10:15:53 -05:00
count , countDiags := evaluateCountExpression ( n . Config . Count , ctx )
diags = diags . Append ( countDiags )
if countDiags . HasErrors ( ) {
2020-10-28 12:47:04 -05:00
return diags
2020-09-25 10:15:53 -05:00
}
2024-11-05 17:08:23 -06:00
state . SetResourceProvider ( addr , n . ResolvedProvider . ProviderConfig )
2020-09-25 10:15:53 -05:00
expander . SetResourceCount ( addr . Module , n . Addr . Resource , count )
2023-05-11 01:38:37 -05:00
case n . Config != nil && n . Config . ForEach != nil :
2020-09-25 10:15:53 -05:00
forEach , forEachDiags := evaluateForEachExpression ( n . Config . ForEach , ctx )
diags = diags . Append ( forEachDiags )
if forEachDiags . HasErrors ( ) {
2020-10-28 12:47:04 -05:00
return diags
2020-09-25 10:15:53 -05:00
}
// This method takes care of all of the business logic of updating this
// while ensuring that any existing instances are preserved, etc.
2024-11-05 17:08:23 -06:00
state . SetResourceProvider ( addr , n . ResolvedProvider . ProviderConfig )
2020-09-25 10:15:53 -05:00
expander . SetResourceForEach ( addr . Module , n . Addr . Resource , forEach )
default :
2024-11-05 17:08:23 -06:00
state . SetResourceProvider ( addr , n . ResolvedProvider . ProviderConfig )
2020-09-25 10:15:53 -05:00
expander . SetResourceSingle ( addr . Module , n . Addr . Resource )
}
2020-10-28 12:47:04 -05:00
return diags
2020-09-25 10:15:53 -05:00
}
Eval() Refactor: Plan Edition (#27177)
* terraforn: refactor EvalRefresh
EvalRefresh.Eval(ctx) is now Refresh(evalRefreshReqest, ctx). While none
of the inner logic of the function has changed, it now returns a
states.ResourceInstanceObject instead of updating a pointer. This is a
human-centric change, meant to make the logic flow (in the calling
functions) easier to follow.
* terraform: refactor EvalReadDataPlan and Apply
This is a very minor refactor that removes the (currently) redundant
types EvalReadDataPlan and EvalReadDataApply in favor of using
EvalReadData with a Plan and Apply functions.
This is in effect an aesthetic change; since there is no longer an
Eval() abstraction we can rename functions to make their functionality
as obvious as possible.
* terraform: refactor EvalCheckPlannedChange
EvalCheckPlannedChange was only used by NodeApplyableResourceInstance
and has been refactored into a method on that type called
checkPlannedChange.
* terraform: refactor EvalDiff.Eval
EvalDiff.Eval is now a method on NodeResourceAbstracted called Plan
which takes as a parameter an EvalPlanRequest. Instead of updating
pointers it returns a new plan and state.
I removed as many redundant fields from the original EvalDiff struct as
possible.
* terraform: refactor EvalReduceDiff
EvalReduceDiff is now reducePlan, a regular function (without a method)
that returns a value.
* terraform: refactor EvalDiffDestroy
EvalDiffDestroy.Eval is now NodeAbstractResourceInstance.PlanDestroy
which takes ctx, state and optional DeposedKey and returns a change.
I've removed the state return value since it was only ever returning a
nil state.
* terraform: refactor EvalWriteDiff
EvalWriteDiff.Eval is now NodeAbstractResourceInstance.WriteChange.
* rename files to something more logical
* terrafrom: refresh refactor, continued!
I had originally made Refresh a stand-alone function since it was
(obnoxiously) called from a graphNodeImportStateSub, but after some
(greatly appreciated) prompting in the PR I instead made it a method on
the NodeAbstractResourceInstance, in keeping with the other refactored
eval nodes, and then built a NodeAbstractResourceInstance inside import.
Since I did that I could also remove my duplicated 'writeState' code
inside graphNodeImportStateSub and use n.writeResourceInstanceState, so
double thanks!
* unexport eval methods
* re-refactor Plan, it made more sense on NodeAbstractResourceInstance. Sorry
* Remove uninformative `Eval`s from EvalReadData, consolidate to a single
file, and rename file to match function names.
* manual rebase
2020-12-08 07:50:30 -06:00
// readResourceInstanceState reads the current object for a specific instance in
2020-09-29 13:31:20 -05:00
// the state.
2024-11-05 17:08:23 -06:00
func ( n * NodeAbstractResourceInstance ) readResourceInstanceState ( ctx EvalContext , addr addrs . AbsResourceInstance ) ( * states . ResourceInstanceObject , tfdiags . Diagnostics ) {
2021-04-28 12:43:45 -05:00
var diags tfdiags . Diagnostics
2024-11-05 17:08:23 -06:00
provider , providerSchema , err := getProvider ( ctx , n . ResolvedProvider . ProviderConfig , n . ResolvedProviderKey )
2020-11-30 16:34:58 -06:00
if err != nil {
2021-04-28 12:43:45 -05:00
diags = diags . Append ( err )
return nil , diags
2020-09-25 11:18:20 -05:00
}
Mildwonkey/eval apply (#27222)
* rename files for consistency with contents
* terraform: refactor EvalValidateSelfref
The EvalValidateSelfref eval node implementation was removed in favor of a regular function.
* terraform: refactor EvalValidateProvisioner
EvalValidateProvisioner is now a method on NodeValidatableResource.
* terraform: refactor EvalValidateResource
EvalValidateResource is now a method on NodeValidatableResource, and the
functions called by (the new) validateResource are now standalone
functions.
This particular refactor gets the prize for "most complicated test
refactoring".
* terraform: refactor EvalMaybeTainted
EvalMaybeTainted was a relatively simple operation which never returned
an error, so I've refactored it into a plain function and moved it into
the only file its called from.
* terraform: eval-related cleanup
De-exported preApplyHook, which got missed in my general cleanup sweeps.
Removed resourceHasUserVisibleApply in favor of moving the logic inline
- it was a single-line check so calling the function was (nearly) as
much code as just checking if the resource was managed.
* terraform: refactor EvalApplyProvisioners
EvalApplyProvisioners.Eval is now a method on
NodeResourceAbstractInstance. There were two "apply"ish functions, so I
named the first "evalApplyProvisioners" since it mainly determined if
provisioners should be run before passing off execution to
applyProvisioners.
* terraform: refactor EvalApply
EvalApply is now a method on NodeAbstractResourceInstance. This was one
of the trickier Eval()s to refactor, and my goal was to change as little
as possible to avoid unintended side effects.
One notable change: there was a createNew boolean that was only used in
NodeApplyableResourceInstance.managedResourceExecute, and that boolean
was populated from the change (which was available from
managedResourceExecute), so I removed it from apply entirely. Out of an
abundance of caution I assigned the value to createNew in (roughtly) the same spot,
in case I was missing some place where the change might get modified.
TODO: Destroy nodes passed nil configs into apply, and I am curious if
we can get the same functionality by checking if the planned change is a
destroy, instead of passing a config into apply. That felt too risky for
this refactor but it is something I would like to explore at a future
point.
There are also a few updates to log output in this PR, since I spent
some time staring at logs and noticed various spots I missed.
2020-12-10 07:05:53 -06:00
log . Printf ( "[TRACE] readResourceInstanceState: reading state for %s" , addr )
2020-09-25 11:18:20 -05:00
src := ctx . State ( ) . ResourceInstanceObject ( addr , states . CurrentGen )
if src == nil {
// Presumably we only have deposed objects, then.
Mildwonkey/eval apply (#27222)
* rename files for consistency with contents
* terraform: refactor EvalValidateSelfref
The EvalValidateSelfref eval node implementation was removed in favor of a regular function.
* terraform: refactor EvalValidateProvisioner
EvalValidateProvisioner is now a method on NodeValidatableResource.
* terraform: refactor EvalValidateResource
EvalValidateResource is now a method on NodeValidatableResource, and the
functions called by (the new) validateResource are now standalone
functions.
This particular refactor gets the prize for "most complicated test
refactoring".
* terraform: refactor EvalMaybeTainted
EvalMaybeTainted was a relatively simple operation which never returned
an error, so I've refactored it into a plain function and moved it into
the only file its called from.
* terraform: eval-related cleanup
De-exported preApplyHook, which got missed in my general cleanup sweeps.
Removed resourceHasUserVisibleApply in favor of moving the logic inline
- it was a single-line check so calling the function was (nearly) as
much code as just checking if the resource was managed.
* terraform: refactor EvalApplyProvisioners
EvalApplyProvisioners.Eval is now a method on
NodeResourceAbstractInstance. There were two "apply"ish functions, so I
named the first "evalApplyProvisioners" since it mainly determined if
provisioners should be run before passing off execution to
applyProvisioners.
* terraform: refactor EvalApply
EvalApply is now a method on NodeAbstractResourceInstance. This was one
of the trickier Eval()s to refactor, and my goal was to change as little
as possible to avoid unintended side effects.
One notable change: there was a createNew boolean that was only used in
NodeApplyableResourceInstance.managedResourceExecute, and that boolean
was populated from the change (which was available from
managedResourceExecute), so I removed it from apply entirely. Out of an
abundance of caution I assigned the value to createNew in (roughtly) the same spot,
in case I was missing some place where the change might get modified.
TODO: Destroy nodes passed nil configs into apply, and I am curious if
we can get the same functionality by checking if the planned change is a
destroy, instead of passing a config into apply. That felt too risky for
this refactor but it is something I would like to explore at a future
point.
There are also a few updates to log output in this PR, since I spent
some time staring at logs and noticed various spots I missed.
2020-12-10 07:05:53 -06:00
log . Printf ( "[TRACE] readResourceInstanceState: no state present for %s" , addr )
2020-09-25 11:18:20 -05:00
return nil , nil
}
schema , currentVersion := ( providerSchema ) . SchemaForResourceAddr ( addr . Resource . ContainingResource ( ) )
if schema == nil {
// Shouldn't happen since we should've failed long ago if no schema is present
2023-09-21 07:38:46 -05:00
return nil , diags . Append ( fmt . Errorf ( "no schema available for %s while reading state; this is a bug in OpenTofu and should be reported" , addr ) )
2020-09-25 11:18:20 -05:00
}
2021-04-28 12:43:45 -05:00
src , upgradeDiags := upgradeResourceState ( addr , provider , src , schema , currentVersion )
if n . Config != nil {
upgradeDiags = upgradeDiags . InConfigBody ( n . Config . Config , addr . String ( ) )
}
diags = diags . Append ( upgradeDiags )
2020-09-25 11:18:20 -05:00
if diags . HasErrors ( ) {
2021-04-28 12:43:45 -05:00
return nil , diags
2020-09-25 11:18:20 -05:00
}
obj , err := src . Decode ( schema . ImpliedType ( ) )
if err != nil {
2021-04-28 12:43:45 -05:00
diags = diags . Append ( err )
2020-09-25 11:18:20 -05:00
}
2021-04-28 12:43:45 -05:00
return obj , diags
2020-09-25 11:18:20 -05:00
}
Mildwonkey/eval apply (#27222)
* rename files for consistency with contents
* terraform: refactor EvalValidateSelfref
The EvalValidateSelfref eval node implementation was removed in favor of a regular function.
* terraform: refactor EvalValidateProvisioner
EvalValidateProvisioner is now a method on NodeValidatableResource.
* terraform: refactor EvalValidateResource
EvalValidateResource is now a method on NodeValidatableResource, and the
functions called by (the new) validateResource are now standalone
functions.
This particular refactor gets the prize for "most complicated test
refactoring".
* terraform: refactor EvalMaybeTainted
EvalMaybeTainted was a relatively simple operation which never returned
an error, so I've refactored it into a plain function and moved it into
the only file its called from.
* terraform: eval-related cleanup
De-exported preApplyHook, which got missed in my general cleanup sweeps.
Removed resourceHasUserVisibleApply in favor of moving the logic inline
- it was a single-line check so calling the function was (nearly) as
much code as just checking if the resource was managed.
* terraform: refactor EvalApplyProvisioners
EvalApplyProvisioners.Eval is now a method on
NodeResourceAbstractInstance. There were two "apply"ish functions, so I
named the first "evalApplyProvisioners" since it mainly determined if
provisioners should be run before passing off execution to
applyProvisioners.
* terraform: refactor EvalApply
EvalApply is now a method on NodeAbstractResourceInstance. This was one
of the trickier Eval()s to refactor, and my goal was to change as little
as possible to avoid unintended side effects.
One notable change: there was a createNew boolean that was only used in
NodeApplyableResourceInstance.managedResourceExecute, and that boolean
was populated from the change (which was available from
managedResourceExecute), so I removed it from apply entirely. Out of an
abundance of caution I assigned the value to createNew in (roughtly) the same spot,
in case I was missing some place where the change might get modified.
TODO: Destroy nodes passed nil configs into apply, and I am curious if
we can get the same functionality by checking if the planned change is a
destroy, instead of passing a config into apply. That felt too risky for
this refactor but it is something I would like to explore at a future
point.
There are also a few updates to log output in this PR, since I spent
some time staring at logs and noticed various spots I missed.
2020-12-10 07:05:53 -06:00
// readResourceInstanceStateDeposed reads the deposed object for a specific
2020-12-04 08:16:26 -06:00
// instance in the state.
2024-11-05 17:08:23 -06:00
func ( n * NodeAbstractResourceInstance ) readResourceInstanceStateDeposed ( ctx EvalContext , addr addrs . AbsResourceInstance , key states . DeposedKey ) ( * states . ResourceInstanceObject , tfdiags . Diagnostics ) {
2021-04-28 12:43:45 -05:00
var diags tfdiags . Diagnostics
2024-11-05 17:08:23 -06:00
provider , providerSchema , err := getProvider ( ctx , n . ResolvedProvider . ProviderConfig , n . ResolvedProviderKey )
2020-12-04 08:16:26 -06:00
if err != nil {
2021-04-28 12:43:45 -05:00
diags = diags . Append ( err )
return nil , diags
2020-12-04 08:16:26 -06:00
}
if key == states . NotDeposed {
2023-09-21 07:38:46 -05:00
return nil , diags . Append ( fmt . Errorf ( "readResourceInstanceStateDeposed used with no instance key; this is a bug in OpenTofu and should be reported" ) )
2020-12-04 08:16:26 -06:00
}
Mildwonkey/eval apply (#27222)
* rename files for consistency with contents
* terraform: refactor EvalValidateSelfref
The EvalValidateSelfref eval node implementation was removed in favor of a regular function.
* terraform: refactor EvalValidateProvisioner
EvalValidateProvisioner is now a method on NodeValidatableResource.
* terraform: refactor EvalValidateResource
EvalValidateResource is now a method on NodeValidatableResource, and the
functions called by (the new) validateResource are now standalone
functions.
This particular refactor gets the prize for "most complicated test
refactoring".
* terraform: refactor EvalMaybeTainted
EvalMaybeTainted was a relatively simple operation which never returned
an error, so I've refactored it into a plain function and moved it into
the only file its called from.
* terraform: eval-related cleanup
De-exported preApplyHook, which got missed in my general cleanup sweeps.
Removed resourceHasUserVisibleApply in favor of moving the logic inline
- it was a single-line check so calling the function was (nearly) as
much code as just checking if the resource was managed.
* terraform: refactor EvalApplyProvisioners
EvalApplyProvisioners.Eval is now a method on
NodeResourceAbstractInstance. There were two "apply"ish functions, so I
named the first "evalApplyProvisioners" since it mainly determined if
provisioners should be run before passing off execution to
applyProvisioners.
* terraform: refactor EvalApply
EvalApply is now a method on NodeAbstractResourceInstance. This was one
of the trickier Eval()s to refactor, and my goal was to change as little
as possible to avoid unintended side effects.
One notable change: there was a createNew boolean that was only used in
NodeApplyableResourceInstance.managedResourceExecute, and that boolean
was populated from the change (which was available from
managedResourceExecute), so I removed it from apply entirely. Out of an
abundance of caution I assigned the value to createNew in (roughtly) the same spot,
in case I was missing some place where the change might get modified.
TODO: Destroy nodes passed nil configs into apply, and I am curious if
we can get the same functionality by checking if the planned change is a
destroy, instead of passing a config into apply. That felt too risky for
this refactor but it is something I would like to explore at a future
point.
There are also a few updates to log output in this PR, since I spent
some time staring at logs and noticed various spots I missed.
2020-12-10 07:05:53 -06:00
log . Printf ( "[TRACE] readResourceInstanceStateDeposed: reading state for %s deposed object %s" , addr , key )
2020-12-04 08:16:26 -06:00
src := ctx . State ( ) . ResourceInstanceObject ( addr , key )
if src == nil {
// Presumably we only have deposed objects, then.
Mildwonkey/eval apply (#27222)
* rename files for consistency with contents
* terraform: refactor EvalValidateSelfref
The EvalValidateSelfref eval node implementation was removed in favor of a regular function.
* terraform: refactor EvalValidateProvisioner
EvalValidateProvisioner is now a method on NodeValidatableResource.
* terraform: refactor EvalValidateResource
EvalValidateResource is now a method on NodeValidatableResource, and the
functions called by (the new) validateResource are now standalone
functions.
This particular refactor gets the prize for "most complicated test
refactoring".
* terraform: refactor EvalMaybeTainted
EvalMaybeTainted was a relatively simple operation which never returned
an error, so I've refactored it into a plain function and moved it into
the only file its called from.
* terraform: eval-related cleanup
De-exported preApplyHook, which got missed in my general cleanup sweeps.
Removed resourceHasUserVisibleApply in favor of moving the logic inline
- it was a single-line check so calling the function was (nearly) as
much code as just checking if the resource was managed.
* terraform: refactor EvalApplyProvisioners
EvalApplyProvisioners.Eval is now a method on
NodeResourceAbstractInstance. There were two "apply"ish functions, so I
named the first "evalApplyProvisioners" since it mainly determined if
provisioners should be run before passing off execution to
applyProvisioners.
* terraform: refactor EvalApply
EvalApply is now a method on NodeAbstractResourceInstance. This was one
of the trickier Eval()s to refactor, and my goal was to change as little
as possible to avoid unintended side effects.
One notable change: there was a createNew boolean that was only used in
NodeApplyableResourceInstance.managedResourceExecute, and that boolean
was populated from the change (which was available from
managedResourceExecute), so I removed it from apply entirely. Out of an
abundance of caution I assigned the value to createNew in (roughtly) the same spot,
in case I was missing some place where the change might get modified.
TODO: Destroy nodes passed nil configs into apply, and I am curious if
we can get the same functionality by checking if the planned change is a
destroy, instead of passing a config into apply. That felt too risky for
this refactor but it is something I would like to explore at a future
point.
There are also a few updates to log output in this PR, since I spent
some time staring at logs and noticed various spots I missed.
2020-12-10 07:05:53 -06:00
log . Printf ( "[TRACE] readResourceInstanceStateDeposed: no state present for %s deposed object %s" , addr , key )
2021-04-28 12:43:45 -05:00
return nil , diags
2020-12-04 08:16:26 -06:00
}
schema , currentVersion := ( providerSchema ) . SchemaForResourceAddr ( addr . Resource . ContainingResource ( ) )
if schema == nil {
// Shouldn't happen since we should've failed long ago if no schema is present
2023-09-21 07:38:46 -05:00
return nil , diags . Append ( fmt . Errorf ( "no schema available for %s while reading state; this is a bug in OpenTofu and should be reported" , addr ) )
2020-12-04 08:16:26 -06:00
}
2021-04-28 12:43:45 -05:00
src , upgradeDiags := upgradeResourceState ( addr , provider , src , schema , currentVersion )
if n . Config != nil {
upgradeDiags = upgradeDiags . InConfigBody ( n . Config . Config , addr . String ( ) )
}
diags = diags . Append ( upgradeDiags )
2020-12-04 08:16:26 -06:00
if diags . HasErrors ( ) {
// Note that we don't have any channel to return warnings here. We'll
// accept that for now since warnings during a schema upgrade would
// be pretty weird anyway, since this operation is supposed to seem
// invisible to the user.
2021-04-28 12:43:45 -05:00
return nil , diags
2020-12-04 08:16:26 -06:00
}
obj , err := src . Decode ( schema . ImpliedType ( ) )
if err != nil {
2021-04-28 12:43:45 -05:00
diags = diags . Append ( err )
2020-12-04 08:16:26 -06:00
}
2021-04-28 12:43:45 -05:00
return obj , diags
2020-12-04 08:16:26 -06:00
}
2020-07-16 18:11:08 -05:00
// graphNodesAreResourceInstancesInDifferentInstancesOfSameModule is an
// annoyingly-task-specific helper function that returns true if and only if
// the following conditions hold:
2022-08-17 13:46:02 -05:00
// - Both of the given vertices represent specific resource instances, as
// opposed to unexpanded resources or any other non-resource-related object.
// - The module instance addresses for both of the resource instances belong
// to the same static module.
// - The module instance addresses for both of the resource instances are
// not equal, indicating that they belong to different instances of the
// same module.
2020-07-16 18:11:08 -05:00
//
// This result can be used as a way to compensate for the effects of
2022-08-17 13:46:02 -05:00
// conservative analysis passes in our graph builders which make their
2020-07-16 18:11:08 -05:00
// decisions based only on unexpanded addresses, often so that they can behave
// correctly for interactions between expanded and not-yet-expanded objects.
//
// Callers of this helper function will typically skip adding an edge between
// the two given nodes if this function returns true.
func graphNodesAreResourceInstancesInDifferentInstancesOfSameModule ( a , b dag . Vertex ) bool {
aRI , aOK := a . ( GraphNodeResourceInstance )
bRI , bOK := b . ( GraphNodeResourceInstance )
if ! ( aOK && bOK ) {
return false
}
aModInst := aRI . ResourceInstanceAddr ( ) . Module
bModInst := bRI . ResourceInstanceAddr ( ) . Module
aMod := aModInst . Module ( )
bMod := bModInst . Module ( )
if ! aMod . Equal ( bMod ) {
return false
}
return ! aModInst . Equal ( bModInst )
}