[玩转系统] 在 Windows 10/Windows Server 2019 上安装 Terraform
作者:精品下载站 日期:2024-12-14 12:23:34 浏览:15 分类:玩电脑
在 Windows 10/Windows Server 2019 上安装 Terraform
问:如何在 Windows 10 上安装 Terraform/Windows Server 2019?本指南将引导您完成在 Windows 10 和 Windows Server 2019 上安装 Terraform 的步骤。Terraform 是一种与云无关的基础设施自动化工具,用于管理代码中的云和本地资源。 Terraform 可以构建、更改和版本化部署在流行服务提供商上的基础设施。
借助 Terraform,您可以使用简单的声明性编程语言来管理计算、网络、DNS、数据库资源和许多其他资源。查看 Terraform 提供商的完整列表。
在 Windows 桌面/Windows 服务器上安装 Terraform。
在本指南中,我们将使用适用于 Windows 的 Scoop 命令行安装程序在 Windows 上安装 terraform。在继续之前,您需要在 Windows 计算机上安装 scoop,您可以使用下面的指南。
- 如何从 Windows 命令行安装应用程序
安装 Scoop 后,使用它来安装 terraform。
PS C:\Users\Administrator> scoop install terraform which vim touch
Installing 'terraform' (1.5.5) [64bit] from main bucket Starting download with aria2 ... Download: Download Results: Download: gid |stat|avg speed |path/URI
Download: ======+====+===========+=======================================================
Download: 04e241|OK | 1.7MiB/s|C:/Users/kipla/scoop/cache/terraform#1.5.5#https_releases.hashicorp.com_terraform_1.5.5_terraform_1.5.5_windows_amd64.zip
Download: Status Legend:
Download: (OK):download completed.
Checking hash of terraform_1.5.5_windows_amd64.zip ... ok.
Extracting terraform_1.5.5_windows_amd64.zip ... done.
Running pre_install script...
Linking ~\scoop\apps\terraform\current => ~\scoop\apps\terraform.5.5
Creating shim for 'terraform'.
'terraform' (1.5.5) was installed successfully!
Installing 'touch' (0.2018.07.25) [64bit] from main bucket
Starting download with aria2 ...
.....
terraform exe 文件将位于 ~/scoop/ 目录
内。
PS C:\Users\Administrator> which terraform
C:\Users\Administrator\scoop\shims\terraform.EXE
在 Windows 桌面/Windows 服务器上配置 Terraform
现在 terraform 已安装,让我们创建一个测试项目。
> mkdir projects
Directory: C:\Users\kipla
Mode LastWriteTime Length Name
---- ------------- ------ ----
d----- 8/17/2023 11:31 AM projects
在项目目录中创建 terraform 文件夹。
PS C:\Users\Administrator> cd .\projects\
PS C:\Users\Administrator\projects> mkdir terraform
Directory: C:\Users\Administrator\projects
Mode LastWriteTime Length Name
---- ------------- ------ ----
d----- 8/17/2023 11:32 AM terraform
PS C:\Users\Administrator\projects> cd .\terraform\
创建 Terraform 主配置文件。
touch main.tf
我正在使用 AWS 提供商进行测试,但您可以为您的项目使用其他提供商。我的 terraform 配置提供程序部分如下
PS C:\Users\Administrator\projects\terraform> vim .\main.tf
# Provider
provider "aws" {
access_key = ""
secret_key = ""
region = "us-west-1"
}
将您的 AWS 访问密钥和秘密密钥分别粘贴到 access_key
和 secret_key
部分中。完成后,运行 terraform init 来初始化 Terraform 工作目录。
PS C:\Users\Administrator\projects\terraform> terraform init
Initializing the backend...
Initializing provider plugins...
- Finding latest version of hashicorp/aws...
- Installing hashicorp/aws v5.12.0...
- Installed hashicorp/aws v5.12.0 (signed by HashiCorp)
Terraform has created a lock file .terraform.lock.hcl to record the provider
selections it made above. Include this file in your version control repository
so that Terraform can guarantee to make the same selections by default when
you run "terraform init" in the future.
Terraform has been successfully initialized!
You may now begin working with Terraform. Try running "terraform plan" to see
any changes that are required for your infrastructure. All Terraform commands
should now work.
If you ever set or change modules or backend configuration for Terraform,
rerun this command to reinitialize your working directory. If you forget, other
commands will detect it and remind you to do so if necessary.
Terraform 将自动下载配置到 .terraform
目录的提供程序。
PS C:\Users\Administrator\projects\terraform> ls
Directory: C:\Users\Administrator\projects\terraform
Mode LastWriteTime Length Name
---- ------------- ------ ----
d----- 8/17/2023 11:35 AM .terraform
-a---- 8/17/2023 11:35 AM 1377 .terraform.lock.hcl
-a---- 8/17/2023 11:34 AM 100 main.tf
里面还有另一个文件夹,用于存储 Terraform 下载的插件。
现在,我们通过编辑 main.tf
文件添加资源部分以创建 AWS VPC 和子网资源。
# Provider
provider "aws" {
access_key = ""
secret_key = ""
region = ""
}
# Retrieve the AZ where we want to create network resources
data "aws_availability_zones" "available" {}
# VPC Resource
resource "aws_vpc" "main" {
cidr_block = "10.11.0.0/16"
enable_dns_support = true
enable_dns_hostnames = true
tags {
Name = "Test-VPC"
}
tags {
Environment = "Test"
}
}
# AWS subnet resource
resource "aws_subnet" "test" {
vpc_id = "${aws_vpc.main.id}"
cidr_block = "10.11.1.0/24"
availability_zone = "${data.aws_availability_zones.available.names[0]}"
map_public_ip_on_launch = "false"
tags {
Name = "Test_subnet1"
}
}
添加资源定义并设置 AWS 变量后保存文件,然后生成并显示执行计划。
PS C:\Users\Administrator\projects\terraform> terraform plan
Refreshing Terraform state in-memory prior to plan...
The refreshed state will be used to calculate this plan, but will not be
persisted to local or remote state storage.
data.aws_availability_zones.available: Refreshing state...
------------------------------------------------------------------------
An execution plan has been generated and is shown below.
Resource actions are indicated with the following symbols:
+ create
Terraform will perform the following actions:
+ aws_subnet.test
id: <computed>
arn: <computed>
assign_ipv6_address_on_creation: "false"
availability_zone: "us-east-1a"
availability_zone_id: <computed>
cidr_block: "10.11.1.0/24"
ipv6_cidr_block: <computed>
ipv6_cidr_block_association_id: <computed>
map_public_ip_on_launch: "false"
owner_id: <computed>
tags.%: "1"
tags.Name: "Test_subnet1"
vpc_id: "${aws_vpc.main.id}"
+ aws_vpc.main
id: <computed>
arn: <computed>
assign_generated_ipv6_cidr_block: "false"
cidr_block: "10.11.0.0/16"
default_network_acl_id: <computed>
default_route_table_id: <computed>
default_security_group_id: <computed>
dhcp_options_id: <computed>
enable_classiclink: <computed>
enable_classiclink_dns_support: <computed>
enable_dns_hostnames: "true"
enable_dns_support: "true"
instance_tenancy: "default"
ipv6_association_id: <computed>
ipv6_cidr_block: <computed>
main_route_table_id: <computed>
owner_id: <computed>
tags.%: "2"
tags.Environment: "Test"
tags.Name: "Test-VPC"
Plan: 2 to add, 0 to change, 0 to destroy.
------------------------------------------------------------------------
Note: You didn't specify an "-out" parameter to save this plan, so Terraform
can't guarantee that exactly these actions will be performed if
"terraform apply" is subsequently run.
PS C:\Users\Administrator\projects\terraform>
最后使用 Terraform apply 构建您的基础设施。
PS C:\Users\Administrator\projects\terraform> terraform apply
data.aws_availability_zones.available: Refreshing state...
An execution plan has been generated and is shown below.
Resource actions are indicated with the following symbols:
+ create
Terraform will perform the following actions:
+ aws_subnet.test
id: <computed>
arn: <computed>
assign_ipv6_address_on_creation: "false"
availability_zone: "us-east-1a"
availability_zone_id: <computed>
cidr_block: "10.11.1.0/24"
ipv6_cidr_block: <computed>
ipv6_cidr_block_association_id: <computed>
map_public_ip_on_launch: "false"
owner_id: <computed>
tags.%: "1"
tags.Name: "Test_subnet1"
vpc_id: "${aws_vpc.main.id}"
...........................
确认要进行的更改并输入“yes”以启动修改。
Plan: 2 to add, 0 to change, 0 to destroy.
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
成功的 terraform 运行应该在最后打印成功消息。
Terraform 状态保存到 .\terraform.tfstate
但后端可以更改。
您可以从 AWS 控制台确认基础设施更改。
摧毁 Terraform 基础设施
我们已确认 Windows 上的 Terraform 安装按预期工作。通过运行 terraform destroy 命令来销毁 Terraform 管理的基础设施。
PS C:\Users\Administrator\projects\terraform> terraform destroy
aws_vpc.main: Refreshing state... (ID: vpc-0e94a7d72c02dab2b)
data.aws_availability_zones.available: Refreshing state...
aws_subnet.test: Refreshing state... (ID: subnet-0ad06c2e86542ddc1)
An execution plan has been generated and is shown below.
Resource actions are indicated with the following symbols:
- destroy
Terraform will perform the following actions:
- aws_subnet.test
- aws_vpc.main
Plan: 0 to add, 0 to change, 2 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 destroy -auto-approve
请参阅下面的输出:
登录AWS控制台并确认资源删除。
在其他系统上安装 terraform:
- 如何在 Fedora 上安装 Terraform
- 如何在 Ubuntu/CentOS 上安装 Terraform
更多 Windows 指南:
- 如何在 Windows Server 上允许 ICMP 回显回复
- 如何在 Windows Server 上运行 Docker 容器
- 适用于 Linux、macOS 和 Windows 的最佳安全备份应用程序
- 如何从 Windows 命令行安装应用程序
- 如何在 Windows Server 上启用远程桌面协议 (RDP)
- 如何使用 WSL 在 Windows Server 上运行 Linux
猜你还喜欢
- 03-30 [玩转系统] 如何用批处理实现关机,注销,重启和锁定计算机
- 02-14 [系统故障] Win10下报错:该文件没有与之关联的应用来执行该操作
- 01-07 [系统问题] Win10--解决锁屏后会断网的问题
- 01-02 [系统技巧] Windows系统如何关闭防火墙保姆式教程,超详细
- 12-15 [玩转系统] 如何在 Windows 10 和 11 上允许多个 RDP 会话
- 12-15 [玩转系统] 查找 Exchange/Microsoft 365 中不活动(未使用)的通讯组列表
- 12-15 [玩转系统] 如何在 Windows 上安装远程服务器管理工具 (RSAT)
- 12-15 [玩转系统] 如何在 Windows 上重置组策略设置
- 12-15 [玩转系统] 如何获取计算机上的本地管理员列表?
- 12-15 [玩转系统] 在 Visual Studio Code 中连接到 MS SQL Server 数据库
- 12-15 [玩转系统] 如何降级 Windows Server 版本或许可证
- 12-15 [玩转系统] 如何允许非管理员用户在 Windows 中启动/停止服务
取消回复欢迎 你 发表评论:
- 精品推荐!
-
- 最新文章
- 热门文章
- 热评文章
[影视] 黑道中人 Alto Knights(2025)剧情 犯罪 历史 电影
[古装剧] [七侠五义][全75集][WEB-MP4/76G][国语无字][1080P][焦恩俊经典]
[实用软件] 虚拟手机号 电话 验证码 注册
[电视剧] 安眠书店/你 第五季 You Season 5 (2025) 【全10集】
[电视剧] 棋士(2025) 4K 1080P【全22集】悬疑 犯罪 王宝强 陈明昊
[软件合集] 25年6月5日 精选软件22个
[软件合集] 25年6月4日 精选软件36个
[短剧] 2025年06月04日 精选+付费短剧推荐33部
[短剧] 2025年06月03日 精选+付费短剧推荐25部
[软件合集] 25年6月3日 精选软件44个
[剧集] [央视][笑傲江湖][2001][DVD-RMVB][高清][40集全]李亚鹏、许晴、苗乙乙
[电视剧] 欢乐颂.5部全 (2016-2024)
[电视剧] [突围] [45集全] [WEB-MP4/每集1.5GB] [国语/内嵌中文字幕] [4K-2160P] [无水印]
[影视] 【稀有资源】香港老片 艺坛照妖镜之96应召名册 (1996)
[剧集] 神经风云(2023)(完结).4K
[剧集] [BT] [TVB] [黑夜彩虹(2003)] [全21集] [粤语中字] [TV-RMVB]
[实用软件] 虚拟手机号 电话 验证码 注册
[资源] B站充电视频合集,包含多位重量级up主,全是大佬真金白银买来的~【99GB】
[影视] 内地绝版高清录像带 [mpg]
[书籍] 古今奇书禁书三教九流资料大合集 猎奇必备珍藏资源PDF版 1.14G
[电视剧] [突围] [45集全] [WEB-MP4/每集1.5GB] [国语/内嵌中文字幕] [4K-2160P] [无水印]
[剧集] [央视][笑傲江湖][2001][DVD-RMVB][高清][40集全]李亚鹏、许晴、苗乙乙
[电影] 美国队长4 4K原盘REMUX 杜比视界 内封简繁英双语字幕 49G
[电影] 死神来了(1-6)大合集!
[软件合集] 25年05月13日 精选软件16个
[精品软件] 25年05月15日 精选软件18个
[绝版资源] 南与北 第1-2季 合集 North and South (1985) /美国/豆瓣: 8.8[1080P][中文字幕]
[软件] 25年05月14日 精选软件57个
[短剧] 2025年05月14日 精选+付费短剧推荐39部
[短剧] 2025年05月15日 精选+付费短剧推荐36部
- 最新评论
-
- 热门tag