All Projects → hashicorp → terraform-schema

hashicorp / terraform-schema

Licence: MPL-2.0 license
This library helps assembling a complete schema for decoding Terraform config

Programming Languages

go
31211 projects - #10 most used programming language
HCL
1544 projects

Projects that are alternatives of or similar to terraform-schema

terraform-aws-datadog-integration
Terraform module to configure Datadog AWS integration
Stars: ✭ 26 (-36.59%)
Mutual labels:  hcl2
terraform-aws-cloudtrail
Terraform module to provision an AWS CloudTrail and an encrypted S3 bucket with versioning to store CloudTrail logs
Stars: ✭ 78 (+90.24%)
Mutual labels:  hcl2
terraform-aws-account
🌳 A sustainable Terraform Package which creates Account & IAM resources on AWS
Stars: ✭ 18 (-56.1%)
Mutual labels:  hcl2
terraform-aws-ec2-instance
Terraform module for provisioning a general purpose EC2 host
Stars: ✭ 123 (+200%)
Mutual labels:  hcl2
terraform-aws-backup
Terraform module to provision AWS Backup, a fully managed backup service that makes it easy to centralize and automate the back up of data across AWS services such as EBS volumes, RDS databases, DynamoDB tables, EFS file systems, and AWS Storage Gateway volumes.
Stars: ✭ 62 (+51.22%)
Mutual labels:  hcl2
terraform-labels
This terraform module is designed to generate consistent label names and tags for resources. You can use terraform-aws-labels to implement a strict naming convention.
Stars: ✭ 0 (-100%)
Mutual labels:  hcl2
terraform-aws-ses
Terraform module to provision Simple Email Service on AWS
Stars: ✭ 24 (-41.46%)
Mutual labels:  hcl2
terraform-aws-documentdb-cluster
Terraform module to provision a DocumentDB cluster on AWS
Stars: ✭ 32 (-21.95%)
Mutual labels:  hcl2
terraform-external-module-artifact
Terraform module to fetch any kind of artifacts using curl (binary and text okay)
Stars: ✭ 13 (-68.29%)
Mutual labels:  hcl2
terraform-aws-cloudformation-stack
Terraform module to provision CloudFormation Stack
Stars: ✭ 24 (-41.46%)
Mutual labels:  hcl2
terraform-aws-ecs-alb-service-task
Terraform module which implements an ECS service which exposes a web service via ALB.
Stars: ✭ 108 (+163.41%)
Mutual labels:  hcl2
terraform-aws-route53-cluster-zone
Terraform module to easily define consistent cluster domains on Route53 (e.g. `prod.ourcompany.com`)
Stars: ✭ 42 (+2.44%)
Mutual labels:  hcl2
terraform-aws-alb-ingress
Terraform module to provision an HTTP style ingress rule based on hostname and path for an ALB using target groups
Stars: ✭ 20 (-51.22%)
Mutual labels:  hcl2
terraform-aws-iam-system-user
Terraform Module to Provision a Basic IAM System User Suitable for CI/CD Systems (E.g. TravisCI, CircleCI)
Stars: ✭ 71 (+73.17%)
Mutual labels:  hcl2
terraform-github-repository-webhooks
Terraform module to provision webhooks on a set of GitHub repositories
Stars: ✭ 20 (-51.22%)
Mutual labels:  hcl2
terraform-aws-acm-request-certificate
Terraform module to request an ACM certificate for a domain name and create a CNAME record in the DNS zone to complete certificate validation
Stars: ✭ 83 (+102.44%)
Mutual labels:  hcl2
hcl-lang
Schema and decoder to be used as building blocks for an HCL2-based language server.
Stars: ✭ 44 (+7.32%)
Mutual labels:  hcl2
Tflint
A Pluggable Terraform Linter
Stars: ✭ 2,756 (+6621.95%)
Mutual labels:  hcl2
terraform-aws-ecs-cloudwatch-sns-alarms
Terraform module to create CloudWatch Alarms on ECS Service level metrics.
Stars: ✭ 23 (-43.9%)
Mutual labels:  hcl2
terraform-aws-ecs-web-app
Terraform module that implements a web app on ECS and supports autoscaling, CI/CD, monitoring, ALB integration, and much more.
Stars: ✭ 175 (+326.83%)
Mutual labels:  hcl2

terraform-schema Go Reference

This library helps assembling a complete hcl-lang schema for decoding Terraform config based on static Terraform core schema and relevant provider schemas.

There is more than one schema?

Yes.

  • Terraform Core defines top-level schema
    • provider, resource or data blocks incl. meta attributes, such as alias or count
    • variable, output blocks etc.
  • each Terraform provider defines its own schema for the body of some of these blocks
    • attributes and nested blocks inside resource, data or provider blocks

Each of these can also differ between (core / provider) version.

Current Status

This project is in use by the Terraform Language Server and could in theory be used by other projects which need to decode the whole configuration.

However it has not been tested in any other scenarios.

Please note that this library depends on hcl-lang which itself is not considered stable yet.

Breaking changes may be introduced.

Alternative Solution

If you only need to perform shallow config decoding, e.g. you just need to get a list of variables, outputs, provider names/source etc. and you don't care as much about version-specific or provider-specific details then you should explore terraform-config-inspect instead, which will likely be sufficient for your needs.

How It Works

Usage

import (
	tfschema "github.com/hashicorp/terraform-schema/schema"
	"github.com/hashicorp/terraform-json"
)

// parse files e.g. via hclsyntax
parsedFiles := map[string]*hcl.File{ /* ... */ }

// obtain relevant core schema
coreSchema := tfschema.UniversalCoreModuleSchema()

// obtain relevant provider schemas e.g. via terraform-exec
// and marshal them into terraform-json type
providerSchemas := &tfjson.ProviderSchemas{ /* ... */ }

mergedSchema, err := tfschema.MergeCoreWithJsonProviderSchemas(parsedFiles, coreSchema, providerSchemas)
if err != nil {
	// ...
}

Provider Schemas

The only reliable way of obtaining provider schemas at the time of writing is via Terraform CLI by running terraform providers schema -json (0.12+).

terraform-exec can help automating the process of obtaining the schema.

terraform-json provides types that the JSON output can be marshalled into, which also used by terraform-exec and is considered as standard way of representing the output.

Known Issues

At the time of writing there is a known issue affecting the above command where it requires the following to be true in order to produce schemas:

  • configuration is valid (e.g. contains no incomplete blocks)
  • authentication is provided for any remote backend

Read more at hashicorp/terraform#24261.

Other ways of obtaining schemas are also being explored.

Why a Separate Repository (from Terraform Core)?

As demonstrated by the recent separation of Plugin SDK, Terraform Core is not intended to be consumed as a Go module and any packages which happen to be importable were not tested nor designed for use outside the context of Terraform Core.

Terraform Core's versioning reflects mainly the experience of end-users interacting with Terraform via the CLI. Functionality which is consumed as Go package and imported into other Go programs deserves its own dedicated versioning.

Terraform Core's schema internally always supports the latest version (e.g. Terraform 0.12 can parse 0.12 configuration). Consumers of this library however need to parse different versions of configuration at the same time.

Experimental Status

By using the software in this repository (the "Software"), you acknowledge that: (1) the Software is still in development, may change, and has not been released as a commercial product by HashiCorp and is not currently supported in any way by HashiCorp; (2) the Software is provided on an "as-is" basis, and may include bugs, errors, or other issues; (3) the Software is NOT INTENDED FOR PRODUCTION USE, use of the Software may result in unexpected results, loss of data, or other unexpected results, and HashiCorp disclaims any and all liability resulting from use of the Software; and (4) HashiCorp reserves all rights to make all decisions about the features, functionality and commercial release (or non-release) of the Software, at any time and without any obligation or liability whatsoever.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].