Terraform 템플릿 게시

  • 릴리스 버전: Australia
  • 업데이트 날짜 2026년 03월 12일
  • 소요 시간: 4분
  • Terraform 에서 애플리케이션에서 GitHub 정의한 템플릿을 게시하여 버전 제어, 공동 작업 및 중앙 집중식 스토리지를 사용하도록 설정합니다.

    시작하기 전에

    필요한 역할: Terraform 관리자

    프로시저

    1. Terraform 템플릿 전용 GitHub 리포지토리를 만듭니다.
    2. 다음 코드를 별도의 파일에 저장합니다.
      • 파일 이름: awsaccount.tf
        terraform {
          required_providers {
            aws = {
              source  = "hashicorp/aws"
              version = "~>5.0"
            }
          }
        }
        
        provider "aws" {
          region = var.region
        }
        
        resource "aws_organizations_account" "account" {
          email = var.root_email
          name = var.account_name
          tags = var.tags
          parent_id = var.parent_id
          close_on_deletion=var.close_delete
          create_govcloud=var.gov_cloud
        }
        
        resource "aws_budgets_budget" "cost" {
          name  = join("-", ["SN-CAM-Monthly-Budget", aws_organizations_account.account.id])
          count = var.monthly_budget > 0 ? 1 : 0
          budget_type  = "COST"
          limit_amount = var.monthly_budget
          limit_unit   = "USD"
          time_unit    = "MONTHLY"
        
          cost_filter {
            name = "LinkedAccount"
            values = [
              aws_organizations_account.account.id
            ]
          }
        
          notification {
            comparison_operator        = "GREATER_THAN"
            threshold                  = 100
            threshold_type             = "PERCENTAGE"
            notification_type          = "FORECASTED"
            subscriber_email_addresses = [var.root_email, var.notification_email]
          }
        
          notification {
            comparison_operator        = "GREATER_THAN"
            threshold                  = 85
            threshold_type             = "PERCENTAGE"
            notification_type          = "ACTUAL"
            subscriber_email_addresses = [var.root_email, var.notification_email]
          }
        
          notification {
            comparison_operator        = "GREATER_THAN"
            threshold                  = 100
            threshold_type             = "PERCENTAGE"
            notification_type          = "ACTUAL"
            subscriber_email_addresses = [var.root_email, var.notification_email]
          }
        }
      • 파일 이름: variables.tf
        variable "region" {
          type = string
          default = "us-east-1"
        }
        
        variable "account_name" {
          type = string
          description = "(Required) Account Name"
        }
        
        variable "root_email" {
          type = string
          description = "(Required) Account Email"
        }
        
        variable tags{
          type = map(string)
          description = "(Required) Tags for the resource"
        }
        
        variable "close_delete" {
          type = bool
          description = "Close Account on deletion"
          default = true
        }
        
        variable "gov_cloud" {
          type = bool
          description = "Gov Cloud Account"
          default = false
        }
        
        variable "parent_id" {
          type = string
          description = "(Required) Account Parent Organizational Unit"
        }
        
        variable monthly_budget {
          type = number
          default = 0
        }
        
        variable notification_email {
          type = string
          description = "Additional email where Budget Notifications are to be sent"
        }
    3. Terraform 파일을 원격 리포지토리로 푸시합니다.
    4. 템플릿이 GitHub에 저장되면 위치 또는 URL을 기록해 둡니다.

      그런 다음, 이 템플릿을 Terraform CloudServiceNow 인스턴스에서 참조하여 구독 계정 생성을 자동화합니다.

      중요사항:

      변수가 애플리케이션에 밀접하게 연결되어 있으므로 템플릿을 수정하지 마십시오.