2015-01-26 22:17:52 -06:00
|
|
|
package terraform
|
|
|
|
|
2015-02-07 17:39:57 -06:00
|
|
|
import (
|
2017-11-02 15:38:32 -05:00
|
|
|
"log"
|
|
|
|
|
2015-02-07 17:39:57 -06:00
|
|
|
"github.com/hashicorp/terraform/dag"
|
2019-12-05 13:13:37 -06:00
|
|
|
"github.com/hashicorp/terraform/helper/logging"
|
2015-02-07 17:39:57 -06:00
|
|
|
)
|
|
|
|
|
2015-01-26 22:17:52 -06:00
|
|
|
// GraphTransformer is the interface that transformers implement. This
|
|
|
|
// interface is only for transforms that need entire graph visibility.
|
|
|
|
type GraphTransformer interface {
|
2015-01-26 23:23:27 -06:00
|
|
|
Transform(*Graph) error
|
2015-01-26 22:17:52 -06:00
|
|
|
}
|
2015-02-07 17:39:57 -06:00
|
|
|
|
|
|
|
// GraphVertexTransformer is an interface that transforms a single
|
|
|
|
// Vertex within with graph. This is a specialization of GraphTransformer
|
|
|
|
// that makes it easy to do vertex replacement.
|
|
|
|
//
|
|
|
|
// The GraphTransformer that runs through the GraphVertexTransformers is
|
|
|
|
// VertexTransformer.
|
|
|
|
type GraphVertexTransformer interface {
|
|
|
|
Transform(dag.Vertex) (dag.Vertex, error)
|
|
|
|
}
|
2016-10-21 01:22:33 -05:00
|
|
|
|
|
|
|
// GraphTransformIf is a helper function that conditionally returns a
|
|
|
|
// GraphTransformer given. This is useful for calling inline a sequence
|
|
|
|
// of transforms without having to split it up into multiple append() calls.
|
|
|
|
func GraphTransformIf(f func() bool, then GraphTransformer) GraphTransformer {
|
|
|
|
if f() {
|
|
|
|
return then
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
type graphTransformerMulti struct {
|
|
|
|
Transforms []GraphTransformer
|
|
|
|
}
|
|
|
|
|
|
|
|
func (t *graphTransformerMulti) Transform(g *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 lastStepStr string
|
2016-10-21 01:22:33 -05:00
|
|
|
for _, t := range t.Transforms {
|
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.Printf("[TRACE] (graphTransformerMulti) Executing graph transform %T", t)
|
2016-10-21 01:22:33 -05:00
|
|
|
if err := t.Transform(g); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
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 thisStepStr := g.StringWithNodeTypes(); thisStepStr != lastStepStr {
|
2019-12-05 13:13:37 -06:00
|
|
|
log.Printf("[TRACE] (graphTransformerMulti) Completed graph transform %T with new graph:\n%s ------", t, logging.Indent(thisStepStr))
|
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
|
|
|
lastStepStr = thisStepStr
|
|
|
|
} else {
|
|
|
|
log.Printf("[TRACE] (graphTransformerMulti) Completed graph transform %T (no changes)", t)
|
|
|
|
}
|
2016-10-21 01:22:33 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// GraphTransformMulti combines multiple graph transformers into a single
|
|
|
|
// GraphTransformer that runs all the individual graph transformers.
|
|
|
|
func GraphTransformMulti(ts ...GraphTransformer) GraphTransformer {
|
|
|
|
return &graphTransformerMulti{Transforms: ts}
|
|
|
|
}
|