Search code examples
terraformterraform-provider-awsterraform-template-file

Why am I getting a cycle error when setting a S3 bucket policy with a template file?


I have the following, when I try and run a "terraform plan" it is failing.

data "template_file" "s3_bucket_policy" {
  template = "${file("${path.module}/templates/s3_bucket_policy.json")}"

  vars = {
    bucket_arn            = aws_s3_bucket.app_bucket.arn
    vpc_endpoint_id       = var.vpc_endpoint_id
    vpc_tools_endpoint_id = var.vpc_tools_endpoint_id
  }
} 

The output says Error: Cycle: data.template_file.s3_bucket_policy, aws_s3_bucket.app_bucket - aws_s3_bucket.app_bucket.arn was created earlier successfully.

I'd be happy with suggestions on how to troubleshoot!


Solution

  • This can happen if your aws_s3_bucket.app_bucket resource refers to data.template_file.s3_bucket_policy.

    Sharing your entire .tf file will be helpful.