반응형
Terraform AWS Provider 설정 방법 (Profile 기반)
Terraform에서 AWS 리소스를 생성하기 위해서는 AWS Credential + Provider 설정이 필요합니다.
1. AWS Credential 설정
credentials 파일
vim ~/.aws/credentials
[terraformA]
aws_access_key_id = AWSACCESSKEYID
aws_secret_access_key = AWSSECRETACCESSKEY
config 파일
vim ~/.aws/config
[terraformA]
region = us-east-1
중요 config 파일에서는 반드시 profile prefix 필요
2. Terraform 디렉터리 구조
mkdir -p terraformA/aws/serviceA/us-east-1
cd terraformA/aws/serviceA/us-east-1
구조 의미
- terraformA → AWS 계정/프로파일
- serviceA → 서비스 단위 (VPC, EC2 등)
- us-east-1 → 리전 분리
3. Provider 정의

728x90
vim provider.tf
terraform {
required_version = ">= 1.3.0"
required_providers {
aws = {
source = "hashicorp/aws"
version = "~> 3.25"
}
}
}
provider "aws" {
profile = "terraformA"
region = "us-east-1"
}
4. 초기화 (Provider 설치)
terraform init
Initializing the backend...
Initializing provider plugins...
- Reusing previous version of hashicorp/aws from the dependency lock file
- Installing hashicorp/aws v3.25.0...
- Installed hashicorp/aws v3.25.0 (signed by HashiCorp)
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.
5. 설정 검증
terraform validate
6. AWS 인증 확인 (권장)
Terraform 실행 전 AWS 인증 정상 여부 확인
aws sts get-caller-identity --profile terraformA
참고URL
- https://registry.terraform.io/providers/hashicorp/aws/latest
- https://learn.hashicorp.com/tutorials/terraform/aws-remote?in=terraform/aws-get-started
728x90
반응형
'퍼블릭 클라우드' 카테고리의 다른 글
| Terraform으로 AWS Subnet 생성하기 (0) | 2021.01.29 |
|---|---|
| Terraform으로 AWS VPC 생성하기 (0) | 2021.01.29 |
| Terraform으로 AWS VPC 생성하기 (Provider 구성) (0) | 2021.01.28 |
| CentOS 7에서 Terraform을 설치하는 방법 (0) | 2021.01.26 |
| AWS RDS mysqldump(backup) error (0) | 2021.01.12 |