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

Cover empty sets in for_each #22756

Merged
merged 1 commit into from
Sep 11, 2019
Merged

Conversation

pselle
Copy link
Contributor

@pselle pselle commented Sep 10, 2019

We should check earlier for empty lists -- having it after set-specific checking meant we were missing empty lists/empty sets, and users would get an error they shouldn't get.

Fixes #22281

@ghost ghost added the sdkv1 [PRs only] Marks changes that may potentially need to be ported to the plugi nSDK label Sep 10, 2019
@pselle pselle requested a review from a team September 10, 2019 14:40
@pselle pselle force-pushed the b-for_each-empty-list branch from 7e2ab78 to a25abbe Compare September 10, 2019 14:57
@hashibot hashibot added bug config v0.12 Issues (primarily bugs) reported against v0.12 releases labels Sep 10, 2019
@pselle pselle merged commit de98de5 into hashicorp:master Sep 11, 2019
@pselle pselle deleted the b-for_each-empty-list branch September 11, 2019 13:36
@aarcro
Copy link

aarcro commented Sep 12, 2019

Will this apply to for_each in dynamic? I'm trying to do:

resource "aws_api_gateway_usage_plan" "these" {                                                               
  for_each = var.apig_plans                                                                                   
                                                                                                              
  name = "${local.namespace}-${each.key}-plan"                                                                
                                                                                                              
  api_stages {                                                                                                
    api_id = aws_api_gateway_rest_api.rest_api[0].id                                                          
    stage  = aws_api_gateway_rest_api.rest_api[0].name                                                        
  }                                                                                                           
                                                                                                              
  dynamic "quota_settings" {                                                                                  
    for_each = [for v in [each.value["quota"]] : v if v != {}]                                                
                                                                                                              
    content {                                                                                                 
      limit  = quota_settings.value["limit"]                                                                  
      offset = quota_settings.value["offset"]                                                                 
      period = quota_settings.value["period"]                                                                 
    }                                                                                                         
  }                                                                                                           
                                                                                                              
  dynamic "throttle_settings" {                                                                               
    for_each = [for v in [each.value["throttle"]] : v if v != {}]                                             
                                                                                                              
    content {                                                                                                 
      burst_limit = throttle_settings.value["burst_limit"]                                                    
      rate_limit  = throttle_settings.value["rate_limit"]                                                     
    }                                                                                                         
  }                                                                                                           
}                                                                                                             

But the empty list in for_each, still tries to execute content with an empty object:

  on .terraform/modules/zappa/zappa/api-keys.tf line 15, in resource "aws_api_gateway_usage_plan" "these":
  15:       limit  = quota_settings.value["limit"]
    |----------------
    | quota_settings.value is object with no attributes

The given key does not identify an element in this collection value.

@pselle
Copy link
Contributor Author

pselle commented Sep 13, 2019

@aarcro No, this is unrelated to dynamic's for_each. This would be a separate bug to file, if you could do that!

appilon pushed a commit to hashicorp/terraform-plugin-sdk that referenced this pull request Sep 16, 2019
appilon pushed a commit to hashicorp/terraform-plugin-sdk that referenced this pull request Sep 16, 2019
kmoe added a commit to hashicorp/terraform-plugin-sdk that referenced this pull request Sep 16, 2019
@appilon appilon removed the sdkv1 [PRs only] Marks changes that may potentially need to be ported to the plugi nSDK label Sep 16, 2019
@galindro
Copy link

@apparentlymart When this change is planned to be released?

@ghost
Copy link

ghost commented Oct 12, 2019

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.

@ghost ghost locked and limited conversation to collaborators Oct 12, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug config v0.12 Issues (primarily bugs) reported against v0.12 releases
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Resource for_each not working with empty list
6 participants