Example - Nested Stacks
This example takes the completed nested stacks example from cfn101 workshop and exports it as modules to Terraform.
Demonstrates the following
- That each
AWS::CloudFormation::Stack
in the root stack is exported to a Terraform module. - That the module blocks for the exported modules are correctly linked up with refrences to input variables and other module outputs.
Inputs
The following CloudFormation templates form the nested stack:
The stacks were deployed with a root stack name of cfn-workshop-nested-stack
.
Import run
This is the command to export cfn-workshop-nested-stack
to Terraform in action...
A few points to note about the warnings here
- References to unsupported AWS pseudo parameters.
- The fact that the instance in
EC2Stack
containsAWS::CloudFormation::Init
and user data. - As a result of the above, the instance is scheduled for replacement.
This goes to show that importing a running EC2 instance to Terraform is not always possible, especially if that instance depends on CloudFormation init events, which don't happen in Terraform. Ultimately a new instance would need to be created using either remote provisioning or some other setup mechanism and the workload migrated to it.
Generated Outputs
A directory structure is generated in the workspace as follows
├ main.
├ module_imports.
├ terraform.
└ modules
├ cfn-workshop-nested-stack-EC2Stack-KGXCZCF8MN3C
│ ├ main.
│ └ terraform.
├ cfn-workshop-nested-stack-VpcStack-CEYRYZJTGP7X
│ ├ main.
│ └ terraform.
└ cfn-workshop-nested-stack-IamStack-R7URHPP7NDAS
└ main.