본문 바로가기

공부/IaC44

[Terraform/EKS/k8s] import 시 Kubernetes: Unauthorized 상황 Terraform의 한 모듈 내에서 EKS Cluster와 k8s 리소스들을 같이 프로비저닝 중 k8s 리소스 블럭들을 추가하였고, 기존 cluster 내부 리소스들을 import 해야하는 상황 ## k8s provider 설정 data "aws_eks_cluster_auth" "cluster" { name = aws_eks_cluster.this.id } provider "kubernetes" { host = aws_eks_cluster.this.endpoint token = data.aws_eks_cluster_auth.cluster.token cluster_ca_certificate = base64decode(aws_eks_cluster.this.certificate_authority[0].d.. 2022. 6. 28.
[Terraform] MAC에서 tfenv로 terraform 특정 버전 사용 # tfenv 설치 $ brew install tfenv # terraform 특정 버전 설치 $ tfenv install 1.1.3 # terraform 특정 버전 사용 $ tfenv use 1.1.3 # terraform 버전 확인 $ terraform version Terraform v1.1.3 다른 버전으로 스위칭하는것도 자유롭다 끝 2022. 5. 14.
[Terraform] 다른 backend의 state가 업데이트가 안돼요..?! (terraform_remote_state 불러오는 방식) terraform backend 설정에 관한 글 : [Terraform] 실행 환경 분리와 Backend 설정 (AWS/Terraform Cloud) terraform import에 관한 글 : [Terraform] Terraform import와 terraforming (AWS) 태초에....A 환경과 B 환경이 있었습니다 A와 B는 S3를 backend로 사용하고 있고...서로의 output을 받아오기 위해 data로 remote_state 블럭을 설정해 두었습니다 A 환경에서 실제 리소스들을 잔뜩 import를 해야 하는데, B 환경에서의 output을 사용할 일이 생겨서 아래와 같은 코드들을 추가했습니다 ## a/main.tf locals { test = data.terraform_remote_s.. 2022. 4. 30.
[Terraform] map 타입 변수 validation 설정하기 아래와 같은 변수를 사용한다고 생각해보자 variable "subnet_cidrs" { description = "Subnet CIDRs" type = map(string) default = { pub-bastion = "10.0.0.0/24" pri-db = "10.0.1.0/24" pri-glue = "10.0.2.0/24" pri-ecs = "10.0.3.0/24" } } 위 변수를 가지고 for_each를 돌리게 된다면, pub-bastion 과 pri-db 등의 이름들은 모두 each.key 로 분류되고, CIDR들은 모두 each.value로 분류된다 이 때, 각 key들의 이름이 pub 또는 pri로 시작하게 강제하고 싶으므로 validation 구문을 사용해보겠다 Terraform Vali.. 2022. 2. 21.
[Terraform] For Expression을 사용해 for_each문의 output 설정하기 https://www.terraform.io/language/expressions/for For Expressions - Configuration Language | Terraform by HashiCorp For expressions transform complex input values into complex output values. Learn how to filter inputs and how to group results. www.terraform.io 예를 들어, vpc를 여러 개 만든다고 해보자 count를 사용하는 경우 : locals { vpc_cidrs = [ "10.0.0.0/16", "10.1.0.0/16", "10.2.0.0/16" ] } resource "aws_vpc" "thi.. 2022. 2. 18.
[M1 MAC Terraform] The plugin.(*GRPCProvider).ValidateProviderConfig request was cancelled. 에러가 나지 않던 Terraform Code에서 갑자기 plan/apply 시 아래와 같은 에러가 떴다 해결 : https://github.com/hashicorp/terraform-provider-aws/issues/20274 plugin.(*GRPCProvider).ValidateResourceConfig request was cancelled. · Issue #20274 · hashicorp/terraform-provider-aws Community Note Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request Ple.. 2022. 1. 24.
[Terraform] CSV -> AWS Security Group : fileset 함수 활용 위와 같이 보안그룹별 csv 파일들을 만들어 두었을 때, 자동으로 sg_csv 폴더 내의 파일들을 한꺼번에 읽어오게 하고 싶었다 알아보니 테라폼엔 fileset이란 함수가 있었다 https://www.terraform.io/docs/language/functions/fileset.html fileset - Functions - Configuration Language - Terraform by HashiCorp The fileset function enumerates a set of regular file names given a pattern. www.terraform.io locals { sg_csvs = fileset("./sg_csv/", "*") sg = toset([for f in local... 2021. 12. 11.
[Terraform] Terraform import와 terraforming (AWS) 1. Terraform import란? https://www.terraform.io/docs/cli/import/index.html Import - Terraform by HashiCorp Terraform can import and manage existing infrastructure. This can help you transition your infrastructure to Terraform. www.terraform.io Terraform import는 말 그대로 기존에 존재하던 인프라를 가져오는 기능이다 는 너무 내 희망회로였고, 공식 도큐를 잘 읽어보면 알겠지만 리소스를 그저 "상태"로 땡겨오는 기능이었다 심지어는 가져올 개체가 매핑될 리소스에 대한 빈 블록을 수동으로 미리 작성해놔야 했다 .. 2021. 11. 7.
[Terrafrom] IP Network Functions (cidrhost, cidrnetmask, cidrsubnet, cudrsubnets) 1. cidrhost https://www.terraform.io/docs/language/functions/cidrhost.html cidrhost - Functions - Configuration Language - Terraform by HashiCorp The cidrhost function calculates a full host IP address within a given IP network address prefix. www.terraform.io 주어진 IP 대역에서의 특정번째 호스트 IP 찾기 기본 구조 : cidrhost(prefix, hostnum) Ex) cidrhost("10.0.0.0/16", 39) > 10.0.0.39 cidrhost("192.168.32.96/27", 12.. 2021. 10. 18.
[Terraform on AWS] CSV 파일 참조해서 Security Group Rule 만들기 CSV 파일 형식 module/main.tf variable "sg_id" {} variable "rule_type" {} # ingress / egress variable "from_port" {} variable "to_port" {} variable "protocol" {} # tcp / udp / icmp variable "src_or_dst_type" {} # cidr(list) / pl(list) / sg variable "destination" {} variable "description" {} # Rule with CIDR Blocks resource "aws_security_group_rule" "sg_cidr_rule" { count = var.src_or_dst_type == "cid.. 2021. 10. 10.