terraform-linters / tflint

A Pluggable Terraform Linter
Mozilla Public License 2.0
4.96k stars 357 forks source link

`tflint-ignore` annotaion not works for redshift resource #1353

Closed Wonong closed 2 years ago

Wonong commented 2 years ago

Descriotion

I ran tflint with my custom module including redshift resource and it printed failure message since i set my redshift password default value as null So, i add tflint-ignore annotation above error line. but, it still prints error message like below.

Failed to check ruleset; Failed to check `aws_redshift_cluster_invalid_master_password` rule: failed to eval an expression in redshift.tf:9; Attempt to get attribute from null value: This value is null, so it does not have any attributes.

redshift.tf

resource "aws_redshift_cluster" "redshift_agent" {
  count                                = var.does_create_db == true ? 1 : 0
  cluster_identifier                   = var.agent_redshift_cluster_identifier
  node_type                            = var.agent_redshift_cluster_node_type
  cluster_type                         = var.agent_redshift_cluster_type
  number_of_nodes                      = 2
  master_username                      = var.agent_redshift_user_password.username
  # tflint-ignore: aws_redshift_cluster_invalid_master_password
  master_password                      = var.agent_redshift_user_password.password
  vpc_security_group_ids               = [aws_security_group.sg_for_redshift[0].id]
  publicly_accessible                  = false
  availability_zone_relocation_enabled = true
  cluster_subnet_group_name            = aws_redshift_subnet_group.redshift_agent_subnet_group[0].name
}

variables.tf

# ...
variable "agent_redshift_user_password" {
  description = "Redshift master username and password"
  type = object({
    username = string
    password = string
  })
  default = null
}

Version

TFLint version 0.35.0 Terraform v1.1.6 on linux_amd64

wata727 commented 2 years ago

Annotation is worked for issues, not runtime errors. This is the intended behavior.

It is recommended to fix it so that the error does not occur. If you always expect to be given the input value, you can remove the default = null. If the default value is adopted, you may get the same error during the terraform plan. You can use the try function to suppress the error.

Wonong commented 2 years ago

Thank you for your answer :)