본문 바로가기

반응형

terraform

[Terraform] 테라폼 ALB 대상 그룹 등록 ALB(Application Load Balancer) 대상 그룹 등록 EC2 모듈 ec2.tf 편집 $ vim ec2.tf ... output "server_id" { value = join(", ", aws_instance.instance.*.id) } ALB 모듈 alb.tf 편집 $ vim abl.tf ... resource "aws_alb_target_group_attachment" "attachment" { count = 2 target_group_arn = aws_alb_target_group.targetgroup.arn target_id = element(split(",", var.server_id), count.index) port = 80 } 메인 모듈 main.tf 편집 $ vim m.. 더보기
[Terraform] 테라폼 join 함수(function) 테라폼 join 함수(function) : join은 주어진 구분 기호를 사용하여 주어진 문자열 목록의 모든 요소를 ​​함께 연결하여 문자열을 생성합니다 instance 모듈 instance.tf 편집 $ vim instance.tf ... ################################################### ##################### OUTPUTS ##################### ################################################### output "server_id" { value = join(", ", aws_instance.instance.*.id) } output "server_id" { value = join(", .. 더보기
[Terraform] 테라폼 concat 함수(function) 테라폼 concat 함수(function) : concat은 둘 이상의 목록을 가져와서 단일 목록으로 결합합니다. instance 모듈 instance.tf 편집 resource "aws_instance" "instance" { count = var.instance_count instance_type = var.instance_type ami = lookup(var.aws_amis, var.aws_region) key_name = var.key_name subnet_id = element(var.subnet_id, count.index) vpc_security_group_ids = var.vpc_security_group_ids associate_public_ip_address = var.associat.. 더보기
[Terraform] 테라폼 모듈화 테스트 테라폼(terraform) 모듈화 테스트 루트 모듈에서 VPC 구성 main.tf 파일 $ vim main.tf module "vpc" { source = "../../../tfmodules/vpc/" aws_region = "ap-northeast-2" suffix = "11" tf_env = "test" #tf_domain = "test.tf.4wxyz.com" public-cidr = ["10.11.12.0/23", "10.11.16.0/23"] private-cidr = ["10.11.22.0/24", "10.11.26.0/24"] mgmt-cidr = ["10.11.92.0/24", "10.11.96.0/24"] azs = ["ap-northeast-2a", "ap-northeast-2c"] }.. 더보기
[Terraform] 테라폼 모듈화 테스트 테라폼 모듈화 테스트 디렉토리 구조 . ├── main.tf ├── modules │ ├── EC2 │ │ ├── main.tf │ │ └── script │ │ └── install_web1.sh │ ├── RDS │ └── VPC ├── provider.tf └── variables.tf 루트 모듈 provider.tf $ vim provider.tf ### ./provider.tf terraform { required_providers { aws = { source = "hashicorp/aws" version = "3.25.0" } } } provider "aws" { # Configuration options shared_credentials_file = "~/.aws/credentials" r.. 더보기
[Terraform] 테라폼 키 페어 생성 키 페어 생성 key.tf 파일 생성 $ vim key.tf ###keypair 생성 resource "aws_key_pair" "tf_key_4wxyz" { key_name = "4wxyz" public_key = file("~/aws-key-pair/4wxyz.pub") tags = { Name = "4wxyz" Env = "stg" CreateUser = "terraform@email.com" Owner = "iac" Role = "keypair" Service = "keypair" } } 더보기
[Terraform] 테라폼 보안 그룹에 정책 추가 보안 그룹에 정책 추가 - EC2 보안 그룹에 ALB 정책 추가 ec2-sg.tf $ vim ec2-sg.tf ####################EC2 웹 시큐리티 구룹 생성 resource "aws_security_group" "tf_vpc99_sg-ec2-web1" { name = "ec2-web1" description = "Managed In Terraform" vpc_id = aws_vpc.tf_vpc99.id tags = { Name = "ec2-web1" Env = "stg" CreateUser = "terraform@email.com" Owner = "iac" Role = "security_group" Service = "security" } ingress { description = ".. 더보기
[Terraform] 테라폼 ALB(로드밸런서) 생성 ALB(로드밸런서) 생성 (선행 작업) - Route 53 생성 - SSL 인증서 생성 - security group 생성 - 인스턴스 생성 - ./script/install_web1.sh 스크립트 생성 alb.tf 파일 생성 $ vim alb.tf ####################ALB 생성 resource "aws_alb" "tf_alb-web1" { name = "web1" internal = false load_balancer_type = "application" idle_timeout = 60 security_groups = [ aws_security_group.tf_vpc99_sg_alb-web1.id ] subnets = [ aws_subnet.tf_vpc99-sb11.id, aws_su.. 더보기

728x90
반응형