Windows 10/Windows Server 2019에 Terraform 설치 |
Q: Windows 10/Windows Server 2019에 Terraform을 설치하려면 어떻게 해야 하나요? 이 가이드에서는 Windows 10 및 Windows Server 2019에 Terraform을 설치하는 단계를 안내합니다. Terraform은 클라우드 및 온프레미스 리소스를 코드로 관리하는 데 사용되는 클라우드에 구애받지 않는 인프라 자동화 도구입니다. Terraform은 인기 있는 서비스 제공업체에 배포된 인프라를 구축, 변경 및 버전화할 수 있습니다.
Terraform을 사용하면 간단한 선언적 프로그래밍 언어를 사용하여 컴퓨팅, 네트워킹, DNS, 데이터베이스 리소스 및 기타 여러 리소스를 관리할 수 있습니다. Terraform 제공업체의 전체 목록을 확인하세요.
Windows 데스크톱/Windows Server에 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\1.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.EXEWindows 데스크톱/Windows Server에서 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"
}access_key 및 secret_key 섹션에 각각 AWS 액세스 키와 비밀 키를 붙여넣습니다. 완료되면 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를 사용하여 Terraform으로 인프라를 구축하세요.
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 가이드:






