我们基础框架有些时候是会需要改变的,例如我觉得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 链接
这个时候如何应用我们的修改呢?我们只需要执行如下命令:
1 |
terraform apply |
这个时候Terraform 会去更新状态,对比我们的文件中的代码和真正架构中的区别,并展示给我们如果我们想达到代码中的状态,我们需要做哪些修改:
因为ami发生了改变,Terraform 会删掉我们原来的instance并且用新的ami创建一个新的instance
1 2 3 4 5 |
Do you want to perform these actions? Terraform will perform the actions described above. Only 'yes' will be accepted to approve. Enter a value: yes |
当我们输入yes后,Terraform 会执行删除然后创建的操作
那我们如何清理我们的架构呢?就是把我创建的都删掉?
首先,我们可以使用
1 |
terraform show |
来列出我们Terraform创建的资源,然后我们如果要清理,只需要执行:
1 |
terraform destroy |
命令其实和apply 类似,都需要我们二次确认
1 2 3 4 5 6 7 |
Plan: 0 to add, 0 to change, 1 to destroy. Do you really want to destroy all resources? Terraform will destroy all your managed infrastructure, as shown above. There is no undo. Only 'yes' will be accepted to confirm. Enter a value: |
输入yes后,我们就可以等着Terraform去帮我们删除instance
Latest posts by Zhiming Zhang (see all)
- aws eks node 自动化扩展工具 Karpenter - 8月 10, 2022
- ReplicationController and ReplicaSet in Kubernetes - 12月 20, 2021
- public key fingerprint - 5月 27, 2021