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: interface conversion: interface {} is nil, not map[string]interface {} in aws_cloudfront_cache_policy #21397

Closed
zaitsevpavel opened this issue Oct 20, 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

@zaitsevpavel
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.8
on linux_amd64

  • provider registry.terraform.io/hashicorp/aws v3.63.0

Affected Resource(s)

  • aws_cloudfront_cache_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.

resource "aws_cloudfront_cache_policy" "some-cache-policy" {
  name        = "some-cache-policy"
  comment     = "To disable CF caching for some-cf-distribution"
  default_ttl = 0
  max_ttl     = 0
  min_ttl     = 0

  parameters_in_cache_key_and_forwarded_to_origin {
    enable_accept_encoding_brotli = false
    enable_accept_encoding_gzip   = false

    cookies_config {
      cookie_behavior = "none"
      cookies {}
    }
    headers_config {
      header_behavior = "none"
      headers {}
    }
    query_strings_config {
      query_string_behavior = "none"
      query_strings {}
    }
  }
}

Debug Output

https://gist.github.com/zaitsevpavel/9fbcb72c43fab7140bbe699582128228

Panic Output

There is no crash.log, just:

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

Expected Behavior

Resource is created.

Actual Behavior

Panic, resource is not created

Steps to Reproduce

  1. terraform apply

Important Factoids

We use a new resource instead of a managed data-source, because TF always tries to reach AWS even if the flag -refresh=false set.
I've tried different versions of aws provider, and the bug has been reproduced in the latest provider version.

@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 Oct 20, 2021
@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 Oct 20, 2021
@ewbankkit
Copy link
Contributor

Stack trace from the terraform-provider-aws_v3.63.0_x5 plugin:

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

goroutine 78 [running]:
github.com/terraform-providers/terraform-provider-aws/aws.expandCloudFrontCachePolicyCookiesConfig(0xc001c05aa0, 0xc001c05a40)
        /opt/teamcity-agent/work/5d79fe75d4460a2f/src/github.com/hashicorp/terraform-provider-aws/aws/cloudfront_cache_policy_structure.go:34 +0x1e5
github.com/terraform-providers/terraform-provider-aws/aws.expandCloudFrontCachePolicyParametersConfig(0xc001c05a40, 0x77f17ec)
        /opt/teamcity-agent/work/5d79fe75d4460a2f/src/github.com/hashicorp/terraform-provider-aws/aws/cloudfront_cache_policy_structure.go:112 +0xb2
github.com/terraform-providers/terraform-provider-aws/aws.expandCloudFrontCachePolicyConfig(0xc001979500, 0xc001b27718)
        /opt/teamcity-agent/work/5d79fe75d4460a2f/src/github.com/hashicorp/terraform-provider-aws/aws/cloudfront_cache_policy_structure.go:138 +0xb9
github.com/terraform-providers/terraform-provider-aws/aws.resourceAwsCloudFrontCachePolicyCreate(0xc001979500, 0x6856740, 0xc001ae6000, 0x3, 0xffffffffffffffff)
        /opt/teamcity-agent/work/5d79fe75d4460a2f/src/github.com/hashicorp/terraform-provider-aws/aws/resource_aws_cloudfront_cache_policy.go:161 +0x55
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*Resource).create(0xc0007fb5e0, 0x83169a8, 0xc00196e1c0, 0xc001979500, 0x6856740, 0xc001ae6000, 0x0, 0x0, 0x0)
        /opt/teamcity-agent/work/5d79fe75d4460a2f/pkg/mod/github.com/gdavison/terraform-plugin-sdk/v2@v2.7.1-0.20210913224932-c7c2dbd9e010/helper/schema/resource.go:318 +0x1ee
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*Resource).Apply(0xc0007fb5e0, 0x83169a8, 0xc00196e1c0, 0xc001904cb0, 0xc0009492e0, 0x6856740, 0xc001ae6000, 0x0, 0x0, 0x0, ...)
        /opt/teamcity-agent/work/5d79fe75d4460a2f/pkg/mod/github.com/gdavison/terraform-plugin-sdk/v2@v2.7.1-0.20210913224932-c7c2dbd9e010/helper/schema/resource.go:456 +0x67b
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*GRPCProviderServer).ApplyResourceChange(0xc00000cfc0, 0x83169a8, 0xc00196e1c0, 0xc001925810, 0xc00196e1c0, 0x74d4b80, 0xc001933800)
        /opt/teamcity-agent/work/5d79fe75d4460a2f/pkg/mod/github.com/gdavison/terraform-plugin-sdk/v2@v2.7.1-0.20210913224932-c7c2dbd9e010/helper/schema/grpc_provider.go:955 +0x8ef
github.com/hashicorp/terraform-plugin-go/tfprotov5/server.(*server).ApplyResourceChange(0xc00222d600, 0x8316a50, 0xc00196e1c0, 0xc001904a80, 0xc00222d600, 0xc001933830, 0xc001898ba0)
        /opt/teamcity-agent/work/5d79fe75d4460a2f/pkg/mod/github.com/hashicorp/terraform-plugin-go@v0.3.0/tfprotov5/server/server.go:332 +0xb5
github.com/hashicorp/terraform-plugin-go/tfprotov5/internal/tfplugin5._Provider_ApplyResourceChange_Handler(0x74d4b80, 0xc00222d600, 0x8316a50, 0xc001933830, 0xc001964fc0, 0x0, 0x8316a50, 0xc001933830, 0xc001934800, 0x3d3)
        /opt/teamcity-agent/work/5d79fe75d4460a2f/pkg/mod/github.com/hashicorp/terraform-plugin-go@v0.3.0/tfprotov5/internal/tfplugin5/tfplugin5_grpc.pb.go:380 +0x214
google.golang.org/grpc.(*Server).processUnaryRPC(0xc0000cb880, 0x833a6d8, 0xc000e1e300, 0xc002270f00, 0xc001547500, 0xbdc3000, 0x0, 0x0, 0x0)
        /opt/teamcity-agent/work/5d79fe75d4460a2f/pkg/mod/google.golang.org/grpc@v1.32.0/server.go:1194 +0x52b
google.golang.org/grpc.(*Server).handleStream(0xc0000cb880, 0x833a6d8, 0xc000e1e300, 0xc002270f00, 0x0)
        /opt/teamcity-agent/work/5d79fe75d4460a2f/pkg/mod/google.golang.org/grpc@v1.32.0/server.go:1517 +0xd0c
google.golang.org/grpc.(*Server).serveStreams.func1.2(0xc001556200, 0xc0000cb880, 0x833a6d8, 0xc000e1e300, 0xc002270f00)
        /opt/teamcity-agent/work/5d79fe75d4460a2f/pkg/mod/google.golang.org/grpc@v1.32.0/server.go:859 +0xab
created by google.golang.org/grpc.(*Server).serveStreams.func1
        /opt/teamcity-agent/work/5d79fe75d4460a2f/pkg/mod/google.golang.org/grpc@v1.32.0/server.go:857 +0x1fd

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

@ewbankkit
Copy link
Contributor

Relates: #20870.

@yhakbar
Copy link

yhakbar commented Nov 8, 2021

I ran into this issue while trying to setup a TF module for aws_cloudfront_cache_policy.

The following is a workaround that prevents this error from popping up when the length of the items field under cookies, headers or query_strings is unknown:

cookies_config {
      cookie_behavior = var.cookie_behavior
      # Workaround due to provider bug
      # https://github.com/hashicorp/terraform-provider-aws/issues/21397

      # cookies {
      #   items = var.cookies
      # }

      dynamic "cookies" {
        for_each = length(var.cookies) == 0 ? [] : [var.cookies]
        content {
          items = var.cookies
        }
      }
    }
    headers_config {
      header_behavior = var.header_behavior

      # Workaround due to provider bug
      # https://github.com/hashicorp/terraform-provider-aws/issues/21397

      # headers {
      #   items = var.headers
      # }

      dynamic "headers" {
        for_each = length(var.headers) == 0 ? [] : [var.headers]
        content {
          items = var.headers
        }
      }
    }
    query_strings_config {
      query_string_behavior = var.query_string_behavior

      # Workaround due to provider bug
      # https://github.com/hashicorp/terraform-provider-aws/issues/21397

      # query_strings {
      #   items = var.query_strings
      # }

      dynamic "query_strings" {
        for_each = length(var.query_strings) == 0 ? [] : [var.query_strings]
        content {
          items = var.query_strings
        }
      }
    }

I'm guessing what this does is bypass the attempted cast here, that will fail if items is not populated with a valid list of strings, but I'm not sure

apiObject.Cookies = expandCloudFrontCachePolicyCookieNames(items[0].(map[string]interface{}))
.

@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 30, 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.

3 participants