Skip to main content

Convert Pydantic Models into Terraform Variables

Project description

Pydantic to Terraform

This library converts Pydantic Models into Terraform Variables.

Usage

This needs to be installed in the same virtual environment as the Models that it is converting. Once installed a CLI tool, py2tf, will be available in the environment.

For example, to generate a variables file for the RDS ParameterValidation class-

robert@Roberts-MacBook-Pro terraform-aws-core % py2tf modules.rds.validation.parameters:ParameterValidation

The command will output the following to stdout:

variable "type" {
  type = string
  default = null
}

variable "pit_identifier" {
  type = string
  default = null
}

variable "tags" {
  type = map(any)
  default = {}
}

variable "name" {
  type = string
  validation {
    # Automatically Generated from Rule: minlength
    condition     = len(var.name) >= 1
    error_message = "Field should not be less than 1 characters"
  }
  validation {
    # Automatically Generated from Rule: maxlength
    condition     = len(var.name) <= 63
    error_message = "Field should not be larger than 63 characters"
  }
  validation {
    # Automatically Generated from Rule: pattern
    condition     = len(regexall("^(?!.*--)[a-zA-Z][A-Za-z0-9.-]+(?<!-)$", var.name)) > 0
    error_message = "Field does not match regex pattern ^(?!.*--)[a-zA-Z][A-Za-z0-9.-]+(?<!-)$"
  }
}

variable "vpc_name" {
  type = string
}

variable "engine" {
  type = string
  validation {
    # Automatically Generated from Rule: minlength
    condition     = len(var.engine) >= 1
    error_message = "Field should not be less than 1 characters"
  }
}

variable "engine_version" {
  type = string
  validation {
    # Automatically Generated from Rule: minlength
    condition     = len(var.engine_version) >= 1
    error_message = "Field should not be less than 1 characters"
  }
}

variable "is_public" {
  type = bool
  default = false
}

Next Steps

At the moment this does not generate validation rules (min/max length, regex, etc).

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

py2tf-0.1.0.tar.gz (7.4 kB view details)

Uploaded Source

Built Distribution

py2tf-0.1.0-py3-none-any.whl (8.4 kB view details)

Uploaded Python 3

File details

Details for the file py2tf-0.1.0.tar.gz.

File metadata

  • Download URL: py2tf-0.1.0.tar.gz
  • Upload date:
  • Size: 7.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.13

File hashes

Hashes for py2tf-0.1.0.tar.gz
Algorithm Hash digest
SHA256 76cc3fe09e89333ef7b9004858e8ddae58d4e928c369b1ba6672dd1cd44929b9
MD5 1ce2edfc7586c0f31f1f2f300c04b87c
BLAKE2b-256 02744902df738affe74ca54ddb7ef9ca1bd0af2aa404d7642b9a1e1369d289fc

See more details on using hashes here.

File details

Details for the file py2tf-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: py2tf-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 8.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.13

File hashes

Hashes for py2tf-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 490ecc8fa3e4087e83ce5ac8d4b9154406309031cd2cdb29924df33bd8e901a4
MD5 78cbe7967bd67216f6760bb14d67b132
BLAKE2b-256 9d59feabcc23c07e34fd853858c6dec10c80a2eb0d0a8198cb3b45d891b6d0d0

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page