Terraform IaC 파일 - AWS Proton

기계 번역으로 제공되는 번역입니다. 제공된 번역과 원본 영어의 내용이 상충하는 경우에는 영어 버전이 우선합니다.

Terraform IaC 파일

Terraform 코드형 인프라(IaC) 파일을와 함께 사용하는 방법을 알아봅니다 AWS Proton. Terraform은 HashiCorp에서 개발한 널리 사용되는 오픈 소스 IaC 엔진입니다. Terraform 모듈은 HashiCorp의 HCL 언어로 개발되었으며 Web Services를 비롯한 여러 백엔드 인프라 제공업체를 지원합니다.

AWS Proton 는 Terraform IaC에 대한 자체 관리형 프로비저닝을 지원합니다.

풀 리퀘스트에 응답하고 인프라 프로비저닝을 구현하는 프로비저닝 리포지토리의 전체 예시는 GitHub의 AWS Proton용 Terraform 오픈 소스 GitHub 작업 자동화 템플릿을 참조하세요.

Terraform IAC 템플릿 번들 파일에서 자체 관리형 프로비저닝이 작동하는 방식:
  1. Terraform 템플릿 번들에서 환경을 생성하면가 콘솔 또는 spec file 입력 파라미터로 .tf 파일을 AWS Proton 컴파일합니다.

  2. 컴파일된 IaC 파일을 AWS Proton에 등록한 리포지토리에 병합하기 위해 풀 리퀘스트를 생성합니다.

  3. 요청이 승인되면는 사용자가 제공한 프로비저닝 상태를 AWS Proton 기다립니다.

  4. 요청이 거부되면 환경 생성이 취소됩니다.

  5. 풀 리퀘스트 제한 시간이 초과되면 환경 생성이 완료되지 않습니다.

AWS Proton Terraform IaC 고려 사항 포함:
  • AWS Proton 는 Terraform 프로비저닝을 관리하지 않습니다.

  • 프로비저닝 리포지토리를에 등록해야 합니다 AWS Proton.이 리포지토리에 대한 풀 요청을 AWS Proton 수행합니다.

  • 프로비저닝 리포지토리 AWS Proton 에 연결하려면 CodeStar 연결을 생성해야 합니다.

  • AWS Proton 컴파일된 IaC 파일에서를 프로비저닝하려면 AWS Proton 풀 요청에 응답해야 합니다. AWS Proton 는 환경 및 서비스 생성 및 업데이트 작업 후 풀 요청을 수행합니다. 자세한 내용은 AWS Proton 환경AWS Proton 서비스 섹션을 참조하세요.

  • AWS Proton 컴파일된 IaC 파일에서 파이프라인을 프로비저닝하려면 CI/CD 파이프라인 리포지토리를 생성해야 합니다.

  • 풀 요청 기반 프로비저닝 자동화에는 AWS Proton 프로비저닝된 AWS Proton 리소스 상태 변경을 알리는 단계가 포함되어야 합니다. AWS Proton NotifyResourceDeploymentStatusChange API를 사용할 수 있습니다.

  • CloudFormation IaC 파일에서 생성된 서비스, 파이프라인 및 구성 요소를 Terraform IaC 파일로 만든 환경에 배포할 수 없습니다.

  • Terraform IaC 파일에서 생성된 서비스, 파이프라인 및 구성 요소를 CloudFormation IaC 파일로 만든 환경에 배포할 수 없습니다.

Terraform IaC 파일을 준비 AWS Proton할 때 다음 예제와 같이 네임스페이스를 입력 변수에 연결합니다. 자세한 내용은 파라미터를 참조하세요.

terraform { required_providers { aws = { source = "hashicorp/aws" version = "~> 3.0" } } // This tells terraform to store the state file in s3 at the location // s3://terraform-state-bucket/tf-os-sample/terraform.tfstate backend "s3" { bucket = "terraform-state-bucket" key = "tf-os-sample/terraform.tfstate" region = "us-east-1" } } // Configure the AWS Provider provider "aws" { region = "us-east-1" default_tags { tags = var.proton_tags } } resource "aws_ssm_parameter" "my_ssm_parameter" { name = "my_ssm_parameter" type = "String" // Use the Proton environment.inputs. namespace value = var.environment.inputs.ssm_parameter_value }

컴파일된 코드형 인프라

환경 또는 서비스를 생성할 때는 콘솔 또는 spec file 입력을 사용하여 코드 파일로 인프라를 AWS Proton 컴파일합니다. 다음 예시와 같이 입력에 대한 proton.resource-type.variables.tfproton.auto.tfvars.json 파일을 생성하여 Terraform에서 사용할 수 있습니다. 이러한 파일은 환경 또는 서비스 인스턴스 이름과 일치하는 폴더의 지정된 리포지토리에 있습니다.

이 예제에서는가 변수 정의 및 변수 값에 태그를 AWS Proton 포함하는 방법과 이러한 AWS Proton 태그를 프로비저닝된 리소스에 전파하는 방법을 보여줍니다. 자세한 내용은 프로비저닝된 리소스에 태그 전파 단원을 참조하십시오.

dev/environment.tf:

terraform { required_providers { aws = { source = "hashicorp/aws" version = "~> 3.0" } } // This tells terraform to store the state file in s3 at the location // s3://terraform-state-bucket/tf-os-sample/terraform.tfstate backend "s3" { bucket = "terraform-state-bucket" key = "tf-os-sample/terraform.tfstate" region = "us-east-1" } } // Configure the AWS Provider provider "aws" { region = "us-east-1" default_tags { tags = var.proton_tags } } resource "aws_ssm_parameter" "my_ssm_parameter" { name = "my_ssm_parameter" type = "String" // Use the Proton environment.inputs. namespace value = var.environment.inputs.ssm_parameter_value }

dev/proton.environment.variables.tf:

variable "environment" { type = object({ inputs = map(string) name = string }) } variable "proton_tags" { type = map(string) default = null }

dev/proton.auto.tfvars.json:

{ "environment": { "name": "dev", "inputs": { "ssm_parameter_value": "MyNewParamValue" } } "proton_tags" : { "proton:account" : "123456789012", "proton:template" : "arn:aws:proton:us-east-1:123456789012:environment-template/fargate-env", "proton:environment" : "arn:aws:proton:us-east-1:123456789012:environment/dev" } }

리포지토리 경로

AWS Proton 는 환경 또는 서비스 생성 작업의 콘솔 또는 사양 입력을 사용하여 컴파일된 IaC 파일을 찾을 리포지토리와 경로를 찾습니다. 입력 값은 네임스페이스 입력 파라미터에 전달됩니다.

AWS Proton 는 두 개의 리포지토리 경로 레이아웃을 지원합니다. 다음 예제에서는 두 환경의 네임스페이스 리소스 파라미터로 경로의 이름을 지정합니다. 각 환경에는 두 서비스의 서비스 인스턴스가 있으며, 이 중 하나의 서비스 인스턴스에는 구성 요소가 직접 정의되어 있습니다.

리소스 유형 이름 파라미터 = 리소스 이름
환경 environment.name = "env-prod"
환경 environment.name "env-staged"
Service service.name "service-one"
  서비스 인스턴스 service_instance.name "instance-one-prod"
  서비스 인스턴스 service_instance.name "instance-one-staged"
Service service.name "service-two"
  서비스 인스턴스 service_instance.name "instance-two-prod"
    구성 요소 service_instance.components.default.name "component-prod"
  서비스 인스턴스 service_instance.name "instance-two-staged"
    구성 요소 service_instance.components.default.name "component-staged"
Layout 1

environments 폴더가 있는 지정된 리포지토리를 AWS Proton 찾으면 컴파일된 IaC 파일이 포함되어 있고 로 이름이 지정된 폴더가 생성됩니다environment.name.

에서 서비스 인스턴스 호환 환경 이름과 일치하는 environments 폴더 이름이 포함된 폴더가 있는 지정된 리포지토리를 AWS Proton 찾으면 컴파일된 인스턴스 IaC 파일을 포함하고 로 이름이 지정된 폴더가 생성됩니다service_instance.name.

/repo /environments /env-prod # environment folder main.tf proton.environment.variables.tf proton.auto.tfvars.json /service-one-instance-one-prod # instance folder main.tf proton.service_instance.variables.tf proton.auto.tfvars.json /service-two-instance-two-prod # instance folder main.tf proton.service_instance.variables.tf proton.auto.tfvars.json /component-prod # component folder main.tf proton.component.variables.tf proton.auto.tfvars.json /env-staged # environment folder main.tf proton.variables.tf proton.auto.tfvars.json /service-one-instance-one-staged # instance folder main.tf proton.service_instance.variables.tf proton.auto.tfvars.json /service-two-instance-two-staged # instance folder main.tf proton.service_instance.variables.tf proton.auto.tfvars.json /component-staged # component folder main.tf proton.component.variables.tf proton.auto.tfvars.json
Layout 2

environments 폴더 없이 지정된 리포지토리를 AWS Proton 찾으면 컴파일된 환경 IaC 파일을 찾을 수 있는 environment.name 폴더가 생성됩니다.

가 서비스 인스턴스 호환 환경 이름과 일치하는 폴더 이름을 가진 지정된 리포지토리를 AWS Proton 찾으면 컴파일된 인스턴스 IaC 파일을 찾을 service_instance.name 폴더를 생성합니다.

/repo /env-prod # environment folder main.tf proton.environment.variables.tf proton.auto.tfvars.json /service-one-instance-one-prod # instance folder main.tf proton.service_instance.variables.tf proton.auto.tfvars.json /service-two-instance-two-prod # instance folder main.tf proton.service_instance.variables.tf proton.auto.tfvars.json /component-prod # component folder main.tf proton.component.variables.tf proton.auto.tfvars.json /env-staged # environment folder main.tf proton.variables.tf proton.auto.tfvars.json /service-one-instance-one-staged # instance folder main.tf proton.service_instance.variables.tf proton.auto.tfvars.json /service-two-instance-two-staged # instance folder main.tf proton.service_instance.variables.tf proton.auto.tfvars.json /component-staged # component folder main.tf proton.component.variables.tf proton.auto.tfvars.json