2016-04-26 12:38:30 -05:00
|
|
|
package terraform
|
|
|
|
|
2016-05-10 11:15:19 -05:00
|
|
|
import (
|
terraform: ugly huge change to weave in new HCL2-oriented types
Due to how deeply the configuration types go into Terraform Core, there
isn't a great way to switch out to HCL2 gradually. As a consequence, this
huge commit gets us from the old state to a _compilable_ new state, but
does not yet attempt to fix any tests and has a number of known missing
parts and bugs. We will continue to iterate on this in forthcoming
commits, heading back towards passing tests and making Terraform
fully-functional again.
The three main goals here are:
- Use the configuration models from the "configs" package instead of the
older models in the "config" package, which is now deprecated and
preserved only to help us write our migration tool.
- Do expression inspection and evaluation using the functionality of the
new "lang" package, instead of the Interpolator type and related
functionality in the main "terraform" package.
- Represent addresses of various objects using types in the addrs package,
rather than hand-constructed strings. This is not critical to support
the above, but was a big help during the implementation of these other
points since it made it much more explicit what kind of address is
expected in each context.
Since our new packages are built to accommodate some future planned
features that are not yet implemented (e.g. the "for_each" argument on
resources, "count"/"for_each" on modules), and since there's still a fair
amount of functionality still using old-style APIs, there is a moderate
amount of shimming here to connect new assumptions with old, hopefully in
a way that makes it easier to find and eliminate these shims later.
I apologize in advance to the person who inevitably just found this huge
commit while spelunking through the commit history.
2018-04-30 12:33:53 -05:00
|
|
|
"github.com/hashicorp/terraform/addrs"
|
|
|
|
"github.com/hashicorp/terraform/configs"
|
2016-12-03 17:27:38 -06:00
|
|
|
"github.com/hashicorp/terraform/dag"
|
terraform: ugly huge change to weave in new HCL2-oriented types
Due to how deeply the configuration types go into Terraform Core, there
isn't a great way to switch out to HCL2 gradually. As a consequence, this
huge commit gets us from the old state to a _compilable_ new state, but
does not yet attempt to fix any tests and has a number of known missing
parts and bugs. We will continue to iterate on this in forthcoming
commits, heading back towards passing tests and making Terraform
fully-functional again.
The three main goals here are:
- Use the configuration models from the "configs" package instead of the
older models in the "config" package, which is now deprecated and
preserved only to help us write our migration tool.
- Do expression inspection and evaluation using the functionality of the
new "lang" package, instead of the Interpolator type and related
functionality in the main "terraform" package.
- Represent addresses of various objects using types in the addrs package,
rather than hand-constructed strings. This is not critical to support
the above, but was a big help during the implementation of these other
points since it made it much more explicit what kind of address is
expected in each context.
Since our new packages are built to accommodate some future planned
features that are not yet implemented (e.g. the "for_each" argument on
resources, "count"/"for_each" on modules), and since there's still a fair
amount of functionality still using old-style APIs, there is a moderate
amount of shimming here to connect new assumptions with old, hopefully in
a way that makes it easier to find and eliminate these shims later.
I apologize in advance to the person who inevitably just found this huge
commit while spelunking through the commit history.
2018-04-30 12:33:53 -05:00
|
|
|
"github.com/hashicorp/terraform/tfdiags"
|
2016-05-10 11:15:19 -05:00
|
|
|
)
|
|
|
|
|
2016-04-26 12:38:30 -05:00
|
|
|
// ImportGraphBuilder implements GraphBuilder and is responsible for building
|
|
|
|
// a graph for importing resources into Terraform. This is a much, much
|
|
|
|
// simpler graph than a normal configuration graph.
|
|
|
|
type ImportGraphBuilder struct {
|
|
|
|
// ImportTargets are the list of resources to import.
|
|
|
|
ImportTargets []*ImportTarget
|
|
|
|
|
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
|
|
|
// Module is a configuration to build the graph from. See ImportOpts.Config.
|
|
|
|
Config *configs.Config
|
2016-05-10 11:15:19 -05:00
|
|
|
|
2018-05-29 15:29:09 -05:00
|
|
|
// Components is the factory for our available plugin components.
|
|
|
|
Components contextComponentFactory
|
2018-05-31 14:39:45 -05:00
|
|
|
|
|
|
|
// Schemas is the repository of schemas we will draw from to analyse
|
|
|
|
// the configuration.
|
|
|
|
Schemas *Schemas
|
2016-04-26 12:38:30 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// Build builds the graph according to the steps returned by Steps.
|
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 (b *ImportGraphBuilder) Build(path addrs.ModuleInstance) (*Graph, tfdiags.Diagnostics) {
|
2016-04-26 12:38:30 -05:00
|
|
|
return (&BasicGraphBuilder{
|
|
|
|
Steps: b.Steps(),
|
|
|
|
Validate: true,
|
2016-11-15 15:36:10 -06:00
|
|
|
Name: "ImportGraphBuilder",
|
2016-04-26 12:38:30 -05:00
|
|
|
}).Build(path)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Steps returns the ordered list of GraphTransformers that must be executed
|
|
|
|
// to build a complete graph.
|
|
|
|
func (b *ImportGraphBuilder) Steps() []GraphTransformer {
|
2016-05-10 11:15:19 -05:00
|
|
|
// Get the module. If we don't have one, we just use an empty tree
|
|
|
|
// so that the transform still works but does nothing.
|
terraform: ugly huge change to weave in new HCL2-oriented types
Due to how deeply the configuration types go into Terraform Core, there
isn't a great way to switch out to HCL2 gradually. As a consequence, this
huge commit gets us from the old state to a _compilable_ new state, but
does not yet attempt to fix any tests and has a number of known missing
parts and bugs. We will continue to iterate on this in forthcoming
commits, heading back towards passing tests and making Terraform
fully-functional again.
The three main goals here are:
- Use the configuration models from the "configs" package instead of the
older models in the "config" package, which is now deprecated and
preserved only to help us write our migration tool.
- Do expression inspection and evaluation using the functionality of the
new "lang" package, instead of the Interpolator type and related
functionality in the main "terraform" package.
- Represent addresses of various objects using types in the addrs package,
rather than hand-constructed strings. This is not critical to support
the above, but was a big help during the implementation of these other
points since it made it much more explicit what kind of address is
expected in each context.
Since our new packages are built to accommodate some future planned
features that are not yet implemented (e.g. the "for_each" argument on
resources, "count"/"for_each" on modules), and since there's still a fair
amount of functionality still using old-style APIs, there is a moderate
amount of shimming here to connect new assumptions with old, hopefully in
a way that makes it easier to find and eliminate these shims later.
I apologize in advance to the person who inevitably just found this huge
commit while spelunking through the commit history.
2018-04-30 12:33:53 -05:00
|
|
|
config := b.Config
|
|
|
|
if config == nil {
|
|
|
|
config = configs.NewEmptyConfig()
|
2016-05-10 11:15:19 -05:00
|
|
|
}
|
|
|
|
|
2016-11-02 12:56:23 -05:00
|
|
|
// Custom factory for creating providers.
|
2016-12-03 17:27:38 -06:00
|
|
|
concreteProvider := func(a *NodeAbstractProvider) dag.Vertex {
|
2016-11-02 12:56:23 -05:00
|
|
|
return &NodeApplyableProvider{
|
2016-12-03 17:27:38 -06:00
|
|
|
NodeAbstractProvider: a,
|
2016-11-02 12:56:23 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-26 12:38:30 -05:00
|
|
|
steps := []GraphTransformer{
|
2016-05-10 11:15:19 -05:00
|
|
|
// Create all our resources from the configuration and state
|
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
|
|
|
&ConfigTransformer{Config: config},
|
2016-05-10 11:15:19 -05:00
|
|
|
|
2019-09-20 09:02:42 -05:00
|
|
|
// Attach the configuration to any resources
|
|
|
|
&AttachResourceConfigTransformer{Config: b.Config},
|
|
|
|
|
2016-04-28 04:46:46 -05:00
|
|
|
// Add the import steps
|
|
|
|
&ImportStateTransformer{Targets: b.ImportTargets},
|
|
|
|
|
2018-05-29 15:29:09 -05:00
|
|
|
// Add root variables
|
|
|
|
&RootVariableTransformer{Config: b.Config},
|
|
|
|
|
|
|
|
TransformProviders(b.Components.ResourceProviders(), concreteProvider, config),
|
2016-04-26 12:38:30 -05:00
|
|
|
|
2016-11-02 13:08:16 -05:00
|
|
|
// This validates that the providers only depend on variables
|
|
|
|
&ImportProviderValidateTransformer{},
|
|
|
|
|
2018-05-29 15:29:09 -05:00
|
|
|
// Add the local values
|
|
|
|
&LocalTransformer{Config: b.Config},
|
|
|
|
|
|
|
|
// Add the outputs
|
|
|
|
&OutputTransformer{Config: b.Config},
|
|
|
|
|
|
|
|
// Add module variables
|
|
|
|
&ModuleVariableTransformer{Config: b.Config},
|
|
|
|
|
2018-06-01 15:00:52 -05:00
|
|
|
// Must attach schemas before ReferenceTransformer so that we can
|
|
|
|
// analyze the configuration to find references.
|
|
|
|
&AttachSchemaTransformer{Schemas: b.Schemas},
|
|
|
|
|
2018-05-29 15:29:09 -05:00
|
|
|
// Connect so that the references are ready for targeting. We'll
|
|
|
|
// have to connect again later for providers and so on.
|
|
|
|
&ReferenceTransformer{},
|
|
|
|
|
2017-04-12 16:25:15 -05:00
|
|
|
// Close opened plugin connections
|
|
|
|
&CloseProviderTransformer{},
|
|
|
|
|
2016-11-02 12:39:04 -05:00
|
|
|
// Single root
|
|
|
|
&RootTransformer{},
|
|
|
|
|
2016-04-26 12:38:30 -05:00
|
|
|
// Optimize
|
|
|
|
&TransitiveReductionTransformer{},
|
|
|
|
}
|
|
|
|
|
|
|
|
return steps
|
|
|
|
}
|