개발자와 DevOps 팀은 일반적으로 다음을 활용합니다. 코드형 인프라(IaC) 도구와 스크립트를 사용하여 소프트웨어 및 인프라 배포를 반복적이고 일관된 방식으로 관리할 수 있습니다. IaC 도구를 사용하면 프로비저닝, 구성, 배포 및 리소스 파기를 포함한 배포의 수명 주기를 자동화할 수 있습니다. 해시코프 테라폼 는 매우 인기 있는 IaC 도구입니다.
1.0 버전의 일반 출시를 발표하게 되어 기쁘게 생각합니다. 카우치베이스 카펠라 테라폼 공급자를 추가하여 사용자가 프로그래밍 방식으로 Couchbase Capella 배포를 관리할 수 있습니다. 이 버전은 카펠라 공급자 v0.2 는 현재 더 이상 사용되지 않으며 곧 지원되지 않을 예정입니다.
이 글에서는 카펠라 테라폼 공급자에 대한 간단한 예시를 소개합니다.
배경
올해 초, 저희는 새로운 버전의 카펠라 관리 API - 사용자가 RESTful 인터페이스를 통해 프로그래밍 방식으로 카우치베이스 카펠라 리소스를 제어할 수 있는 개선된 버전의 카펠라 퍼블릭 API입니다.
카우치베이스 카펠라 테라폼 공급자 v1.0은 카펠라 관리 API를 활용합니다. 따라서 공급자를 통해 관리할 수 있는 Capella 리소스 세트는 기본 API에 따라 달라집니다. API가 새로운 엔드포인트를 지원하도록 발전함에 따라. Terraform 공급자는 엔드포인트를 통해 노출되는 해당 리소스의 관리를 지원하기 위해 그에 따라 확장될 것입니다.

공급자 워크스루
이 예제에서는 Capella Terraform 공급자를 사용하여 Capella 프로젝트, 클러스터를 배포하고 버킷을 프로비저닝하는 방법을 보여드리겠습니다.
그리고 GitHub 리포지토리 에는 사용자, 프로젝트, 클러스터, 버킷, 데이터베이스 자격 증명, 허용된 CIDR, 앱 서비스, 백업/복원 등 지원되는 각 리소스를 관리하기 위한 광범위한 예제가 있습니다.
전제 조건
-
- Terraform >= 1.5.2
- 이동 >= 1.20
- 아카펠라 유료 계정.
참고 현재 버전의 제공업체는 Capella 무료 평가판에서 지원되지 않습니다. 평가판 지원은 기본 Capella 관리 API가 평가판 배포의 오케스트레이션을 지원하는 경우에 사용할 수 있습니다.
인증 및 권한 부여
Capella Terraform 공급자의 모든 작업은 Capella 관리 API 키를 통해 인증되고 권한이 부여됩니다. 프로덕션 환경에서는 다음과 같은 것을 사용하게 됩니다. 해시코프 볼트 또는 다음과 같은 클라우드 서비스 제공업체에서 제공하는 비밀 관리자 AWS 시크릿 매니저 를 사용하여 API 키를 관리할 수 있습니다. 시크릿 매니저에 대한 참조는 Terraform 공급자에게 입력으로 지정됩니다.
이 데모에서는 로컬 환경 변수 파일에 자격 증명을 설정하겠습니다:
- 라는 파일을 만듭니다. variables.tf 를 클릭하고 다음 변수 정의를 추가합니다. 구성 파일 내에서 이러한 변수를 사용할 것입니다.
|
1 2 3 4 5 6 7 |
variable "organization_id" { description = "Capella Organization ID" } variable "auth_token" { description = "Authentication API Key" } |
2. 라는 파일을 만듭니다. terraform.template.tfvars 를 열고 다음 줄을 추가합니다. 여기서 배포와 관련된 주요 변수의 값을 지정합니다.
|
1 2 |
auth_token = "<replace-with-v4-api-key-secret>" organization_id = "<replace-with-the-oid-of-your-tenant>" |
샘플 배포를 위한 구성
앞서 언급했듯이 GitHub 리포지토리 의 공급자에는 광범위한 구성 템플릿 세트가 있습니다. 이 글에서는 간단한 예시를 통해 공급자를 사용하여 프로필을 만들고, 클러스터와 클러스터 내 버킷을 배포하는 방법을 설명합니다.
-
- 라는 파일을 만듭니다. capella.tf 를 클릭하고 다음 구성을 추가합니다. 구성은 다음을 수행합니다.
- 지정된 조직 내에 프로젝트 생성
- 프로젝트 내에 클러스터를 만듭니다.
- 클러스터 내에 버킷을 생성합니다.
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
terraform { required_providers { couchbase-capella = { source = "registry.terraform.io/couchbasecloud/couchbase-capella" } } } # Configure the Couchbase Capella Provider using predefined variables provider "couchbase-capella" { authentication_token = var.auth_token } # Create example project resource resource "couchbase-capella_project" "new_project" { organization_id = var.organization_id name = "Terraform Demo Project" description = "A Capella Project that will host a Capella cluster" } # Stores the project name in an output variable. # Can be viewed using `terraform output project` command output "project" { value = couchbase-capella_project.new_project.name } # Create cluster resource resource "couchbase-capella_cluster" "new_cluster" { organization_id = var.organization_id project_id = couchbase-capella_project.new_project.id name = "Terraform Demo Cluster" description = "Test cluster created with Terraform" cloud_provider = { type = "aws" region = "us-east-1" cidr = "192.168.10.0/23" } couchbase_server = { version = "7.2" } service_groups = [ { node = { compute = { cpu = 4 ram = 16 } disk = { storage = 50 type = "io2" iops = 5000 } } num_of_nodes = 3 services = ["data", "index", "query"] } ] availability = { "type" : "multi" } support = { plan = "developer pro" timezone = "PT" } } # Stores the cluster details in an output variable. # Can be viewed using `terraform output cluster` command output "cluster" { value = couchbase-capella_cluster.new_cluster } # Create bucket in cluster resource "couchbase-capella_bucket" "new_bucket" { name = "terraform_bucket" organization_id = var.organization_id project_id = couchbase-capella_project.new_project.id cluster_id = couchbase-capella_cluster.new_cluster.id type = "couchbase" storage_backend = "couchstore" memory_allocation_in_mb = 100 bucket_conflict_resolution = "seqno" durability_level = "none" replicas = 1 flush = false time_to_live_in_seconds = 0 eviction_policy = "fullEviction" } # Stores the bucket name in an output variable. # Can be viewed using `terraform output bucket` command output "bucket" { value = couchbase-capella_bucket.new_bucket.name } |
리소스 배포 및 관리
표준 사용 테라폼 명령 를 사용하여 리소스를 초기화하고 배포합니다.
1. Terraform 공급자 초기화
Terraform은 공급자를 처음 사용할 때 초기화해야 합니다:
|
1 |
terraform init |
2. 테라폼 계획 검토
다음 명령을 사용하여 배포할 리소스를 검토합니다:
|
1 |
terraform plan -var-file terraform.template.tfvars |
3. 테라폼 계획 실행
다음 명령을 사용하여 카우치베이스 아카펠라 리소스를 배포합니다:
|
1 |
terraform apply -var-file terraform.template.tfvars |
다음과 비슷한 결과가 표시됩니다. 리소스를 배포하는 데 몇 분 정도 걸립니다:
|
1 2 3 4 5 6 7 8 9 10 11 12 |
capella_project.new_project: Creating... capella_project.new_project: Creation complete after 0s [id=c9151819-2f75-41dd-b944-7e33d12163ea] capella_cluster.new_cluster: Creating... capella_cluster.new_cluster: Still creating... [10s elapsed] capella_cluster.new_cluster: Still creating... [30s elapsed] ....... capella_cluster.new_cluster: Still creating... [2m50s elapsed] capella_cluster.new_cluster: Still creating... [3m0s elapsed] capella_cluster.new_cluster: Creation complete after 3m1s [id=29ebb043-xxxx-xxxx-xxxx-xxxxxxxxxxxx] capella_bucket.new_bucket: Creating... capella_bucket.new_bucket: Creation complete after 0s [id=dGVycmFmb3JtXXXXXXXXXX=] Apply complete! Resources: 3 added, 0 changed, 0 destroyed. |
4. 리소스의 현재 상태 보기
|
1 |
terraform state list |
생성된 세 가지 리소스를 보여주는 다음과 유사한 출력이 표시됩니다:
|
1 2 3 |
couchbase-capella_bucket.new_bucket couchbase-capella_cluster.new_cluster couchbase-capella_project.new_project |
5. 배포된 리소스의 상세 상태 보기
|
1 |
terraform state show couchbase-capella_project.new_project |
생성된 세 가지 리소스를 보여주는 다음과 유사한 출력이 표시됩니다:
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
# capella_project.new_project: resource "couchbase-capella_project" "new_project" { audit = { created_at = "2023-11-19 22:59:59.695367442 +0000 UTC" created_by = "WFXyD6xRlAyCwKcpLGs6pKVScBGK299c" modified_at = "2023-11-19 22:59:59.695380869 +0000 UTC" modified_by = "WFXyD6xRlAyCwKcpLGs6pKVScBGK299c" version = 1 } description = "A Capella Project that will host a Capella cluster" etag = "Version: 1" id = "5ab4f4b5-756c-4f12-97ec-xxxxxyyyyyzzzz" name = "Terraform Demo Project" organization_id = "8b05f96d-45ba-zzzz-xxxx-fa55555555" } |
6. 리소스 파괴
다음 명령을 실행하여 리소스를 삭제합니다:
|
1 |
terraform destroy -var-file terraform.template.tfvars |
다음과 비슷한 결과가 표시됩니다. 리소스를 삭제하는 데 몇 분 정도 걸립니다.
|
1 2 3 4 5 6 7 8 9 10 11 |
capella_bucket.new_bucket: Destroying... [id=dGVycmFmb3JtX2J1Y2tldA==] capella_bucket.new_bucket: Destruction complete after 1s capella_cluster.new_cluster: Destroying... [id=e64b8ba9-46a1-46f1-9fc3-7a412508ce4b] capella_cluster.new_cluster: Still destroying... [id=e64b8ba9-46a1-46f1-9fc3-7a412508ce4b, 10s elapsed] ..... capella_cluster.new_cluster: Still destroying... [id=e64b8ba9-46a1-46f1-9fc3-7a412508ce4b, 50s elapsed] .... [id=e64b8ba9-46a1-46f1-9fc3-7a412508ce4b, 3m20s elapsed] capella_cluster.new_cluster: Destruction complete after 3m26s capella_project.new_project: Destroying... [id=5ab4f4b5-756c-4f12-97ec-8e2427c7c1ab] capella_project.new_project: Destruction complete after 1s |
리소스 및 다음 단계
공급업체 버전 1.0은 더 이상 사용되지 않으며 곧 제거될 Capella 공급업체의 버전 0.0.2를 대체합니다. 따라서 이전 공급업체를 사용 중인 경우 새 공급업체로 마이그레이션할 계획을 세워야 합니다.
다음은 몇 가지 유용한 리소스에 대한 직접 링크입니다:
질문이나 의견이 있으시면 아래에 댓글을 남겨 주세요. The 카우치베이스 포럼 또는 카우치베이스 불화 채널도 질문하기 좋은 곳입니다.
원하는 수집을 위한 유효성 검사 기능과 함께 TF를 통해 앱 서비스 엔드포인트를 만들 수 있나요?
안녕하세요 Jan- 프로그래밍 방식으로 앱 엔드포인트를 배포하고 관리할 수 있는 관리 API가 오늘 출시되었습니다. https://docs.couchbase.com/cloud/management-api-reference/index.html#tag/App-Endpoints. 테라폼 지원은 저희의 레이더망에 있습니다. 계속 지켜봐 주세요!