我个人对terraform module的理解是,这个东西更像是我们传统意义上的函数,我们在一个地方定义了一个函数以后,以后相同的功能直接调用函数就可以了,不需要重新copy paste代码,当然我们也可以传递参数,这样函数执行的过程中还有差异化的选择, Terraform module的定义完全相同 我们使用https://github……
分类目录:Terraform
Terraform 参数输入 参数输出
Terraform 对象初始化Provisioner
Terraform resource之间的依赖问题
Terraform 修改 清理
我们基础框架有些时候是会需要改变的,例如我觉得ec2的内存和cpu不够用了,我要用更大的类型以获得足够的cpu和内存,这个时候我们就需要作出修改
1 2 3 4 5 6 7 8 9 |
provider "aws" { profile = "default" region = "us-east-1" } resource "aws_instance" "jeremyzhang-test-instance" { ami = "ami-b374d5a5" instance_type = "t2.micro" } |
和上一篇文章不同的地方是我们修改了ami 链接 这个时候如何应用我们的修改呢?我们只需要执行如下命令: [crayon-6422……
Terraform 如何创建一个aws instance
首先,我们要先安装Terraform, Terraform的安装很简单,以Mac 为例:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
$brew install terraform $terraform --help Usage: terraform [-version] [-help] <command> [args] The available commands for execution are listed below. The most common, useful commands are shown first, followed by less common or more advanced commands. If you're just getting started with Terraform, stick with the common commands. For the other commands, please read the help and docs before usage. Common commands: apply Builds or changes infrastructure console Interactive console for Terraform interpolations destroy Destroy Terraform-managed infrastructure env Workspace management fmt Rewrites config files to canonical format get Download and install modules for the configuration graph Create a visual graph of Terraform resources import Import existing infrastructure into Terraform init Initialize a Terraform working directory output Read an output from a state file plan Generate and show an execution plan providers Prints a tree of the providers used in the configuration refresh Update local state file against real resources show Inspect Terraform state or plan taint Manually mark a resource for recreation untaint Manually unmark a resource as tainted validate Validates the Terraform files version Prints the Terraform version workspace Workspace management All other commands: 0.12upgrade Rewrites pre-0.12 module source code for v0.12 debug Debug output management (experimental) force-unlock Manually unlock the terraform state push Obsolete command for Terraform Enterprise legacy (v1) state Advanced state management |
安装完成后我们来使用Terraform在aws中创建一个instance 先看代码 example.tf:
1 2 3 4 5 6 7 8 9 |
provider "aws" { profile = "default" region = "us-east-1" } resource "aws_instance" "example" { ami = "ami-2757f631" instance_type = "t2.micro" } |
注意:例子……