Reputation: 1718
Importing resources from Terraform is straight forward using "terraform import" syntax. However, there's no documentation for terraspace on this matter. Their docs only talks about how to import existing Terraform state files into Terraspace by moving it to S3 and configuring the backend so that Terraspace can seamlessly pick up the already existing tfstate file.
Does anyone know how I can import existing infrastructure into Terraspace? I have some existing infrastructure in AWS that I would like to import and managed by Terraspace going forward.
Upvotes: 4
Views: 1376
Reputation: 1869
The import
command was added to Terraspace in 2.2.1. The command is used like this:
terraspace import STACK ADDR ID
Note that at the moment of writing this comment, the docs for the import command contain an error. Here's a link to the relevant issue in GitHub.
Upvotes: 1
Reputation: 51
You can use the normal Terraform commands from within the BUILD_DIR (most likely in .terraspace-cache///stacks/); i.e.
TS_ENV=dev terraspace plan discombobulator
cd .terraspace-cache/us-east-1/dev/stacks/discombobulator
terraform state list aws_resource.foo
terraform import aws_resource.foo foo_id
Upvotes: 5
Reputation: 41
this is something you can do with terraform. For each resource that you want to import from your infrastructure you'll need to pass some args to terraform CLI.
So, for instance, if you want to import an exists cognito pool from AWS to terraform state you can use the following command:
terraform import aws_cognito_identity_pool.my_resource cognito_resource_id
Whereas the "my_resource" would be a terraform resource block inside your .tf file:
resource "aws_cognito_user_pool" "my_resource" {}
And the cognito_resource_id would be the pool id showing in your aws console.
If you go to documentation you'll find an "import" block, but not all resources can be imported, I suggest you go there and check each resource to double check if it can be imported.
https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/cognito_user_pool#import
I use a lot this import command to reverse engineering stufs, sometime is very confusing create all directly from terraform, in this scenario I try to create the thing on AWS console and then import with terraform.
After import you can check all the configurations that come with it using the following command:
terraform state show module.cognito.aws_cognito_user_pool_client.my_resource
In case you don't use module you can ignore the "module"and just use the rest.
Upvotes: 0