data.aws_cloudfront_cache_policy.CachingDisabled.id is no read

According to official documentation I have declared:

data "aws_cloudfront_cache_policy" "CachingDisabled" {
  name = "CachingDisabled"
}

And then I’m using it in a behaviour:

...
ordered_cache_behavior {
    ...
    cache_policy_id = data.aws_cloudfront_cache_policy.CachingDisabled.id
    ...
}

If I try to run terraform plan I get:

      ~ ordered_cache_behavior {
          - cache_policy_id        = "4135ea2d-6df8-44a3-9df3-4b5a84be39ad" -> null
            # (12 unchanged attributes hidden)
        }

It happens only in some projects. Any idea how to fix it?

Hi there @frattallone , any update on this ? :face_with_monocle:

hi @hpzudo yours is the only answer :smiley:

Since in my tf file I have several behaviours to improve readability I’m using locals

locals {
   cors_s3origin_id = "<your policy id>"
 }
...
ordered_cache_behavior {
    cache_policy_id = local.cors_s3origin_id
}
...
1 Like

Hello again :slight_smile:

I’ve passed it by NAME instead of by ID and it’s working. I couldn’t find the name from the AWS webpage so I had to use AWS CLI to list the cache policy and retrieve the real name.

There’s a similar topic here amazon web services - How to use the the newly introduced aws_cloudfront_cache_policy resource in terraform - Stack Overflow