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

if && conditional judgment #35052

Closed
zhangfuli opened this issue Apr 23, 2024 · 2 comments
Closed

if && conditional judgment #35052

zhangfuli opened this issue Apr 23, 2024 · 2 comments
Labels
bug duplicate issue closed because another issue already tracks this problem

Comments

@zhangfuli
Copy link

Terraform Version

terraform version                                                                
Terraform v1.7.0
on darwin_arm64
+ provider registry.terraform.io/hashicorp/local v2.5.1

Terraform Configuration Files

I have a json file like this:

{
  ...
  "modules": [{
    "name": "test1",
    "kubeconfig": {
        "role": "master",
        "path": "/etc/kubernetes/kubeconfig"
    },
    "machine": ["...", "..."]
  },{
    "name": "test2",
    "machine": ["...", "..."]
  }]
}

this is the .tf

data "local_file" "module_vars" {
  filename = "../prod_vars.json"
}
locals {
  module_content = jsondecode(data.local_file.module_vars.content)
  master_machines = [for key, value in local.module_content.modules:
          value.machine if contains(keys(value), "kubeconfig") && value.kubeconfig.role == "master"
  ]
  master_hosts = flatten(local.master_machines)
}

Debug Output

null

Expected Behavior

Theoretically, should we judge contains first? If contains does not meet the conditions, it will be skipped directly. Why should we still judge value.kubeconfig?

Actual Behavior

This object does not have an attribute named "kubeconfig".

Steps to Reproduce

  1. terraform init
  2. terraform plan

Additional Context

No response

References

No response

@zhangfuli zhangfuli added bug new new issue not yet triaged labels Apr 23, 2024
@jbardin
Copy link
Member

jbardin commented Apr 23, 2024

Duplicate of #24128

@jbardin jbardin marked this as a duplicate of #24128 Apr 23, 2024
@jbardin jbardin closed this as completed Apr 23, 2024
@crw crw added duplicate issue closed because another issue already tracks this problem and removed new new issue not yet triaged labels Apr 23, 2024
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 24, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug duplicate issue closed because another issue already tracks this problem
Projects
None yet
Development

No branches or pull requests

3 participants