Zone Id not in root module

When I attempt to add the host zone id from my AWS route53 dashboard, terraform fails indicating that
‘A managed resource “aws_route53_zone” “<my_host_zone_id>” has not been declared in the root module.’

Is there something I need to address within AWS or is my syntax somehow incorrect? main.tf config is as follows:

resource "aws_s3_bucket_acl" "web_bucket" {
    bucket = "mywebsitebucket"
    acl    = "public-read"
}

resource "aws_acm_certificate" "web_cert" {
    domain_name     = "mywebsite.com"
    validation_method = "DNS"
}

resource "aws_route53_record" "www_record" {
    zone_id         = aws_route53_zone.<string_from_rt53_dashboard>.id
    name            = "www.mywebsite.com"
    type            = "A"
    ttl             = 3600
    records         = [aws_cloudfront_distribution.web_distribution.domain_name]

I have attempted terraform apply using both ‘.id’ and ‘zone_id’. Please advise. Thanks.

You need to define (and import) the aws_route53_zone resource.

You’d then reference it via aws_route53_zone.foo.id (where foo is the resource name).

If for some reason you can’t / won’t define the zone as a resource (which you probably should if not defined elsewhere), you would need to define and reference a data resource and / or an output from a remote state via a remote state data resource, to do what you want. But again, you probably should define and import the zone resource, unless it’s defined elsewhere in Terraform already.

In the specific case where the zone is defined in a different state, you can use a couple approaches for this for tighter or looser coupling. What I’d personally do is make an output of the zone ID from the state where it’s defined, and reference it via a terraform remote state data reference. But using a data source and hard-coding the zone ID in it would also work.