用对流层管理aws云层的一个类似地形的实用程序
tropoform的Python项目详细描述
对流层形态
tropoform是一个为aws提供类似于terraform的接口的工具。 由对流层创建的云形成堆栈
可以创建至少有一个方法的对流层脚本(python模块):get_template() 并使用对流层来计划、应用、破坏云层堆栈。
要求
- python3-很抱歉,不打算将它移植回python 2.x
- Tropoform-可与PIP一起安装
PIP3安装Tropoform
tropoform安装以下附加库,这些库可能有助于开发 对流层脚本
安装
安装最新版本的tropoform
pip install tropoform --user --upgrade
对于开发项目,建议安装在python中 虚拟环境
或者,您可以从源代码安装https://github.com/cloudshiftstrategies/tropoform" rel="nofollow">https://github.com/cloudshiftstrategies/tropoform
用法
使用tropoform-h
获得帮助
$ tropform -h
usage: tropoform [-h] [-v]
{apply,plan,destroy,list,output,parameters,reason} ...
optional arguments:
-h, --help show this help message and exit
-v, --verbose get DEBUG logging
operation:
{apply,plan,destroy,list,output,parameters,reason}
apply create or update stack
plan view change plan
destroy remove stack
list list stacks
output view stack outputs
parameters list parameters used in a stack
reason list reasons for failed stack
有关操作的详细使用帮助,请参见tropoform apply-h
usage: tropoform apply [-h] [-m MODULE_NAME] [-p PARAMETER_FILES]
[-c CAPABILITIES] [-r REGION] [--auto_approve]
stack_name
positional arguments:
stack_name The name of the cloud formation stack on which to
perform operation. If a module exists in the current
working directory that matches the stack_name and has
a get_template() method, module_name is not required
optional arguments:
-h, --help show this help message and exit
-m MODULE_NAME, --module_name MODULE_NAME
The name of the python troposphere module that will
create the template. Module must have a get_template()
method that returns a valid troposphere.Template
object
-p PARAMETER_FILES, --parameter_files PARAMETER_FILES
Comma separated yaml parameter files that will be
passed to cloud formation as parameters
-c CAPABILITIES, --capabilities CAPABILITIES
Comma separated list of AWS capabilities. default:
CAPABILITY_NAMED_IAM
-r REGION, --region REGION
The name of the AWS region to perform operations.
default is the env variable: AWS_DEFAULT_REGION
--auto_approve If set, user will not be prompted to approve changes.
default=False
用法示例
使用至少有一个名为get_template()的函数的tropoform创建一个python脚本 返回未渲染的对流层.template()对象。
在下面的
example.py
脚本中,我们在函数get_template()中创建一个iam用户并返回 已完成的模板对象示例.py
fromtroposphereimportTemplatefromtroposphereimportiamdefget_template():template=Template()template.add_resource(iam.User("testIamUser",UserName="tropoform_test_user"))returntemplate
配置您的aws凭据 https://docs.aws.amazon.com/sdk for java/v1/developer-guide/setup credentials.html 以便您可以进行api/cli调用。
- 使用awscli命令测试您的凭据,如
aws s3 ls
- 或者您可以测试boto3 python api
python3-c"import boto3;client=boto3.client('s3');print(client.list_buckets())"
- 使用awscli命令测试您的凭据,如
在堆栈上运行
tropoform计划
,并查看是否将创建一个iam用户资源$ tropoform plan myStack -m example.py STACK: myStack is not yet deployed STACK: myStack creates 1 # ) action logical_id resource_type 1) Create testIamUser AWS::IAM::User
使用(创建)堆栈
$ tropoform apply myStack -m example.py STACK: myStack, Current Status: None CREATING Stack: myStack with 1 resources Are you sure? [yes|no] yes STACK: myStack, Status: CREATE_IN_PROGRESS - 16:36:10 STACK: myStack, Status: CREATE_IN_PROGRESS - 16:36:25 STACK: myStack, Status: CREATE_COMPLETE - 16:36:41 STACK: myStack deployed 1 resources in 00:00:48 STACK OUTPUTS:
使用
tropoform list
查看应用的堆栈。请注意,它处于"创建完成"状态$ tropoform list stack_name stack_status drift_status stack_description myStack CREATE_COMPLETE NOT_CHECKED
更新example.template并添加另一个资源
示例.py
fromtroposphereimportTemplatefromtroposphereimportiamdefget_template():template=Template()template.add_resource(iam.User("testIamUser",UserName="tropoform_test_user"))template.add_resource(iam.User("testIamUser2",UserName="tropoform_test_user2"))returntemplate
运行一个新的对流层计划。请注意,它将添加一个新资源。
$ tropoform plan myStack -m example.py STACK: myStack has 1 detected changes # ) action logical_id resource_id resource_type scope Replace? 1) Add testIamUser2 AWS::IAM::User []
tropoform应用更改,然后使用
tropoform列表进行验证
0pip install tropoform --user --upgrade
完成后销毁堆栈
1pip install tropoform --user --upgrade
< > >参数文件
通常,cloudformation模板将需要参数,以便它们可以很容易地 可重复使用的。可以使用key:value对创建基于yaml的文件,并将其添加为 对流层计划和对流层应用操作的参数
示例_parms1.yaml
2pip install tropoform --user --upgrade
示例_parms2.yaml
3pip install tropoform --user --upgrade
在应用程序中使用参数文件
4pip install tropoform --user --upgrade
能力
云形成堆栈可能需要确认它将创建 某些类型。最常见的是授权云形成的功能 创建IAM资源。这个默认情况下包含在对流层中。但是如果你的堆栈 需要其他功能,可以将它们与
-c
参数一起包含。查看更多 本文档中有关功能的信息: https://docs.aws.amazon.com/awscloudformation/latest/apirerence/api廑createstack.html在应用程序中使用附加功能
5pip install tropoform --user --upgrade
区域
默认情况下,对流层将读取环境变量aws_default_region以确定 在哪里管理堆栈。但是如果你想为一个操作指定一个不同的区域 传递'-r'或'--region'参数
在列表命令中指定区域
6pip install tropoform --user --upgrade
堆栈名称和模块名称
如果要为cloudformation堆栈指定的名称是 工作目录和与对流层脚本同名,则可以省略 module_name参数
当对流层为"example.py"时,创建一个称为"example"的云形成堆栈的示例 当前工作目录中存在脚本
7pip install tropoform --user --upgrade
当对流层为"example.py"时创建一个称为"mystack"的云形成堆栈的示例 脚本存在于某些文件系统位置
8pip install tropoform --user --upgrade
自动批准
有时在自动脚本中运行tropoform时,您不想被提示说 是以确认
应用
或销毁
操作示例
--auto_approve
9pip install tropoform --user --upgrade
失败原因
如果您的cloudformation堆栈由于某种原因未能应用,则cloudformation事件 这导致将被打印。
在下面的示例中,我们试图附加一个故意拼写错误的managediampolicy
0$ tropform -h usage: tropoform [-h] [-v] {apply,plan,destroy,list,output,parameters,reason} ... optional arguments: -h, --help show this help message and exit -v, --verbose get DEBUG logging operation: {apply,plan,destroy,list,output,parameters,reason} apply create or update stack plan view change plan destroy remove stack list list stacks output view stack outputs parameters list parameters used in a stack reason list reasons for failed stack
您可以使用
对流层形式原因
操作查找失败堆栈的状态
1$ tropform -h usage: tropoform [-h] [-v] {apply,plan,destroy,list,output,parameters,reason} ... optional arguments: -h, --help show this help message and exit -v, --verbose get DEBUG logging operation: {apply,plan,destroy,list,output,parameters,reason} apply create or update stack plan view change plan destroy remove stack list list stacks output view stack outputs parameters list parameters used in a stack reason list reasons for failed stack
参数
如果使用参数部署堆栈,则可以使用
对流层形状参数
操作
2$ tropform -h usage: tropoform [-h] [-v] {apply,plan,destroy,list,output,parameters,reason} ... optional arguments: -h, --help show this help message and exit -v, --verbose get DEBUG logging operation: {apply,plan,destroy,list,output,parameters,reason} apply create or update stack plan view change plan destroy remove stack list list stacks output view stack outputs parameters list parameters used in a stack reason list reasons for failed stack
输出
如果堆栈指定了输出参数,则在完成部署堆栈时,将输出 将被打印。
3$ tropform -h usage: tropoform [-h] [-v] {apply,plan,destroy,list,output,parameters,reason} ... optional arguments: -h, --help show this help message and exit -v, --verbose get DEBUG logging operation: {apply,plan,destroy,list,output,parameters,reason} apply create or update stack plan view change plan destroy remove stack list list stacks output view stack outputs parameters list parameters used in a stack reason list reasons for failed stack
如果以后要访问这些输出,可以运行
tropoform output
4$ tropform -h usage: tropoform [-h] [-v] {apply,plan,destroy,list,output,parameters,reason} ... optional arguments: -h, --help show this help message and exit -v, --verbose get DEBUG logging operation: {apply,plan,destroy,list,output,parameters,reason} apply create or update stack plan view change plan destroy remove stack list list stacks output view stack outputs parameters list parameters used in a stack reason list reasons for failed stack
< > >
附加功能
欢迎投稿!
打开问题并通过github repo发送pull请求https://github.com/cloudshiftstrategies/tropoform
构建说明
$ tropform -h
usage: tropoform [-h] [-v]
{apply,plan,destroy,list,output,parameters,reason} ...
optional arguments:
-h, --help show this help message and exit
-v, --verbose get DEBUG logging
operation:
{apply,plan,destroy,list,output,parameters,reason}
apply create or update stack
plan view change plan
destroy remove stack
list list stacks
output view stack outputs
parameters list parameters used in a stack
reason list reasons for failed stack
5