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

#152 Ensure terraform-docs 0.12 multi-line default statement is parsed correctly #155

Merged
merged 2 commits into from
Jun 17, 2019

Conversation

cytopia
Copy link
Contributor

@cytopia cytopia commented Jun 15, 2019

terraform-docs 0.12 multi-line default parsing

Description

There currently seems to be an issue with multi-line default statement parsing as mentioned by @antonbabenko here: #152 (comment)

This PR tries to address this.

Note

I've tested this on various samples to the best of my knowledge, but there may be other edge cases that I haven't yet taken into consideration.

Samples

Sample CI build

For a complex sample, I've re-triggered our CI pipeline, which is now using the here provided awk script, building terraform-docs output for one Terraform 0.12 main module and 4 bundled example usages. There seem to be no issues so far: https://travis-ci.com/Flaconi/terraform-aws-microservice/builds/115597635#L500

Sample file

input:

variable "database_outbound_acl_rules" {
  description = "Database subnets outbound network ACL rules"
  type        = list(map(string))
  default     = [
    {
      rule_number = 100
      rule_action = "allow"
      from_port   = 0
      to_port     = 0
      protocol    = "-1"
      cidr_block  = "0.0.0.0/0"
    },
  ]
}

variable "network" {
  description = "The network"
  type        = object({
    vpc = object({
      id         = string
      cidr_block = string
    })
    subnets = set(object({
      id         = string
      cidr_block = string
    }))
  })
  default     = {
    vpc = {
      id          = "vpc-123456"
      cidr_block  = "10.0.0.0/16"
    },
    subnets = [
      {
        id          = "vpc-123456"
        cidr_block  = "10.0.0.0/16"
      },
    ],
  }
}

output "environment" {
  description = "The output"
  value       = {
    id = aws_elastic_beanstalk_environment.example.id
    vpc_settings = {
      for s in aws_elastic_beanstalk_environment.example.all_settings :
      s.name => s.value
      if s.namespace == "aws:ec2:vpc"
    }
  }
}

output:

variable "database_outbound_acl_rules" {
  description = "Database subnets outbound network ACL rules"
  type = "list(map(string))"
  default     = [
    {
      rule_number = 100
      rule_action = "allow"
      from_port   = 0
      to_port     = 0
      protocol    = "-1"
      cidr_block  = "0.0.0.0/0"
    },
  ]
}
variable "network" {
  description = "The network"
  type = "object"
  default     = {
    vpc = {
      id          = "vpc-123456"
      cidr_block  = "10.0.0.0/16"
    },
    subnets = [
      {
        id          = "vpc-123456"
        cidr_block  = "10.0.0.0/16"
      },
    ],
  }
}
output "environment" {
  description = "The output"
}

terraform-docs

## Inputs

| Name | Description | Type | Default | Required |
|------|-------------|:----:|:-----:|:-----:|
| database\_outbound\_acl\_rules | Database subnets outbound network ACL rules | list(map(string)) | `[ { "cidr_block": "0.0.0.0/0", "from_port": 0, "protocol": "-1", "rule_action": "allow", "rule_number": 100, "to_port": 0 } ]` | no |
| network | The network | object | `{ "subnets": [ { "cidr_block": "10.0.0.0/16", "id": "vpc-123456" } ], "vpc": [ { "cidr_block": "10.0.0.0/16", "id": "vpc-123456" } ] }` | no |

## Outputs

| Name | Description |
|------|-------------|
| environment | The output |

@antonbabenko
Copy link

Thanks @cytopia for making this!

I've tested this with this module - terraform-aws-modules/terraform-aws-vpc#288

Also, I have updated pre-commit-terraform to v1.13.0.

@osterman osterman merged commit 58733c4 into cloudposse:master Jun 17, 2019
@osterman
Copy link
Member

@cytopia thanks for the contribution!

@cytopia
Copy link
Contributor Author

cytopia commented Jun 17, 2019

@osterman be aware that there is still a current issue reported by @antonbabenko with the submitted code.

See here: antonbabenko/pre-commit-terraform#47

And also here for the current mitigation: cytopia/docker-terraform-docs#13

If the PR works out fine, I will create another PR to address this, until it has finally been fixed upstream by terraform-docs.

@osterman
Copy link
Member

@cytopia: Ok, please keep us posted.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants