Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provider crashes instead of providing error message when cloudfront_cache_policy isn't configured correctly #21854

Open
masterqwerty opened this issue Nov 19, 2021 · 3 comments
Labels
bug Addresses a defect in current functionality. service/cloudfront Issues and PRs that pertain to the cloudfront service.

Comments

@masterqwerty
Copy link

Community Note

  • Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request
  • Please do not leave "+1" or other comments that do not add relevant new information or questions, they generate extra noise for issue followers and do not help prioritize the request
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment

Terraform CLI and Terraform AWS Provider Version

Terraform v1.0.11 on linux_amd64
provider registry.terraform.io/hashicorp/aws v3.65.0

Affected Resource(s)

  • aws_cloudfront_cache_policy

Terraform Configuration Files

terraform {
  required_providers {
    aws = {
      source  = "hashicorp/aws",
      version = "~> 3.65.0"
    }
  }
}

provider "aws" {
  region = "us-west-2"
}

resource "aws_cloudfront_cache_policy" "my_cache_policy" {
  name        = "my_cache_policy"
  min_ttl     = 300
  default_ttl = 86400
  max_ttl     = 604800

  parameters_in_cache_key_and_forwarded_to_origin {
    cookies_config {
      cookie_behavior = "all"
    }
    headers_config {}
    query_strings_config {
      query_string_behavior = "all"
    }
  }
}

Debug Output

https://gist.github.com/masterqwerty/d8c94b5d70f8c387c1534b8b30c49e72

Panic Output

https://gist.github.com/masterqwerty/e1b55abeffa28b8fe017b356189352b3

Expected Behavior

When I apply, Terraform should give me an error message saying that my terraform is invalid because the headers_config block is missing required values.

Actual Behavior

The provider plugin crashes and produces a panic. (See gist link above.)

Steps to Reproduce

  1. terraform apply

References

@github-actions github-actions bot added needs-triage Waiting for first response or review from a maintainer. service/cloudfront Issues and PRs that pertain to the cloudfront service. labels Nov 19, 2021
@masterqwerty
Copy link
Author

Update: Exact same thing happens with provider version 3.66.0

@justinretzolk justinretzolk added bug Addresses a defect in current functionality. and removed needs-triage Waiting for first response or review from a maintainer. labels Dec 9, 2021
@kirankumar-grootan
Copy link

@masterqwerty I fixed it by adding at least one arg in each *_config

cookies_config {
cookie_behavior = "none"
}

headers_config {
header_behavior = "none"
}

query_strings_config {
query_string_behavior = "whitelist"

query_strings {
items = ["v", "versions"]
}
}

@JoshCooley
Copy link

Just ran into this on 5.41.0.

Missing cookie_behavior and query_string_behavior arguments correctly throw errors

╷
│ Error: Missing required argument
│
│   on cloudfront.tf line 16, in resource "aws_cloudfront_cache_policy" "pod":
│   16:     cookies_config {
│
│ The argument "cookie_behavior" is required, but no definition was found.
╵
╷
│ Error: Missing required argument
│
│   on cloudfront.tf line 22, in resource "aws_cloudfront_cache_policy" "pod":
│   22:     query_strings_config {
│
│ The argument "query_string_behavior" is required, but no definition was found.
╵

but missing header_behavior still panics.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Addresses a defect in current functionality. service/cloudfront Issues and PRs that pertain to the cloudfront service.
Projects
None yet
4 participants