This Terraform module creates blueprints in Port using the blueprint json schema.
-
Create the blueprint in Port and copy the json definition
-
Save the json definition in a local directory or in a git repository
-
Use the module to create the blueprint in Port
The module will create the blueprints defined in the blueprint json schema following the order below:
- First run of
terraform apply
will create the blueprints defined in the blueprint json files- Second run of
terraform apply
willadd || update
the blueprints relations (if any)- Third run of
terraform apply
willadd || update
the blueprints mirrorProperties (if any)
- Third run of
- Second run of
Terraform Providers and Plan Validation: each workflow run includes details about Terraform Providers.
### Export your Port Credentials
export TF_VAR_client_id="your_client_id"
export TF_VAR_client_secret="your_client_secret"
# Create a local directory in your root folder
mkdir blueprint_json_files && cd blueprint_json_files
# Download a blueprint JSON file and save it
curl -0 https://raw.githubusercontent.com/port-labs/template-assets/main/kubernetes/blueprints/argo-blueprints.json > argo-blueprints.json
# Create a main.tf
cd ..
touch main.tf
# $ tree
.
|-- blueprint_json_files
| `-- argo-blueprints.json
`-- main.tf
Note
To access this module outside of the Terraform registry, replace:
# Module source
- source = "J0hn-B/blueprint/port"
- version = ">= 0.1
+ source = "github.com/J0hn-B/terraform-port-blueprint?ref=v0.1.1
// main.tf (basic example)
# Provider
terraform {
required_providers {
port = {
source = "port-labs/port-labs"
version = ">= 1.10.1"
}
}
}
provider "port" {
client_id = var.client_id
secret = var.client_secret
}
# Variables
variable "client_id" { type = string }
variable "client_secret" { type = string }
module "port" {
# Module source
source = "J0hn-B/blueprint/port"
version = ">= 0.1"
# Port API credentials
client_id = var.client_id
client_secret = var.client_secret
# Path to the directory containing the blueprint json files (required)
blueprint_dir = "${path.module}/blueprint_json_files"
}
# Output
// Return the blueprint definition
output "blueprint" {
value = module.port.blueprint
}
Advanced
- Complete the basic example
- Replace the
main.tf
file with the following code:
- Replace the
// main.tf
# Provider
terraform {
required_providers {
port = {
source = "port-labs/port-labs"
version = ">= 1.10.1"
}
github = {
source = "integrations/github"
version = ">= 5.45.0"
}
}
}
provider "port" {
client_id = var.client_id
secret = var.client_secret
}
# Variables
variable "client_id" { type = string }
variable "client_secret" { type = string }
# Get the json configuration from the gitops repository
data "github_repository" "port_labs" {
full_name = "port-labs/template-assets"
}
data "github_repository_file" "lean_kubernetes_usecase_bps" {
repository = data.github_repository.port_labs.full_name
branch = "main"
file = "kubernetes/blueprints/lean_kubernetes_usecase_bps.json"
}
# Module
module "port" {
// Set the module source
source = "J0hn-B/blueprint/port"
version = ">= 0.1"
// Port API credentials used by hashicorp/http provider
client_id = var.client_id
client_secret = var.client_secret
// Set the path to the directory containing the blueprint json files
blueprint_dir = "${path.module}/blueprint_json_files"
// Get the blueprints json data
blueprint_repo = data.github_repository_file.lean_kubernetes_usecase_bps.content
// Force delete entities (optional)
force_delete_entities = true
}
The module has a single output named blueprint
which returns the blueprint definition.
Access the output values using the syntax as shown in the example below:
output "blueprint" {
value = module.port.blueprint
// Access output values (examples)
// module.port.blueprint["workload"]["properties"]["array_props"]["containers"]["description"]
}