Create and deploy a Terraform Developer Portal template
Platform engineers can create Terraform Developer Portal templates that pre-define infrastructure for Terraform no-code modules, including inputs for the modules. Developers use these templates to create new applications in Terraform Developer Portal.
By creating a template with common infrastructure, platform engineers ensure that infrastructure is properly configured and in compliance with your security, finance, and scaling policies.
Templates serve as a starting point for application developers. For example, a template can consist of a code repository template configured with your organization's default frontend framework, linting libraries, and CI/CD pipelines. Other examples of templates can be a production-ready Kubernetes cluster or backend API framework that is configured for serverless.
In this tutorial, you will publish a no-code module to HCP Terraform that creates new GitHub repository and preloads it with files for Terramino, a static website to run a brick-stacking browser game. Then, you will create a Terraform Developer Portal template that gives developers safe, self-service access to deploy the no-code module, without requiring them to interact with Terraform or other infrastructure tooling.
Prerequisites
For this tutorial, you will need the following:
- A GitHub account.
- An HCP Terraform account organization on the Standard edition or higher to use HCP Terraform no-code modules and the private module registry.
- A GitHub VCS provider configured in your HCP Terraform organization. Refer to Set up the GitHub.com VCS provider for more information.
Publish the no-code module
Navigate to the template repository for this tutorial. Click the Use this template button and select Create a new repository. Choose a GitHub account to create the repository in and name the new repository terraform-github-terramino. Leave the rest of the settings at their default values.
Review module configuration
This module contains Terraform configuration to create a GitHub repository and prepopulate it with all of the files for a static web application. The module repository contains the following files:
├── github.tf
├── outputs.tf
├── src
│ ├── README.md
│ └── www
│ ├── cache.js
│ ├── cacheCheck.html
│ ├── index.html
│ ├── terramino.css
│ └── terramino.js
├── terraform.tf
└── variables.tf
Open github.tf and review the configuration:
resource "github_repository" "repo" {
name = var.developer_portal_application
visibility = "private"
auto_init = true
}
resource "github_repository_file" "template" {
for_each = fileset("${path.module}/src", "**/*")
repository = github_repository.repo.name
branch = "main"
file = each.value
content = file("${path.module}/src/${each.value}")
commit_message = "Created from Terraform Developer Portal"
overwrite_on_create = true
}
This configuration creates a github_repository resource to create a new private GitHub repository. It references a variable named developer_portal_application. When you deploy this application, Terraform Developer Portal automatically populates this value. This configuration then creates a collection of github_repository_file resources to upload every file in the src directory.
Publish the module
Complete the following steps to publish the module to your HCP Terraform organization’s private module registry:
- Sign in to your HCP Terraform organization and click Registry in the sidebar.
- Click the Publish dropdown, then click Module.
- Choose your VCS provider.
- In the Repository dropdown, select the terraform-github-terramino repository you created earlier in this tutorial.
- Under Module Publishing Type, chose Branch.
- Enter a Branch Name of
main. - Enter a Module Version of
1.0.0. - Click Next.
- Enter a Module Name of
terramino. - Enter a Provider Name of
github. - Enable the Add module to no-code provision allowlist option.
- Click Publish module.
After a few moments, HCP Terraform displays your module overview.
Create a template
Next, complete the following steps to create a new Terraform Developer Portal template:
- Sign in to your HCP Terraform organization and click Developer Portal.
- Click Templates in the left navigation panel.
- Click New template.
- In the Name textbox, enter
terramino. - In the Base Module dropdown, choose the terramino (github) module you published in the previous step.
- Terraform Developer Portal prompts you to provide values for any variables that do not have default values. In the gh_org textbox, enter your GitHub username. This is the organization that the template creates the repository in.
- Click Continue.
- In the Summary textbox, enter
Static website to host Terramino. - Click Update from module's README to import the module's
READMEfile. - Click Save.
After you create your template, anyone in your HCP Terraform organization can deploy it and it will automatically create the repository in the GitHub organization that you specified.
Deploy an application
Next, complete the following steps to deploy a new application from the template you created in the previous step:
- Sign in to your HCP Terraform organization and click Developer Portal.
- Click the New dropdown and choose Application.
- Choose the terramino template you create in the previous step, then click Next.
- In the Name textbox, enter
terramino-get-started. - In the Terraform project dropdown, choose the Developer Portal project you created in the previous tutorial.
- Click Create application.
Terraform Developer Portal automatically redirects you to the overview page for your new application.
When you create a new application, Terraform Developer Portal creates a new workspace to deploy the no-code module. To monitor the progress of the deployment, click the Workspaces dropdown to list the workspaces associated with this application. After a few moments, Terraform Developer Portal reports that the workspace apply run completed. You may need to refresh the page to update the status.
When HCP Terraform completes the apply run, Terraform Developer Portal reports that the application has two outputs. Click View all in the Outputs section. This application outputs the repository name as well as the repository's URL. Copy the repository URL and open it in a new tab in your browser to see the application code.
Next steps
In this tutorial, you published a new no-code module, then used it to create a Terraform Developer Portal template. You then used that template to deploy a new application that created a GitHub repository with an application's code.
In the next tutorial, you will create an add-on to deploy the repository to AWS S3 and see the application running.