stelligent / config-lint

Command line tool to validate configuration files
https://stelligent.github.io/config-lint/#/
MIT License
198 stars 39 forks source link

tf12 errors on parameter list format #207

Open twellspring opened 4 years ago

twellspring commented 4 years ago

For the tf12 parser the block syntax works as expected:

  parameter {
        name  = "tls"
        value = "enabled"
      }
  parameter  {
        name = "audit_logs"
        value = "enabled"
      }

But the list of objects returns a warning/failure condition for the same rule

  parameter   = 
    [{
        name  = "tls"
        value = "enabled"
      },
      {
        name = "audit_logs"
        value = "enabled"
      }]

Per https://www.terraform.io/docs/configuration/attr-as-blocks.html this syntax is not recommended, but is still supported.

Assertion that works for blocks and fails for list of objects

    assertions:
      - some:
          key: parameter
          expressions:
            - and:
              - key: name
                op: eq
                value: tls
              - key: value
                op: eq
                value: enabled
milldr commented 4 years ago

I am able to reproduce the error and am working on a resolution. So far, looks like separate blocks are grouped together as a single block and then linted. Whereas a joined block that's already in that format isnt read correctly, and instead UNDEFINED is returned. Looking into why now.

In this example, fail_best has the working, separated block syntax and fail_alt has the failing, joined as a list block syntax.

  {                                                                         
    "ID": "fail_best",                                                      
    "Type": "aws_redshift_parameter_group",                                 
    "Category": "resource",                                                 
    "Properties": {                                                         
      "__name__": "fail_best",                                              
      "__type__": "aws_redshift_parameter_group",                           
      "family": "redshift-1.0",                                             
      "name": "fail_foo",                                                   
      "parameter": [                                                        
        {                                                                   
          "name": "tls",                                                    
          "value": "disabled"                                               
        },                                                                  
        {                                                                   
          "name": "audit_logs",                                             
          "value": "enabled"                                                
        }                                                                   
      ]                                                                     
    },                                                                      
    "Filename": "./testdata/resources/attr_block_syntax.tf",                
    "LineNumber": 33                                                        
  },                                                                        
  {                                                                         
    "ID": "fail_alt",                                                       
    "Type": "aws_redshift_parameter_group",                                 
    "Category": "resource",                                                 
    "Properties": {                                                         
      "__name__": "fail_alt",                                               
      "__type__": "aws_redshift_parameter_group",                           
      "family": "redshift-1.0",                                             
      "name": "fail_bar",                                                   
      "parameter": "UNDEFINED"                                              
    },                                                                      
    "Filename": "./testdata/resources/attr_block_syntax.tf",                
    "LineNumber": 48                                                        
  }