/terraform-external-datasource-python

Example external Terraform data object to fetch data from an API

Primary LanguageHCLApache License 2.0Apache-2.0

Terraform External Datasource Python

Example external Terraform data object to fetch data from an API

Requirements

Name Version
terraform ~> 1.2
python ~> 3.10
curl ~
jq ~

Usage

Set Up

  1. Modify versions.tf with your own state information. Local or otherwise
  2. Ideally you would want to set up a virtual environment python -m venv /path/to/virtual/environment
  3. Install requirements python -m pip install -r requirements.txt

Run Terraform

Init state

terraform init

Plan

terraform plan

Apply

terraform apply

Outputs

Name Description
message The message value from the JSON object
html_url The URL of the repo

Notes

In practice python isn't the best choice for an external datasource as it will likely have dependencies best satisfied in a virtualenv making it less portable. I'd recommend a simple shell script or a checked in static binary.