2023-05-02 10:33:06 -05:00
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0
2016-11-06 01:00:05 -06:00
package terraform
2016-11-06 12:15:09 -06:00
import (
2021-04-30 18:55:53 -05:00
"fmt"
"strings"
2018-09-19 20:30:16 -05:00
2021-05-17 14:00:50 -05:00
"github.com/hashicorp/terraform/internal/addrs"
2021-05-17 11:30:37 -05:00
"github.com/hashicorp/terraform/internal/dag"
2021-05-17 14:43:35 -05:00
"github.com/hashicorp/terraform/internal/states"
2021-05-17 12:11:06 -05:00
"github.com/hashicorp/terraform/internal/tfdiags"
2016-11-06 12:15:09 -06:00
)
2022-09-23 14:29:48 -05:00
// nodeExpandPlannableResource represents an addrs.ConfigResource and implements
// DynamicExpand to a subgraph containing all of the addrs.AbsResourceInstance
// resulting from both the containing module and resource-specific expansion.
2020-03-20 14:19:01 -05:00
type nodeExpandPlannableResource struct {
* NodeAbstractResource
// ForceCreateBeforeDestroy might be set via our GraphNodeDestroyerCBD
// during graph construction, if dependencies require us to force this
// on regardless of what the configuration says.
ForceCreateBeforeDestroy * bool
2020-09-21 14:53:53 -05:00
2020-09-23 10:05:09 -05:00
// skipRefresh indicates that we should skip refreshing individual instances
skipRefresh bool
2022-11-11 10:46:56 -06:00
preDestroyRefresh bool
2021-04-05 19:05:57 -05:00
// skipPlanChanges indicates we should skip trying to plan change actions
// for any instances.
skipPlanChanges bool
2021-04-06 19:37:38 -05:00
// forceReplace are resource instance addresses where the user wants to
// force generating a replace action. This set isn't pre-filtered, so
// it might contain addresses that have nothing to do with the resource
// that this node represents, which the node itself must therefore ignore.
forceReplace [ ] addrs . AbsResourceInstance
2020-09-21 14:53:53 -05:00
// We attach dependencies to the Resource during refresh, since the
// instances are instantiated during DynamicExpand.
2022-06-14 10:09:27 -05:00
// FIXME: These would be better off converted to a generic Set data
// structure in the future, as we need to compare for equality and take the
// union of multiple groups of dependencies.
2020-09-21 14:53:53 -05:00
dependencies [ ] addrs . ConfigResource
2023-04-28 17:45:43 -05:00
// legacyImportMode is set if the graph is being constructed following an
// invocation of the legacy "terraform import" CLI command.
legacyImportMode bool
2020-03-20 14:19:01 -05:00
}
var (
_ GraphNodeDestroyerCBD = ( * nodeExpandPlannableResource ) ( nil )
_ GraphNodeDynamicExpandable = ( * nodeExpandPlannableResource ) ( nil )
_ GraphNodeReferenceable = ( * nodeExpandPlannableResource ) ( nil )
_ GraphNodeReferencer = ( * nodeExpandPlannableResource ) ( nil )
_ GraphNodeConfigResource = ( * nodeExpandPlannableResource ) ( nil )
_ GraphNodeAttachResourceConfig = ( * nodeExpandPlannableResource ) ( nil )
2020-09-21 14:53:53 -05:00
_ GraphNodeAttachDependencies = ( * nodeExpandPlannableResource ) ( nil )
2020-06-10 14:39:29 -05:00
_ GraphNodeTargetable = ( * nodeExpandPlannableResource ) ( nil )
2022-09-22 09:23:45 -05:00
_ graphNodeExpandsInstances = ( * nodeExpandPlannableResource ) ( nil )
2020-03-20 14:19:01 -05:00
)
2020-05-12 09:28:33 -05:00
func ( n * nodeExpandPlannableResource ) Name ( ) string {
return n . NodeAbstractResource . Name ( ) + " (expand)"
}
2022-09-22 09:23:45 -05:00
func ( n * nodeExpandPlannableResource ) expandsInstances ( ) {
}
2020-09-21 14:53:53 -05:00
// GraphNodeAttachDependencies
func ( n * nodeExpandPlannableResource ) AttachDependencies ( deps [ ] addrs . ConfigResource ) {
n . dependencies = deps
}
2020-03-20 14:19:01 -05:00
// GraphNodeDestroyerCBD
func ( n * nodeExpandPlannableResource ) CreateBeforeDestroy ( ) bool {
if n . ForceCreateBeforeDestroy != nil {
return * n . ForceCreateBeforeDestroy
}
// If we have no config, we just assume no
if n . Config == nil || n . Config . Managed == nil {
return false
}
return n . Config . Managed . CreateBeforeDestroy
}
// GraphNodeDestroyerCBD
func ( n * nodeExpandPlannableResource ) ModifyCreateBeforeDestroy ( v bool ) error {
n . ForceCreateBeforeDestroy = & v
return nil
}
func ( n * nodeExpandPlannableResource ) DynamicExpand ( ctx EvalContext ) ( * Graph , error ) {
var g Graph
expander := ctx . InstanceExpander ( )
2020-03-27 16:16:08 -05:00
moduleInstances := expander . ExpandModule ( n . Addr . Module )
// Lock the state while we inspect it
state := ctx . State ( ) . Lock ( )
var orphans [ ] * states . Resource
for _ , res := range state . Resources ( n . Addr ) {
found := false
for _ , m := range moduleInstances {
if m . Equal ( res . Addr . Module ) {
found = true
break
}
}
2022-09-23 14:29:48 -05:00
// The module instance of the resource in the state doesn't exist
// in the current config, so this whole resource is orphaned.
2020-03-27 16:16:08 -05:00
if ! found {
orphans = append ( orphans , res )
}
}
2022-09-23 14:29:48 -05:00
// We'll no longer use the state directly here, and the other functions
// we'll call below may use it so we'll release the lock.
state = nil
ctx . State ( ) . Unlock ( )
2020-03-27 16:16:08 -05:00
// The concrete resource factory we'll use for orphans
concreteResourceOrphan := func ( a * NodeAbstractResourceInstance ) * NodePlannableResourceInstanceOrphan {
// Add the config and state since we don't do that via transforms
a . Config = n . Config
a . ResolvedProvider = n . ResolvedProvider
a . Schema = n . Schema
a . ProvisionerSchemas = n . ProvisionerSchemas
a . ProviderMetas = n . ProviderMetas
2020-09-21 14:53:53 -05:00
a . Dependencies = n . dependencies
2020-03-27 16:16:08 -05:00
return & NodePlannableResourceInstanceOrphan {
NodeAbstractResourceInstance : a ,
2021-09-23 15:38:08 -05:00
skipRefresh : n . skipRefresh ,
skipPlanChanges : n . skipPlanChanges ,
2020-03-27 16:16:08 -05:00
}
}
for _ , res := range orphans {
for key := range res . Instances {
addr := res . Addr . Instance ( key )
abs := NewNodeAbstractResourceInstance ( addr )
abs . AttachResourceState ( res )
n := concreteResourceOrphan ( abs )
g . Add ( n )
}
}
2022-09-23 14:29:48 -05:00
// The above dealt with the expansion of the containing module, so now
// we need to deal with the expansion of the resource itself across all
// instances of the module.
//
// We'll gather up all of the leaf instances we learn about along the way
// so that we can inform the checks subsystem of which instances it should
// be expecting check results for, below.
var diags tfdiags . Diagnostics
instAddrs := addrs . MakeSet [ addrs . Checkable ] ( )
for _ , module := range moduleInstances {
resAddr := n . Addr . Resource . Absolute ( module )
err := n . expandResourceInstances ( ctx , resAddr , & g , instAddrs )
diags = diags . Append ( err )
}
if diags . HasErrors ( ) {
return nil , diags . ErrWithWarnings ( )
}
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-09-23 14:29:48 -05:00
// If this is a resource that participates in custom condition checks
// (i.e. it has preconditions or postconditions) then the check state
// wants to know the addresses of the checkable objects so that it can
// treat them as unknown status if we encounter an error before actually
// visiting the checks.
if checkState := ctx . Checks ( ) ; checkState . ConfigHasChecks ( n . NodeAbstractResource . Addr ) {
checkState . ReportCheckableObjects ( n . NodeAbstractResource . Addr , instAddrs )
}
2020-03-23 07:56:55 -05:00
2022-09-27 18:25:04 -05:00
addRootNodeToGraph ( & g )
2022-09-23 14:29:48 -05:00
return & g , diags . ErrWithWarnings ( )
2020-03-24 14:19:12 -05:00
}
2022-09-23 14:29:48 -05:00
// expandResourceInstances calculates the dynamic expansion for the resource
// itself in the context of a particular module instance.
//
// It has several side-effects:
// - Adds a node to Graph g for each leaf resource instance it discovers, whether present or orphaned.
// - Registers the expansion of the resource in the "expander" object embedded inside EvalContext ctx.
// - Adds each present (non-orphaned) resource instance address to instAddrs (guaranteed to always be addrs.AbsResourceInstance, despite being declared as addrs.Checkable).
//
// After calling this for each of the module instances the resource appears
// within, the caller must register the final superset instAddrs with the
// checks subsystem so that it knows the fully expanded set of checkable
// object instances for this resource instance.
func ( n * nodeExpandPlannableResource ) expandResourceInstances ( globalCtx EvalContext , resAddr addrs . AbsResource , g * Graph , instAddrs addrs . Set [ addrs . Checkable ] ) error {
2021-04-30 18:55:53 -05:00
var diags tfdiags . Diagnostics
2022-09-23 14:29:48 -05:00
// The rest of our work here needs to know which module instance it's
// working in, so that it can evaluate expressions in the appropriate scope.
moduleCtx := globalCtx . WithPath ( resAddr . Module )
2021-04-30 18:55:53 -05:00
// writeResourceState is responsible for informing the expander of what
// repetition mode this resource has, which allows expander.ExpandResource
// to work below.
2022-09-23 14:29:48 -05:00
moreDiags := n . writeResourceState ( moduleCtx , resAddr )
2021-04-30 18:55:53 -05:00
diags = diags . Append ( moreDiags )
if moreDiags . HasErrors ( ) {
2022-09-23 14:29:48 -05:00
return diags . ErrWithWarnings ( )
2021-04-30 18:55:53 -05:00
}
// Before we expand our resource into potentially many resource instances,
// we'll verify that any mention of this resource in n.forceReplace is
// consistent with the repetition mode of the resource. In other words,
// we're aiming to catch a situation where naming a particular resource
// instance would require an instance key but the given address has none.
2022-09-23 14:29:48 -05:00
expander := moduleCtx . InstanceExpander ( )
instanceAddrs := expander . ExpandResource ( resAddr )
2021-04-30 18:55:53 -05:00
// If there's a number of instances other than 1 then we definitely need
// an index.
mustHaveIndex := len ( instanceAddrs ) != 1
// If there's only one instance then we might still need an index, if the
// instance address has one.
if len ( instanceAddrs ) == 1 && instanceAddrs [ 0 ] . Resource . Key != addrs . NoKey {
mustHaveIndex = true
}
if mustHaveIndex {
for _ , candidateAddr := range n . forceReplace {
if candidateAddr . Resource . Key == addrs . NoKey {
if n . Addr . Resource . Equal ( candidateAddr . Resource . Resource ) {
switch {
case len ( instanceAddrs ) == 0 :
// In this case there _are_ no instances to replace, so
// there isn't any alternative address for us to suggest.
diags = diags . Append ( tfdiags . Sourceless (
tfdiags . Warning ,
"Incompletely-matched force-replace resource instance" ,
fmt . Sprintf (
"Your force-replace request for %s doesn't match any resource instances because this resource doesn't have any instances." ,
candidateAddr ,
) ,
) )
case len ( instanceAddrs ) == 1 :
diags = diags . Append ( tfdiags . Sourceless (
tfdiags . Warning ,
"Incompletely-matched force-replace resource instance" ,
fmt . Sprintf (
"Your force-replace request for %s doesn't match any resource instances because it lacks an instance key.\n\nTo force replacement of the single declared instance, use the following option instead:\n -replace=%q" ,
candidateAddr , instanceAddrs [ 0 ] ,
) ,
) )
default :
var possibleValidOptions strings . Builder
for _ , addr := range instanceAddrs {
fmt . Fprintf ( & possibleValidOptions , "\n -replace=%q" , addr )
}
diags = diags . Append ( tfdiags . Sourceless (
tfdiags . Warning ,
"Incompletely-matched force-replace resource instance" ,
fmt . Sprintf (
"Your force-replace request for %s doesn't match any resource instances because it lacks an instance key.\n\nTo force replacement of particular instances, use one or more of the following options instead:%s" ,
candidateAddr , possibleValidOptions . String ( ) ,
) ,
) )
}
}
}
}
2018-09-19 20:30:16 -05:00
}
2021-04-30 18:55:53 -05:00
// NOTE: The actual interpretation of n.forceReplace to produce replace
2022-09-23 14:29:48 -05:00
// actions is in the per-instance function we're about to call, because
// we need to evaluate it on a per-instance basis.
for _ , addr := range instanceAddrs {
// If this resource is participating in the "checks" mechanism then our
// caller will need to know all of our expanded instance addresses as
// checkable object instances.
// (NOTE: instAddrs probably already has other instance addresses in it
// from earlier calls to this function with different resource addresses,
// because its purpose is to aggregate them all together into a single set.)
instAddrs . Add ( addr )
2018-09-21 19:08:52 -05:00
}
2022-09-23 14:29:48 -05:00
// Our graph builder mechanism expects to always be constructing new
// graphs rather than adding to existing ones, so we'll first
// construct a subgraph just for this individual modules's instances and
// then we'll steal all of its nodes and edges to incorporate into our
// main graph which contains all of the resource instances together.
instG , err := n . resourceInstanceSubgraph ( moduleCtx , resAddr , instanceAddrs )
if err != nil {
diags = diags . Append ( err )
return diags . ErrWithWarnings ( )
2018-09-21 19:08:52 -05:00
}
2022-09-23 14:29:48 -05:00
g . Subsume ( & instG . AcyclicGraph . Graph )
2018-09-21 19:08:52 -05:00
2022-09-23 14:29:48 -05:00
return diags . ErrWithWarnings ( )
2018-09-21 19:08:52 -05:00
}
2022-09-23 14:29:48 -05:00
func ( n * nodeExpandPlannableResource ) resourceInstanceSubgraph ( ctx EvalContext , addr addrs . AbsResource , instanceAddrs [ ] addrs . AbsResourceInstance ) ( * Graph , error ) {
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 diags tfdiags . Diagnostics
terraform: Ugly huge change to weave in new State and Plan types
Due to how often the state and plan types are referenced throughout
Terraform, there isn't a great way to switch them out gradually. As a
consequence, this huge commit gets us from the old world to a _compilable_
new world, but still has a large number of known test failures due to
key functionality being stubbed out.
The stubs here are for anything that interacts with providers, since we
now need to do the follow-up work to similarly replace the old
terraform.ResourceProvider interface with its replacement in the new
"providers" package. That work, along with work to fix the remaining
failing tests, will follow in subsequent commits.
The aim here was to replace all references to terraform.State and its
downstream types with states.State, terraform.Plan with plans.Plan,
state.State with statemgr.State, and switch to the new implementations of
the state and plan file formats. However, due to the number of times those
types are used, this also ended up affecting numerous other parts of core
such as terraform.Hook, the backend.Backend interface, and most of the CLI
commands.
Just as with 5861dbf3fc49b19587a31816eb06f511ab861bb4 before, I apologize
in advance to the person who inevitably just found this huge commit while
spelunking through the commit history.
2018-08-14 16:24:45 -05:00
// Our graph transformers require access to the full state, so we'll
// temporarily lock it while we work on this.
state := ctx . State ( ) . Lock ( )
defer ctx . State ( ) . Unlock ( )
2016-11-07 15:23:06 -06:00
2016-11-06 12:15:09 -06:00
// The concrete resource factory we'll use
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
concreteResource := func ( a * NodeAbstractResourceInstance ) dag . Vertex {
2023-04-28 17:45:43 -05:00
var m * NodePlannableResourceInstance
// If we're in legacy import mode (the import CLI command), we only need
// to return the import node, not a plannable resource node.
if n . legacyImportMode {
for _ , importTarget := range n . importTargets {
if importTarget . Addr . Equal ( a . Addr ) {
return & graphNodeImportState {
Addr : importTarget . Addr ,
ID : importTarget . ID ,
ResolvedProvider : n . ResolvedProvider ,
}
2022-06-06 13:46:59 -05:00
}
}
}
2016-11-06 12:15:09 -06:00
// Add the config and state since we don't do that via transforms
a . Config = n . Config
2017-11-01 17:34:18 -05:00
a . ResolvedProvider = n . ResolvedProvider
2018-05-31 14:39:45 -05:00
a . Schema = n . Schema
2018-06-01 17:04:28 -05:00
a . ProvisionerSchemas = n . ProvisionerSchemas
2020-03-05 18:53:24 -06:00
a . ProviderMetas = n . ProviderMetas
2020-05-01 09:22:50 -05:00
a . dependsOn = n . dependsOn
2020-09-21 14:53:53 -05:00
a . Dependencies = n . dependencies
2022-11-11 10:46:56 -06:00
a . preDestroyRefresh = n . preDestroyRefresh
2016-11-06 12:15:09 -06:00
2023-04-28 17:45:43 -05:00
m = & NodePlannableResourceInstance {
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
NodeAbstractResourceInstance : a ,
2018-09-21 19:08:52 -05:00
// By the time we're walking, we've figured out whether we need
// to force on CreateBeforeDestroy due to dependencies on other
// nodes that have it.
ForceCreateBeforeDestroy : n . CreateBeforeDestroy ( ) ,
2020-09-23 10:05:09 -05:00
skipRefresh : n . skipRefresh ,
2021-04-05 19:05:57 -05:00
skipPlanChanges : n . skipPlanChanges ,
2021-04-06 19:37:38 -05:00
forceReplace : n . forceReplace ,
2016-11-06 12:15:09 -06:00
}
2023-04-28 17:45:43 -05:00
for _ , importTarget := range n . importTargets {
if importTarget . Addr . Equal ( a . Addr ) {
// If we get here, we're definitely not in legacy import mode,
// so go ahead and plan the resource changes including import.
m . importTarget = ImportTarget {
ID : importTarget . ID ,
Addr : importTarget . Addr ,
}
}
}
return m
2016-11-06 12:15:09 -06:00
}
2016-11-06 12:07:17 -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
// The concrete resource factory we'll use for orphans
concreteResourceOrphan := func ( a * NodeAbstractResourceInstance ) dag . Vertex {
2016-11-07 16:05:21 -06:00
// Add the config and state since we don't do that via transforms
a . Config = n . Config
2017-11-01 17:34:18 -05:00
a . ResolvedProvider = n . ResolvedProvider
2018-05-31 14:39:45 -05:00
a . Schema = n . Schema
2018-06-01 17:04:28 -05:00
a . ProvisionerSchemas = n . ProvisionerSchemas
2020-03-05 18:53:24 -06:00
a . ProviderMetas = n . ProviderMetas
2016-11-07 16:05:21 -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
return & NodePlannableResourceInstanceOrphan {
NodeAbstractResourceInstance : a ,
2021-05-04 20:14:43 -05:00
skipRefresh : n . skipRefresh ,
2021-09-23 15:38:08 -05:00
skipPlanChanges : n . skipPlanChanges ,
2016-11-07 15:23:06 -06:00
}
}
2016-11-06 12:07:17 -06:00
// Start creating the steps
2016-11-07 15:23:06 -06:00
steps := [ ] GraphTransformer {
2019-06-12 10:07:32 -05:00
// Expand the count or for_each (if present)
2016-11-07 15:23:06 -06:00
& ResourceCountTransformer {
2019-11-21 20:45:43 -06:00
Concrete : concreteResource ,
Schema : n . Schema ,
Addr : n . ResourceAddr ( ) ,
InstanceAddrs : instanceAddrs ,
2016-11-07 15:23:06 -06:00
} ,
2019-06-12 10:07:32 -05:00
// Add the count/for_each orphans
2020-03-27 16:16:08 -05:00
& OrphanResourceInstanceCountTransformer {
2019-11-21 20:45:43 -06:00
Concrete : concreteResourceOrphan ,
2022-09-23 14:29:48 -05:00
Addr : addr ,
2019-11-21 20:45:43 -06:00
InstanceAddrs : instanceAddrs ,
State : state ,
2016-11-07 15:23:06 -06:00
} ,
2016-11-06 12:07:17 -06:00
2016-11-07 15:23:06 -06:00
// Attach the state
& AttachStateTransformer { State : state } ,
2016-11-07 19:45:08 -06:00
// Targeting
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
& TargetsTransformer { Targets : n . Targets } ,
2016-11-07 19:45:08 -06:00
2016-11-07 15:55:35 -06:00
// Connect references so ordering is correct
& ReferenceTransformer { } ,
2016-11-07 15:23:06 -06:00
// Make sure there is a single root
& RootTransformer { } ,
}
2016-11-06 12:07:17 -06:00
// Build the graph
2016-11-15 15:36:10 -06:00
b := & BasicGraphBuilder {
2022-03-11 08:31:24 -06:00
Steps : steps ,
2022-09-23 14:29:48 -05:00
Name : "nodeExpandPlannableResource" ,
2016-11-15 15:36:10 -06:00
}
2022-09-23 14:29:48 -05:00
graph , diags := b . Build ( addr . Module )
terraform: ugly huge change to weave in new HCL2-oriented types
Due to how deeply the configuration types go into Terraform Core, there
isn't a great way to switch out to HCL2 gradually. As a consequence, this
huge commit gets us from the old state to a _compilable_ new state, but
does not yet attempt to fix any tests and has a number of known missing
parts and bugs. We will continue to iterate on this in forthcoming
commits, heading back towards passing tests and making Terraform
fully-functional again.
The three main goals here are:
- Use the configuration models from the "configs" package instead of the
older models in the "config" package, which is now deprecated and
preserved only to help us write our migration tool.
- Do expression inspection and evaluation using the functionality of the
new "lang" package, instead of the Interpolator type and related
functionality in the main "terraform" package.
- Represent addresses of various objects using types in the addrs package,
rather than hand-constructed strings. This is not critical to support
the above, but was a big help during the implementation of these other
points since it made it much more explicit what kind of address is
expected in each context.
Since our new packages are built to accommodate some future planned
features that are not yet implemented (e.g. the "for_each" argument on
resources, "count"/"for_each" on modules), and since there's still a fair
amount of functionality still using old-style APIs, there is a moderate
amount of shimming here to connect new assumptions with old, hopefully in
a way that makes it easier to find and eliminate these shims later.
I apologize in advance to the person who inevitably just found this huge
commit while spelunking through the commit history.
2018-04-30 12:33:53 -05:00
return graph , diags . ErrWithWarnings ( )
2016-11-06 01:00:05 -06:00
}