Giter VIP home page Giter VIP logo

terraform-validator's Introduction

๐Ÿ‘‹ Hey there

LinkedIn URL Twitter URL Reddit URL Keybase URL

I'm Thibault, a Site Reliability Engineer from France.

Github stats

โฃ๏ธ What I love

  • Keep learning everything related with the DevOps way of working
  • Using and maintaining Cloud Native apps/tools and even better if that's open source

๐Ÿ› ๏ธ Currently working on

  • Cloud: AWS, Gcloud, Terraform
  • Containers: Kubernetes, Helm, Kustomize, Docker
  • Development: Golang, Bash, Ansible, Python3
  • Observability: Prometheus, AlertManager, Grafana, Loki, Thanos
  • CI/CD: GitHub, GitHub actions, ArgoCD, Argo workflow

terraform-validator's People

Contributors

chdorb avatar dependabot[bot] avatar germainlefebvre4 avatar owulveryck avatar thazelart avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

terraform-validator's Issues

Unexpected "validation" block

Hi,

Using "validation" in a variable block generates an error :

Unexpected "validation" block; Blocks are not allowed here

variable "image_id" {
  type        = string
  description = "The id of the machine image (AMI) to use for the server."

  validation {
    condition     = length(var.image_id) > 4 && substr(var.image_id, 0, 4) == "ami-"
    error_message = "The image_id value must be a valid AMI id, starting with \"ami-\"."
  }
}

Even "validation" comes with terraform 0.13, terraform-validator should not raise an error because validation block is inside variable definition ?

Blocks of type "required_providers" are not expected here

Firstly, this is a great tool. I use it constantly for a large number of Terraform modules I maintain. Thank you!

In my versions.tf file, I have a block which looks like this:

# https://www.terraform.io/docs/configuration/terraform.html
terraform {
  required_version = ">= 0.12"

  required_providers {
    aws      = "~> 2.67"
    newrelic = "~> 1.19"
  }
}

A truncated version of my .terraform-validator.yaml file looks like this:

layers:
  default:
    files:
      versions.tf:
        mandatory: true
        authorized_blocks:
          - required_providers # only added this after receiving the error message; it didn't help
          - terraform

When I run the tool, I get this message:

$ terraform-validator .
2020/07/03 01:07:04 versions.tf:5,3-21: Unsupported block type; Blocks of type "required_providers" are not expected here.

The required_providers sub-block of a terraform block is documented here: https://www.terraform.io/docs/configuration/terraform.html#specifying-required-provider-versions

How do I get terraform-validator to allow/enforce this block without throwing an error?

Add `terraform fmt` test

the idea is to add a new test: ensure_terraform_fmt

If set to true, this will ensure that the terraform fmt command pass. This ensure that the terraform code is well formatted.

In order to run the good terraform version for everyone, terraform will be a dependency of terraform-validator if that option is set to true

Add the possibility of prohibiting certain types of resources

An exemple with the GCP Provider :

About IAM management, 3 different types of resources can be used : google_project_iam_policy, google_project_iam_binding and google_project_iam_member.

The GCP IAM API manage users roles as a users list per roles.
In terraform, google_project_iam_member will append a new user in the list of the role, but google_project_iam_binding will totally replace this list by the one in parameter.

So, it's not possible to declare two times the resource google_project_iam_binding (or google_project_iam_binding and google_project_iam_member) to manage the same gcp role in the same Terraform stack.

Same case with the resources google_project_service and google_project_services

It could be interesting to check this part with terraform-validator.

Hcl2 error in provider.tf

Hi!
I have an "assume_role" block in my provider.tf

provider "google" {
  version = "foo"

  assume_role {
    role_arn = "role"
  }
}

and I ran in this error:

2019/11/15 15:24:23 testdata/ok_default_config/providers.tf:5,3-14: Unexpected "assume_role" block; Blocks are not allowed here.

It seems that hcl2 libs are giving an error for a valid terraform format. Also the hcl2 repo is archived.

Are you aware of this issue?

Enforce presence of a block in a file

It would be interesting to enforce that a file exist and then that a block is present inside.

e.g. :
Enforce presence of provider block only providers.tffile.

Configuration could be like this :

 layers:
   default:
     files:
       main.tf:
         mandatory: true
         authorized_blocks:
       providers.tf:
         mandatory: true
         exclusive_blocks:
           - provider

Terraform-validator should check recursively

Terraform-validator current version cannot handle internal modules and layering.

This should be the next evolve !

Each sub directory inherit the .terrform-validator.yaml configuration. If something is different, another .terrform-validator.yaml can be added here to change the configuration of the directory and it's sub directories

add `terraform-docs` test

the idea is to add a new test: ensure_readme_updated

If set to true, this will ensure the terraform-docs command was run and so that the documentation seems updated.

In order to run the good terraform version for everyone, terraform-docs will be a dependency of terraform-validator if that option is set to true. If not install, we might use the latest version (not yet fuly decided about that)

Add ensure outputs/variables description set

Terraform-validator should be able to ensure that outputs and/or variables blocks contains a description.

For this, we will needs to add two parameters (one to check the variables description, one for the outputs).
Create the check and include it in the fileCheck function.

Reduce main complexity

Problem

Main complexity is to high.

Solution

Extract the log code in a new internal/log package

Example of code to extract

if len(blockNamesErrors) > 0 || len(blocksInFilesErrors) > 0 || len(providersVersionErrors) > 0 {
	exitCode = 1
	fmt.Printf("\nERROR: %s misformed:\n", file.Path)
	if len(providersVersionErrors) > 0 {
		fmt.Printf("  Unversioned provider(s):\n")
		for _, err := range providersVersionErrors {
			fmt.Printf("    - %s\n", err.Error())
		}
	}
	if len(blockNamesErrors) > 0 {
		fmt.Printf("  Unmatching \"%s\" pattern blockname(s):\n",
			globalConfig.TerraformConfig.BlockPatternName)
		for _, err := range blockNamesErrors {
			fmt.Printf("    - %s\n", err.Error())
		}
	}
	if len(blocksInFilesErrors) > 0 {
		fmt.Println("  Unauthorized block(s):")
		for _, err := range blocksInFilesErrors {
			fmt.Printf("    - %s\n", err.Error())
		}
	}
}

Add `terraform validate` test

the idea is to add a new test: ensure_terraform_validate

If set to true, this will ensure that the terraform validate command pass. This ensure that the terraform code is well written.

In order to run the good terraform version for everyone, terraform will be a dependency of terraform-validator if that option is set to true

Allow existence check of a non *.tf file

Hi,

It seems terraform-validator is unable to check if a non *.tf file exists :

 layers:
   default:
     files:
       README.md:
         mandatory: true
 terraform-validator .
INFO: running on terraform/meta with default configuration
ERROR: missing mandatory file(s):
  - README.md
ls -1  terraform/meta/README.md
terraform/meta/README.md

In this sample, it good be interesting to ensure that a README.md file exists

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.