Hi everybody, how you are doing?
So, I need to import some resources from our AWS account. Here they are:
- One Auto Scaling Group
- Related Launch Configuration
- Related Target Groups
- Related Load Balancer (and its dependencies, like Certificates, Listeners, etc…)
- Finally, related EC2 instances
First thing, should I import those EC2 instances? Because they are created by ASG with configs defined in Launch Configuration, right?
What should be the workflow to import those related resources?
best regards
Vitor Jr.
No, those EC2 instances are managed by AWS (via the ASG) so wouldn’t be added into Terraform at all. Instead you’d have the other resources in your code as you mentioned.
In terms of doing the imports you just need to run terraform import
for each of the resources (order doesn’t really matter) ensuring you get the correct AWS ID corresponding to the correct resource identifier in your code.
1 Like
Hi @stuart-c , thanks for your reply. So, I was using terraformer to generate code for import, and I got this:
resource "aws_lb_target_group_attachment" "tfer--arn-..." {
target_group_arn = "arn:aws:elasticloadbalancing:us-west-2:000000000:targetgroup/teste-terraform-import-1/18fb..."
target_id = "i-0397b15303209..."
}
resource "aws_lb_target_group_attachment" "tfer--arn-..." {
target_group_arn = "arn:aws:elasticloadbalancing:us-west-2:000000000:targetgroup/teste-terraform-import-1/18fb..."
target_id = "i-0426590019984..."
}
How can I reference an ec2 instance in the target_id
if I’m not supposed to import then?
That is the main question for me, right now.
best regards
Vitor Jr.
You shouldn’t be targetting specific EC2 instances. This will all need to be done from the ASG configuration. Amazon will create/remove EC2 instances as needed (based on the ASG settings/scaling) so nothing in Terraform can refer to EC2 directly