-
Terraform AWS ec2 userdata로 httpd 생성하기메모 및 기타 2022. 12. 2. 17:12
다음과 같은 user_data를 aws_instance resource 블럭안에 넣어준다.
user_data = <<EOF #! /bin/bash INSTANCE_ID=$(curl -s http://169.254.169.254/latest/meta-data/instance-id) sudo yum install -y httpd echo $INSTANCE_ID | sudo tee /var/www/html/index.html sudo service httpd start EOF
예시)
resource "aws_instance" "bastion" { ami = data.aws_ami.distro.id instance_type = var.aws_bastion_size count = var.aws_bastion_num associate_public_ip_address = true subnet_id = element(module.aws-vpc.aws_subnet_ids_public, count.index) vpc_security_group_ids = module.aws-vpc.aws_security_group key_name = var.AWS_SSH_KEY_NAME user_data = <<EOF #! /bin/bash INSTANCE_ID=$(curl -s http://169.254.169.254/latest/meta-data/instance-id) sudo yum install -y httpd echo $INSTANCE_ID | sudo tee /var/www/html/index.html sudo service httpd start EOF tags = merge(var.default_tags, tomap({ Name = "${var.aws_cluster_name}-bastion-${count.index}" })) }
반응형'메모 및 기타' 카테고리의 다른 글
containerd 환경에서 http image registry 사용 설정 (0) 2023.01.16 ubuntu root 계정 ssh 접속 Script (0) 2023.01.04 Keycloak client scope 정리 (0) 2022.11.25 golang reflect로 struct 필드 순회하기 (1) 2022.11.22 Network Trouble Shooting Pod Manifest (0) 2022.11.01