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

Panic error when creating aws_cloudfront_origin_request_policy: interface {} is nil, not map[string]interface {} #20870

Closed
Lauan opened this issue Sep 10, 2021 · 5 comments · Fixed by #12509
Labels
bug Addresses a defect in current functionality. crash Results from or addresses a Terraform crash or kernel panic. service/cloudfront Issues and PRs that pertain to the cloudfront service.
Milestone

Comments

@Lauan
Copy link

Lauan commented Sep 10, 2021

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.1 on darwin_arm64
provider registry.terraform.io/hashicorp/aws v3.58.0

Affected Resource(s)

  • aws_cloudfront_origin_request_policy

Terraform Configuration Files

Please include all Terraform configurations required to reproduce the bug. Bug reports without a functional reproduction may be closed without investigation.

variable "k8s_cache_forwarded_cookies" {
  default     = []
}

variable "k8s_cache_forwarded_headers" {
  default     = []
}

variable "k8s_cache_forwarded_query_strings" {
  default     = []
}

provider "aws" {
  region = "us-east-1"
}

resource "aws_cloudfront_origin_request_policy" "kubernetes" {
  name    = "KubernetesOriginPolicy"
  comment = "Origin Request Policy with custom config"
  cookies_config {
    cookie_behavior = var.k8s_cache_forwarded_cookies == [] ? "none" : "whitelist"
    dynamic "cookies" {
      for_each = var.k8s_cache_forwarded_cookies == [] ? [] : ["go"]
      content {
        items = var.k8s_cache_forwarded_cookies
      }
    }
  }
  headers_config {
    header_behavior = var.k8s_cache_forwarded_headers == [] ? "none" : "whitelist"
    dynamic "headers" {
      for_each = var.k8s_cache_forwarded_headers == [] ? [] : ["go"]
      content {
        items = var.k8s_cache_forwarded_headers
      }
    }
  }
  query_strings_config {
    query_string_behavior = var.k8s_cache_forwarded_query_strings == [] ? "none" : "whitelist"
    dynamic "query_strings" {
      for_each = var.k8s_cache_forwarded_query_strings == [] ? [] : ["go"]
      content {
        items = var.k8s_cache_forwarded_query_strings
      }
    }
  }
}

Debug Output

https://gist.github.com/Lauan/c75f45b971d33813bf7937f16022f4c7

Panic Output

https://gist.github.com/Lauan/c75f45b971d33813bf7937f16022f4c7

Expected Behavior

Creation of the cloudfront origin policy with all behaviors as "none" and no nested blocks

Actual Behavior

It seems to me that the provider is trying to create empty nested blocks, which is not allowed in this context.

Steps to Reproduce

  1. terraform apply
    Obs: terraform plan works fine, only crashing when applying

Important Factoids

If you pass non-empty lists for each variable, the resource is created as it should. The issue only happens for empty lists.
Tried to run on my M1 MacBook pro as well as on terraform cloud and the outcome is the same

@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 Sep 10, 2021
@ewbankkit
Copy link
Contributor

panic: interface conversion: interface {} is nil, not map[string]interface {}

goroutine 87 [running]:
github.com/terraform-providers/terraform-provider-aws/aws.expandCloudFrontOriginRequestPolicyCookiesConfig(0x140003ff830, 0x108d48c8d)
	/opt/teamcity-agent/work/5d79fe75d4460a2f/src/github.com/hashicorp/terraform-provider-aws/aws/cloudfront_origin_request_policy_structure.go:36 +0x1e0
github.com/terraform-providers/terraform-provider-aws/aws.expandCloudFrontOriginRequestPolicyConfig(0x140003e6980, 0x1400018aa90)
	/opt/teamcity-agent/work/5d79fe75d4460a2f/src/github.com/hashicorp/terraform-provider-aws/aws/cloudfront_origin_request_policy_structure.go:114 +0x164
github.com/terraform-providers/terraform-provider-aws/aws.resourceAwsCloudFrontOriginRequestPolicyCreate(0x140003e6980, 0x10a435740, 0x1400199e000, 0xffffffffffffffff, 0x140019d9798)
	/opt/teamcity-agent/work/5d79fe75d4460a2f/src/github.com/hashicorp/terraform-provider-aws/aws/resource_aws_cloudfront_origin_request_policy.go:130 +0x48
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*Resource).create(0x140009ada40, 0x10b6b02e8, 0x140003e2580, 0x140003e6980, 0x10a435740, 0x1400199e000, 0x0, 0x0, 0x0)
	/opt/teamcity-agent/work/5d79fe75d4460a2f/pkg/mod/github.com/gdavison/terraform-plugin-sdk/[email protected]/helper/schema/resource.go:318 +0x170
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*Resource).Apply(0x140009ada40, 0x10b6b02e8, 0x140003e2580, 0x140003da460, 0x140012099a0, 0x10a435740, 0x1400199e000, 0x0, 0x0, 0x0, ...)
	/opt/teamcity-agent/work/5d79fe75d4460a2f/pkg/mod/github.com/gdavison/terraform-plugin-sdk/[email protected]/helper/schema/resource.go:456 +0x4ec
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*GRPCProviderServer).ApplyResourceChange(0x140001a0d50, 0x10b6b02e8, 0x140003e2580, 0x140003bf270, 0x140003e2580, 0x10b08af80, 0x0)
	/opt/teamcity-agent/work/5d79fe75d4460a2f/pkg/mod/github.com/gdavison/terraform-plugin-sdk/[email protected]/helper/schema/grpc_provider.go:955 +0x6f8
github.com/hashicorp/terraform-plugin-go/tfprotov5/server.(*server).ApplyResourceChange(0x140021356e0, 0x10b6b0390, 0x140003e2580, 0x140003da230, 0x140021356e0, 0x1048b54d0, 0x10ae1a220)
	/opt/teamcity-agent/work/5d79fe75d4460a2f/pkg/mod/github.com/hashicorp/[email protected]/tfprotov5/server/server.go:332 +0x94
github.com/hashicorp/terraform-plugin-go/tfprotov5/internal/tfplugin5._Provider_ApplyResourceChange_Handler(0x10b08af80, 0x140021356e0, 0x10b6b0390, 0x140003f00f0, 0x140012e71a0, 0x0, 0x10b6b0390, 0x140003f00f0, 0x140003f2000, 0x2a0)
	/opt/teamcity-agent/work/5d79fe75d4460a2f/pkg/mod/github.com/hashicorp/[email protected]/tfprotov5/internal/tfplugin5/tfplugin5_grpc.pb.go:380 +0x1c8
google.golang.org/grpc.(*Server).processUnaryRPC(0x1400029fdc0, 0x10b6d2fd8, 0x14000866300, 0x140003d2200, 0x140006e0ed0, 0x10efe6660, 0x0, 0x0, 0x0)
	/opt/teamcity-agent/work/5d79fe75d4460a2f/pkg/mod/google.golang.org/[email protected]/server.go:1194 +0x3e8
google.golang.org/grpc.(*Server).handleStream(0x1400029fdc0, 0x10b6d2fd8, 0x14000866300, 0x140003d2200, 0x0)
	/opt/teamcity-agent/work/5d79fe75d4460a2f/pkg/mod/google.golang.org/[email protected]/server.go:1517 +0xa50
google.golang.org/grpc.(*Server).serveStreams.func1.2(0x14001558170, 0x1400029fdc0, 0x10b6d2fd8, 0x14000866300, 0x140003d2200)
	/opt/teamcity-agent/work/5d79fe75d4460a2f/pkg/mod/google.golang.org/[email protected]/server.go:859 +0x94
created by google.golang.org/grpc.(*Server).serveStreams.func1
	/opt/teamcity-agent/work/5d79fe75d4460a2f/pkg/mod/google.golang.org/[email protected]/server.go:857 +0x1f8

Error: The terraform-provider-aws_v3.58.0_x5 plugin crashed!

@ewbankkit ewbankkit added bug Addresses a defect in current functionality. crash Results from or addresses a Terraform crash or kernel panic. and removed needs-triage Waiting for first response or review from a maintainer. labels Sep 10, 2021
@Lauan
Copy link
Author

Lauan commented Sep 10, 2021

Thanks @ewbankkit . And sorry for creating a duplicated thread. twiden's issue is exactly the same as mine.

@github-actions
Copy link

This functionality has been released in v3.65.0 of the Terraform AWS Provider. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading.

For further feature requests or bug reports with this functionality, please create a new GitHub issue following the template. Thank you!

@github-actions
Copy link

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.
If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 29, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Addresses a defect in current functionality. crash Results from or addresses a Terraform crash or kernel panic. service/cloudfront Issues and PRs that pertain to the cloudfront service.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants