Search code examples
amazon-web-servicesterraformterraform-provider-awsamazon-route53

Using just Terraform scripts, how can I reuse an existing AWS Route53 zone record


Is there a way to get around the fact that there is not no data object defined for an aws_route53_record?

I am using the AWS Parameters Manager to store the object ID's of the resources that I want to share across different projects. In a static Terraform project, I create the shared resources, and then I save the magic ID's of the shared resources to the AWS Parameters Manager.

Then, in each of the sharing projects, I use data objects to retrieve the AWS parameter values, and then I pull in the shared AWS resources.

Essentially, using just Terraform, I am trying to do the equivalent of the following:

terraform import module.networking.aws_route53_zone.example_dom EXAMPLEZONEID
terraform import module.networking.aws_route53_record.myproject_example_dom EXAMPLEZONEID_myproject.example.dom_A

Ideally, I would like to do the following

data "aws_ssm_parameter" "route53_zone_example" { name = local.route53_zone_example_ssm_lookup }
data "aws_ssm_parameter" "route53_zone_record_myproject" { name = local.route53_zone_record_myproject_ssm_lookup }

data "aws_route53_zone" "example_dom" { zone_id = data.aws_ssm_parameter.route53_zone_example.value }
data "aws_route53_record" "myproject_example_dom" { id = data.route53_zone_record_myproject.value }

Unfortunately, that produces the expected response

The provider hashicorp/aws does not support data source "aws_route53_record".

Again, what I am looking for a pure Terraform solution, one that does not require that I copy the resource definitions to each of the sharing projects.


Solution

  • If you just need the DNS address to pass into some other resource, I suggest storing that as a string.