TerraForm开发工具,用于提取变量并生成variables.tf文件。

scratchrelaxtv的Python项目详细描述


scratch relax tv

地形模块开发工具。

  1. main.tf中提取变量并生成variables.tf文件
  2. 根据彼此查找variables.tfmain.tf中缺少的变量
  3. variables.tf文件生成模块使用存根
  4. 使用main.tf
  5. 中的变量生成.env文件
  6. 删除多余的scratchrelaxtv文件

安装

pip install scratchrelaxtv

提示

安装后,您可以通过键入relaxtvscratchrelaxtv来运行scratchrelaxtv

了解更多关于terraform工作流的信息,并使用scratchrelaxtvhere

工作流

下面是使用scratchrelaxtv的两个示例工作流。

原始模块开发

  1. 用任何需要的变量编写main.tf
  2. 运行scratchrelaxtv生成variables.tf
  3. variables.tf
  4. 中填写描述、默认值等
  5. 运行terraform fmt以美化所有内容

清除模块

  1. 在带有main.tfvariables.tf的文件夹中运行scratchrelaxtv以查找丢失的变量
  2. 使用-cf选项,自动将缺少的变量添加到variables.tf
  3. variables.tf中为新添加的变量填写描述、默认值等
  4. 运行terraform fmt以美化所有内容

示例

示例:生成variables.tf

默认情况下,scratchrelaxtv查找main.tf,并生成一个variables.tf文件。变量在variables.tf中的顺序与在main.tf中的顺序相同。有对变量排序的选项。可以改写现有的^ {< CD2> }文件^ {CD24}}。否则,scratchrelaxtv将在每次运行时生成新的variables.tf文件:variables.1.tfvariables.2.tf等等。

假设这个main.tf

resource "aws_s3_bucket" "this" {
  count  = "${var.create_bucket ? 1 : 0}"
  bucket = "${var.bucket}"
  region = "${var.region}"
}

运行scratchrelaxtv

$ relaxtv
2019-04-26 08:02:54,011 - INFO - generating variables file2019-04-26 08:02:54,011 - INFO - input file: main.tf2019-04-26 08:02:54,011 - INFO - output file: variables.tf2019-04-26 08:02:54,011 - INFO - not forcing overwrite of output file2019-04-26 08:02:54,011 - INFO - not ordering output file

生成的variables.tf

variable "create_bucket" {
  description = ""
  type        = "string"
  default     = ""
}

variable "bucket" {
  description = ""
  type        = "string"
  default     = ""
}

variable "region" {
  description = ""
  type        = "string"
  default     = ""
}

示例:查找并修复丢失的变量

假设您已经有一个main.tf和一个variables.tf。在本例中,variables.tf缺少region变量。

main.tf

resource "aws_s3_bucket" "this" {
  bucket = "${var.bucket}"
  region = "${var.region}"
}

variables.tf

variable "bucket" {
  description = "The bucket where the stuff will be stored"
  type        = "string"
  default     = ""
}

运行scratchrelaxtv自动添加任何缺少的变量:

$ relaxtv -cf
2019-04-26 08:21:27,289 - INFO - checking for missing variables2019-04-26 08:21:27,289 - INFO - input file: main.tf2019-04-26 08:21:27,289 - INFO - output file: variables.tf2019-04-26 08:21:27,289 - INFO - forcing overwrite of output file2019-04-26 08:21:27,289 - INFO - not ordering output file2019-04-26 08:21:27,290 - WARNING - input file main.tf is missing variables:region

现在,variables.tf看起来像这样:

variable "bucket" {
  description = "The bucket where the stuff will be stored"
  type        = "string"
  default     = ""
}

variable "region" {
  description = ""
  type        = "string"
  default     = ""
}

示例:生成使用模块的存根

默认情况下,生成存根时,scratchrelaxtv查找variables.tf

假设这个variables.tf

variable "id" {
  description = "The ID of the resource"
  type        = "string"
  default     = ""
}

variable "bucket" {
  description = "The bucket where the stuff will be stored"
  type        = "string"
  default     = ""
}

variable "region" {
  description = "The AWS region where the bucket lives"
  type        = "string"
  default     = ""
}

使用模块存根选项运行scratchrelaxtv

$ relaxtv -m
2019-04-26 08:09:27,147 - INFO - generating module usage stub2019-04-26 08:09:27,147 - INFO - input file: variables.tf2019-04-26 08:09:27,147 - INFO - output file: modstub.tf2019-04-26 08:09:27,147 - INFO - not forcing overwrite of output file2019-04-26 08:09:27,147 - INFO - not ordering output file

生成的modstub.tf

module "tests2" {
  source = "../tests2"

  providers = {
    aws = "aws"
  }

  id     = "${local.id}"
  bucket = "${local.bucket}"
  region = "${local.region}"
}

示例:生成.env(dotenv)文件

默认情况下,生成.env文件时,scratchrelaxtv查找variables.tf

假设这个variables.tf

resource "aws_s3_bucket" "this" {
  bucket = "${var.bucket}"
  region = "${var.region}"
}

使用generate.env运行scratchrelaxtv并对升序选项进行排序:

$ relaxtv -ea
2019-06-21 20:01:35,362 - INFO - generating .env file2019-06-21 20:01:35,362 - INFO - input file: main.tf2019-06-21 20:01:35,362 - INFO - output file: .env2019-06-21 20:01:35,362 - INFO - not forcing overwrite of output file2019-06-21 20:01:35,362 - INFO - ordering output file ascending

生成的.env

unset"${!TF_VAR_@}"TF_VAR_bucket=replace
TF_VAR_region=replace

示例:删除文件

$ relaxtv -r

scratchrelaxtv还可以通过删除自己额外生成的文件来整理目录。可能它只会删除您不再需要的文件,但是请小心。此图表显示了哪些内容将被删除或不删除的示例。

notescratchrelaxtv删除当前目录和子目录中的文件。

FilenameDeleted?
variables.tfno
modstub.tfyes
modstub.1.tfyes
variables.1.tfyes
xyz.abcno
variables.a.tfno
variables.43.tfyes
modstubno
modstub..tfno

帮助

scratchrelaxtv包括帮助:

$ relaxtv --help
usage: scratchrelaxtv [-h] [-i INPUT] [-o OUTPUT] [-f] [-m] [-n MODNAME] [-r]                      [-c] [-e] [-a | -d]optional arguments:  -h, --help            show this help message and exit  -i INPUT, --input INPUT                        file to extract vars from  -o OUTPUT, --output OUTPUT                        file to write extracted vars to  -f, --force           overwrite existing out file  -m, --modstub         generate module usage stub  -n MODNAME, --modname MODNAME                        name to use in module stub  -r, --remove          remove all modstub.tf, variables.#.tf files  -c, --check           check that all vars are listed  -e, --env             generate .env with Terraform vars  -a, --asc             sort output variables in ascending order  -d, --desc            sort output variables in descending order

更改日志

0.5.2-2019.07.19

  • 添加与HCl2/Terraform 0.12.x变量(不含^{})的兼容性
  • 删除功能以自动将列表默认值设置为空列表(对HCl2样式的变量不起作用)

0.5.0-2019.07.02

  • 添加功能以生成地形变量(.tfvars)文件

0.4.0至2019.06.21

  • 添加功能以生成点环境(.env)文件

0.3.0-2019.04.25

    添加功能以检查丢失变量的现有^ { CD1> }和^ {CD2}}

0.2.1-2019.04.25

  • 修复删除文件时引发的无关紧要的错误

0.2.0-2019.04.25

  • 添加删除额外工作文件的功能

0.1.3-2019.04.17

  • 添加模块存根功能

0.1.2-2019.04.17

  • 添加简单文档

0.1.1-2019.04.16

  • 初始工作版本

0.1.0-2019.04.15

  • 初次发布!

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java获取TaskCompletionSource工作(Firestore的Android任务)   从PNG文件获取java或信息   neo4j嵌入式版本2.3.8的java NotInTransactionException   OSGI框架的java Eclipse启动配置在Mac上不起作用   java svn:“预提交”挂钩失败,输出错误:   java中ResourceBundle的io查询   java声明变量的最佳方法是什么?遵循下面的例子?   java如何在log4j中获得不同的记录器?   hibernate错误“java.lang.NoSuchMethodError:org.jboss.logging.Logger.getMessageLogger”   swing将JPanel保存为图像   eclipse(Java Spigot)我的PlayerInteractEvent有问题   使用java nio从FileChannel读取的字符串   java Eclipse无法清理生成输出   安卓对Eclipse java组件中的代码行数有限制吗   java Android Studio将应用程序推到手机上,不会让我   针对具有两个编辑器的页面的selenium java代码自动化   Java正则表达式:负前瞻   JavaJPA:基于实例变量将实体动态映射到表