Reputation: 151
I'm terraforming an infrastructure that was never in Terraform before. I have like 300 Route53 records. I used terraform import
command to import into state until I realised it's not wise to do for each records because there are a lot of them.
I tried a tool called terraforming
but looks like the state isn't getting updated well. After import, when I do terraform plan
, I see a lot of stuff that will be created. This is wrong.
I have blocks like:
resource "aws_route53_record" "examplerecord" {
zone_id = "zone_id"
name = "name"
type = "NS"
records = [""]
resource "aws_route53_zone" "examplezone" {
name = "name"
comment = "comment"
tags {
}
}
How can I achieve achieve importing all the records at once into Terraform state? Any ideas? Thanks.
Upvotes: 0
Views: 1045
Reputation: 326
Take a look at terraformer.
It can import all of your r53 records to your state and generate terraform code at the same time.
Upvotes: 2
Reputation: 497
I am not familiar with terraforming
, but to do what you want with raw terraform
would already be a pain, as you need to create the blank resource entries in your .tf file.
Assuming this is a one-off thing, I would just write a short program that uses the AWS API to get all the relevant records, and then reformat them as terraform configurations. Something like
r = boto3.client('route53')
for hz in r.list_hosted_zones()['HostedZones']
# ... output an "aws_route53_zone" record
for rrs in r.list_resource_record_sets(HostedZoneId=hz['HostedZoneId']):
for rr in rrs['ResourceRecordSets']:
# ... output an aws_route53_record"
You get the idea. You can tell I've done this before :)
Upvotes: 2