Templates for generating Terraform

Creating and publishing your first Blueprint

This guide assumes you have integrated Resourcely with your version control, so that Resourcely can submit change requests on your behalf.

Blueprints are powerful guided experiences for configuring and deploying cloud infrastructure. They are created and managed by central teams (Platform, SRE, DevOps, Infrastructure, etc), and used by developers.

With Blueprints:

  1. Customize Blueprint code and preview the form developers will see based on the Blueprint

  2. Developers can discover Blueprints and use Blueprint forms to configure infrastructure

  3. Terraform is generated and change requests automatically created, based on Blueprint forms

Create your first Blueprint

We'll create our first Blueprint based on an AWS RDS instance example.

Note that this Blueprint is for demonstration purposes only, and you should not use this in production. Resourcely has a variety of integrated Blueprints with embedded best practices around security, access, networking, cost, and more.

Consider the following example of Terraform for an AWS RDS Instance

Terraform
/// This is one of the basic examples from the AWS Terraform provider
/// https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/db_instance

resource "aws_db_instance" "default" {
  allocated_storage    = 10
  db_name              = "mydb"
  engine               = "mysql"
  engine_version       = "8.0"
  instance_class       = "db.t3.micro"
  username             = "foo"
  password             = "foobarbaz"
  parameter_group_name = "default.mysql8.0"
  skip_final_snapshot  = true
}

Blueprint code

We have replaced 4 parameter inputs with {{ inline-variables }}, and added a frontmatter with a __name constant.

---
constants:
  
---

resource "aws_db_instance" "{{ __name }}"  {
  allocated_storage    = {{ allocated_storage }}
  db_name              = "mydb"
 
  engine_version       = {{ engine_version }}
  instance_class       = {{ instance_class }}
  username             = "foo"
  password             = "foobarbaz"
  parameter_group_name = "default.mysql8.0"
  skip_final_snapshot  = true
}

/// This is a basic Blueprint with some variables and a best practices naming convention

In Resourcely navigate to the Foundry, copy the Blueprint code from above, and paste it into the Blueprint Content.

Adding variables

Let's further customize our Blueprint form by changing the Blueprint code.

Adding variables

Replace the rest of the hard-coded values in your Blueprint code with {{ inline-variables}}. It should look something like this:

Blueprint code: all parameters have variables
---
constants:
  __name: "{{ db_name }}_{{ __guid }}"
---

resource "aws_db_instance" "{{__name}}" {
  allocated_storage    = {{ allocated_storage }}
  db_name              = {{ db_name }}
  engine               = {{ engine_name }}
  engine_version       = {{ engine_version }}
  instance_class       = {{ instance_class }}
  username             = {{ username }}
  password             = {{ password }}
  parameter_group_name = {{ parameter_group_name }}
  skip_final_snapshot  = {{ skip_final_snapshot }}
}

// In this Blueprint, all parameters are associated with variables

Variables can also be defined in frontmatter - we cover this in detail in Authoring Your Own Blueprints

Customizing variables with tags

Inline variables can be customized with a variety of tags. These tags impact the form developers will use to configure resources. Check out Authoring Your Own Blueprintsfor a detailed listing of tags.

We'll start by adding a description, a default value, and setting some as required:

Blueprint code: adding variable tags
---
constants:
  __name: "{{ db_name }}_{{ __guid }}"
---

resource "aws_db_instance" "{{__name}}" {
  allocated_storage    = {{ allocated_storage | default: 50 }}
  db_name              = {{ db_name | desc: "Your database name" }}
  engine               = {{ engine_name | default: "postgres" | desc: "Database flavor to use. We recommend Postgres version 16.4" }}
  engine_version       = {{ engine_version | default: "16.4" }}
  instance_class       = {{ instance_class | desc: "Instance size, this should be Medium or smaller" }}
  username             = {{ username }}
  password             = {{ password }}
  parameter_group_name = {{ parameter_group_name | required: false }}
  skip_final_snapshot  = {{ skip_final_snapshot | required: false }}
}

// In this Blueprint, we have added several tags.

Add variable tags to your Blueprint, or copy the above code into the Foundry Blueprint content window, and observe how it changes the form in the Developer Experience tab.

Publishing

Publish your new Blueprint by adding a name, description, provider, and categories in the Define Metadata tab. Once you have done that, the Blueprint is ready for developers to interact with it.

Next steps

Blueprints are powerful: you can collect context questions, creating highly opinionated templates, or provide developers with modular linkable building blocks for creating Terraform.

From here, you can use other parts of Resourcely. Enforce rules by creating Terraform policies integrated into CI, or Remediate policy violations in existing infrastructure.

Last updated