hashicorp / terraform-provider-aws

The AWS Provider enables Terraform to manage AWS resources.
https://registry.terraform.io/providers/hashicorp/aws
Mozilla Public License 2.0
9.8k stars 9.15k forks source link

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

Open masterqwerty opened 2 years ago

masterqwerty commented 2 years ago

Community Note

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)

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

masterqwerty commented 2 years ago

Update: Exact same thing happens with provider version 3.66.0

kirankumar-grootan commented 1 year ago

@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 commented 7 months ago

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.