고가용성은 인프라 장애, 시스템 유지보수 및 기타 중단 시 지속적인 작업을 보장하고 가동 중단 시간을 최소화하는 애플리케이션의 기능입니다. MongoDB의 기본값 배포서버 아키텍처는 고가용성을 위해 설계되었으며, 데이터 중복성과 자동 페일오버를 위한 내장 기능을 갖추고 있습니다.
고가용성은 재해 복구와 다릅니다. 고가용성은 노드, 구역, 리전 또는 클라우드 공급자 장애와 같은 인프라 장애로부터 보호하며, 자동 페일오버를 통해 데이터 손실 없이 장애 발생 정확한 시점으로 복구(RPO =)하고 0 RTO는 몇 초 이내에 이루어집니다. 재해 복구는 손상 또는 실수로 인한 삭제와 같은 데이터 무결성 문제로부터 보호합니다. 이러한 문제는 백업에서 복원해야 합니다. 재해 복구에 대해 자세히 알아보려면, Atlas 재해 복구 지침을 참조하세요.
이 페이지에서는 중단을 방지하고 구역, 리전 및 클라우드 공급자 장애에 대한 강력한 페일오버 메커니즘을 지원하기 위해 선택할 수 있는 추가 구성 옵션 및 배포서버 아키텍처 개선 사항에 대해 설명합니다.
고가용성을 위한 Atlas의 기능
데이터베이스 복제
MongoDB's default deployment architecture is designed for redundancy. Atlas deploys each cluster as a replica set with a minimum of three database instances (also called nodes or replica set members), distributed across separate availability zones within your selected cloud provider regions. Applications write data to the replica set's primary node, and then Atlas replicates and stores that data across all nodes within your cluster. To control the durability of your data storage, you can adjust the write concern of your application code to complete the write only once a certain number of secondaries have committed the write. The default behavior is for data to be persisted on a majority of electable nodes before confirming the action.
다음 다이어그램에서 기본값 3노드 복제본 세트의 복제 작동 방식을 확인하실 수 있습니다.

자동 페일오버
In the event that a primary node in a replica set becomes unavailable due to an infrastructure outage, scheduled maintenance, or any other disruption, Atlas clusters self-heal by promoting an existing secondary node to the role of primary node in a replica set election. This failover process is fully automatic and recovers to the exact moment of failure with no data loss (RPO = 0) in seconds. Operations that were in flight at the time of the failure are retried after the failure if retryable writes are enabled. After a replica set election, Atlas restores or replaces the failing member to ensure that the cluster is returned to its target configuration as soon as possible. The MongoDB client driver also automatically switches all client connections during and after the failure.
다음 다이어그램은 복제본 세트 투표 과정을 보여줍니다.

가장 중요한 애플리케이션의 가용성을 개선하기 위해 노드, 리전 또는 클라우드 공급자를 추가하여 각각 구역, 리전 또는 제공자 장애를 견딜 수 있도록 배포서버를 확장할 수 있습니다. 자세한 내용은 아래의 내결함성을 위한 배포서버 패러다임 확장 권장사항을 참조하세요.
Atlas 고가용성 권장 사항
다음 권장사항은 배포서버의 가용성을 높이기 위해 수행할 수 있는 추가 구성 옵션 및 배포서버 아키텍처 개선 사항을 설명합니다.
배포서버 목표에 맞는 클러스터 계층 선택
Dedicated, Flex 또는 무료 배포서버 유형에서 사용할 수 있는 범위 클러스터 계층 중에서 선택할 수 있습니다. MongoDB Atlas 의 클러스터 계층 클러스터 의 각 노드 에 사용할 수 있는 리소스(메모리, 저장 , vCPU, IOPS)를 지정합니다. 상위 계층 으로 확장하면 클러스터가 트래픽 급증을 처리하다 기능 향상되고 높은 워크로드에 더 빠르게 응답하여 시스템 안정성이 향상됩니다. 애플리케이션 크기에 권장되는 클러스터 계층 결정하려면 Atlas 클러스터 크기 가이드를 참조하세요.
Atlas also supports auto-scaling to allow the cluster to automatically adjust to spikes in demand. Atlas uses both reactive auto-scaling, which triggers based on current resource usage, and predictive auto-scaling, which proactively scales up eligible clusters before forecasted cyclical demand spikes occur. Automating scaling actions reduces the risk of an outage due to resource constraints. To learn more, see Guidance for Atlas Automated Infrastructure Provisioning.
내결함성을 위한 배포서버 패러다임 확장
An Atlas deployment's fault tolerance is the number of replica set members that can become unavailable while your deployment still remains operational. In the event of an availability zone, region, or cloud provider outage, Atlas clusters self-heal by promoting an existing secondary node to the role of primary node in a replica set election. A majority of the voting nodes in a replica set must be operational in order to run a replica set election when a primary node experiences an outage.
부분적인 지역 장애가 발생할 경우 복제본 세트가 프라이머리를 선택할 수 있게 하려면 가용영역이 최소 3개인 리전에 클러스터를 배포해야 합니다. 가용영역은 단일 클라우드 공급자 리전 내에 있는 분리된 데이터 센터 그룹으로, 각 그룹은 자체 전력, 냉각 및 네트워킹 인프라를 갖추고 있습니다. 선택한 클라우드 공급자 리전에서 가용영역을 지원하는 경우, Atlas는 클러스터를 가용영역에 자동으로 분산하여 어느 가용영역에 장애가 발생하더라도 클러스터의 나머지 노드가 여전히 리전 서비스를 지원할 수 있도록 합니다. 대부분의 Atlas가 지원하는 클라우드 공급자 리전에는 최소 3개의 가용영역이 있습니다. 이러한 리전은 Atlas UI에 별 아이콘으로 표시됩니다.
각 클라우드 공급자 가용영역 내에서 기본값 데이터 중복성을 제공합니다.
AWS는 AWS 리전에서 최소 3개의 가용영역에 걸쳐 여러 기기에 데이터를 저장합니다.
Microsoft Azure 선택한 리전 의 단일 데이터 센터 내에서 데이터를 세 번 복제하는 로컬 중복 저장 (LRS)를 사용합니다.
Google Cloud는 리전 의 여러 영역에 데이터를 분산합니다.
For more information about recommended regions, see Cloud Providers and Regions.
가장 중요한 애플리케이션의 내결함성을 더욱 개선하려면 가용영역, 리전 또는 공급자의 장애를 견딜 수 있도록 노드, 리전 또는 클라우드 공급자를 추가하여 배포서버를 확장할 수 있습니다. 투표 선택 가능 노드 최대 7개 및 총 노드 50개까지 홀수로 노드 수를 늘릴 수 있습니다. 또한 클러스터를 여러 리전에 배포하면 더 넓은 지역에 걸쳐 가용성을 향상하고, 전체 리전 장애가 발생하여 프라이머리 리전 내의 모든 가용영역이 비활성화되는 경우 자동 페일오버를 사용할 수 있습니다. 클라우드 공급자의 전체 장애를 견디기 위해 클러스터를 여러 클라우드 공급자에 배포하는 경우에도 동일한 패턴이 적용됩니다.
고가용성, 낮은 지연 시간, 컴플라이언스 및 비용 요구 사항을 균형 있게 충족하는 배포서버를 선택하는 방법은 Atlas 배포서버 패러다임 문서를 참조하세요.
배포 패러다임 RTO/RPO 절충안
다음 표에서는 다양한 배포서버 패러다임의 RTO 및 RPO 특성을 비교합니다. majority 쓰기 고려 (write concern) 사용하면 이러한 모든 접근 방식을 통해 RPO = 0 (데이터 손실 없음) 및 RTO를 몇 초 만에 달성할 수 있습니다. 단점은 배포서버 복잡성과 클러스터 비용 에 있습니다.
배포 패러다임 | 실패 시나리오 포함 | 일반 RTO | RPO(과반수 쓰기 고려 (write concern) 포함) | 상대적 복잡성 | 상대적 클러스터 비용 |
|---|---|---|---|---|---|
단일 리전 배포서버 (1 리전 의 3 노드) | 단일 리전 내의 노드 또는 AZ 장애 | 초(자동 페일오버) | 0 (데이터 손실 없음) | 낮은 | $ |
멀티 리전, 단일 클라우드 | 한 지역의 AZ 또는 리전 장애 | 초(자동 페일오버) | 0 (데이터 손실 없음) | 중간 | $$ |
멀티 리전, 다중 지역 | 여러 지역에 걸친 리전 또는 지리적 장애 | 초(자동 페일오버) | 0 (데이터 손실 없음) | 중간-높음 | $$–$$$ |
멀티 클라우드(2-3 제공자) | 한 제공자 에게 영향을 미치는 클라우드 공급자 또는 멀티 리전 장애 | 초(자동 페일오버) | 0 (데이터 손실 없음) | 높음 | $$$ |
실수로 인한 클러스터 삭제 방지
종료 방지 기능을 활성화해 클러스터가 실수로 종료되지 않도록 하고, 백업에서 복원할 때 가동 중단 시간이 발생하지 않도록 할 수 있습니다. 종료 보호가 활성화된 클러스터를 삭제하려면 먼저 종료 보호를 비활성화해야 합니다. 기본적으로 Atlas는 모든 클러스터에 대해 종료 보호를 비활성화합니다.
종료 보호는 재배포로 인해 새 인프라가 프로비저닝되지 않도록 보장하기 위해 Terraform과 같은 Infrastructure as Code 도구를 사용할 때 특히 중요합니다.
자동 페일오버 테스트
We strongly recommend that you simulate various scenarios that require automatic node failovers to measure your preparedness for such events before you deploy an application to production. With Atlas, you can test primary node failover for a replica set and simulate regional outages for a multi-region deployment.
majority 쓰기 고려 사용
MongoDB allows you to specify the level of acknowledgment requested for write operations by using write concern. Atlas has a default write concern of majority, meaning that data must be replicated across more than half of the nodes in your cluster before Atlas reports success. Using majority instead of a definite number value like 2 allows Atlas to automatically adjust to requiring replication across fewer nodes if you experience a temporary node outage, allowing writes to continue after automatic failover. This also provides a consistent setting across all environments, so your connection string remains the same whether you have three nodes in a test environment or a larger number of nodes in production.
재시도 가능 데이터베이스 읽기 및 쓰기 구성
Atlas supports retryable read and retryable write operations. When enabled, Atlas retries read and write operations once as a safeguard against intermittent network outages and replica set elections in which the application temporarily cannot find a healthy primary node. Retryable writes require an acknowledged write concern, meaning your write concern cannot be {w: 0}.
리소스 사용률 모니터링 및 계획
To avoid resource capacity issues, we recommend that you monitor resource utilization and hold regular capacity planning sessions. MongoDB's Professional Services offers these sessions. See our Resource Capacity Disaster Recovery Plan for our recommendations on how to recover from resource capacity issues.
리소스 사용률에 대한 경고 및 모니터링 모범 사례는 Atlas 모니터링 및 경고 지침을 참조하세요.
MongoDB 버전 변경 계획
We recommend that you run the latest MongoDB version to take advantage of new features and improved security guarantees. You should always ensure that you upgrade to the latest MongoDB major version before your current version reaches end of life.
MongoDB Atlas UI를 사용하는 MongoDB 버전은 다운그레이드할 수 없습니다. 따라서 주요 버전 업그레이드를 계획하고 실행할 때, 업그레이드 과정에서 발생할 수 있는 문제를 방지하기 위해 MongoDB의 Professional Services 또는 기술 서비스에 문의하는 것이 좋습니다.
유지 관리 기간 구성
Atlas는 예정된 유지 관리 동안 한 번에 하나의 노드에 롤링 방식으로 업데이트를 적용하여 가동 시간을 유지합니다. 이 프로세스가 진행되는 동안 유지 관리를 위해 현재 프라이머리가 오프라인으로 전환될 때마다 Atlas는 자동 복제본 세트 투표를 통해 새로운 프라이머리를 선택합니다. 이는 계획되지 않은 프라이머리 노드 장애에 대한 응답으로 자동 페일오버 중에 진행되는 것과 동일한 프로세스입니다.
We recommend that you configure a custom maintenance window for your project to avoid maintenance-related replica set elections during business-critical hours. You can also set protected hours in your maintenance window settings to define a daily window of time in which standard updates cannot begin. Standard updates do not involve cluster restarts or resyncs.
자동화 예시: Atlas 고가용성
다음 예제에서는 자동화3 위한 Atlas 도구를 사용하여 단일 리전, 노드 복제본 세트/샤드 배포서버 토폴로지 구성합니다.
이러한 예시는 다음을 포함한 다른 권장 구성에도 적용됩니다.
개발/테스트 환경을 위해 클러스터 계층을
M10으로 설정합니다. 애플리케이션 크기에 맞는 권장 클러스터 계층을 알아보려면 클러스터 크기 가이드를 참조하세요.단일 리전, 3-노드 복제본 세트/샤드 배포 토폴로지
Our examples use AWS, Azure, and Google Cloud interchangeably. You can use any of these three cloud providers, but you must change the region name to match the cloud provider. To learn about the cloud providers and their regions, see Cloud Providers.
중간 규모 애플리케이션을 위해 클러스터 계층을
M30으로 설정합니다. 애플리케이션 크기에 맞는 권장 클러스터 계층을 알아보려면 클러스터 크기 가이드를 참조하세요.단일 리전, 3-노드 복제본 세트/샤드 배포 토폴로지
Our examples use AWS, Azure, and Google Cloud interchangeably. You can use any of these three cloud providers, but you must change the region name to match the cloud provider. To learn about the cloud providers and their regions, see Cloud Providers.
참고
Atlas CLI로 리소스를 생성하기 전에 다음을 수행해야 합니다.
Create your paying organization and create an API key for the paying organization.
Connect from the Atlas CLI using the steps for Programmatic Use.
프로젝트당 하나의 배포 생성
개발 및 테스트 환경에서 각 프로젝트에 대해 다음 명령을 실행합니다. 다음 예시에서는 ID와 이름을 사용자의 값으로 변경합니다.
참고
다음 예시에서는 개발 및 테스트 환경에서 비용을 관리하는 데 도움이 되는 자동 확장을 사용하지 않습니다. 스테이징 및 프로덕션 환경에서는 자동 확장을 활성화해야 합니다. 자동 확장을 활성화하는 예시는 '스테이징 및 프로덕션 환경' 탭을 참조하세요.
atlas clusters create CustomerPortalDev \ --projectId 56fd11f25f23b33ef4c2a331 \ --region EASTERN_US \ --members 3 \ --tier M10 \ --provider GCP \ --mdbVersion 8.0 \ --diskSizeGB 30 \ --tag bu=ConsumerProducts \ --tag teamName=TeamA \ --tag appName=ProductManagementApp \ --tag env=dev \ --tag version=8.0 \ --tag email=marissa@example.com \ --watch
스테이징 및 프로덕션 환경의 경우 각 프로젝트에 대해 다음 cluster.json 파일을 생성합니다. ID와 이름을 사용자의 값으로 변경하세요.
{ "clusterType": "REPLICASET", "links": [], "name": "CustomerPortalProd", "mongoDBMajorVersion": "8.0", "replicationSpecs": [ { "numShards": 1, "regionConfigs": [ { "electableSpecs": { "instanceSize": "M30", "nodeCount": 3 }, "priority": 7, "providerName": "GCP", "regionName": "EASTERN_US", "analyticsSpecs": { "nodeCount": 0, "instanceSize": "M30" }, "autoScaling": { "compute": { "enabled": true, "scaleDownEnabled": true }, "diskGB": { "enabled": true } }, "readOnlySpecs": { "nodeCount": 0, "instanceSize": "M30" } } ], "zoneName": "Zone 1" } ], "tag" : [{ "bu": "ConsumerProducts", "teamName": "TeamA", "appName": "ProductManagementApp", "env": "Production", "version": "8.0", "email": "marissa@example.com" }] }
cluster.json 파일을 생성한 후 각 프로젝트에 대해 다음 명령을 실행합니다. 이 명령은 cluster.json 파일을 사용하여 클러스터를 생성합니다.
atlas cluster create --projectId 5e2211c17a3e5a48f5497de3 --file cluster.json
For more configuration options and info about this example, see the atlas clusters create command.
참고
Terraform으로 리소스를 생성하기 전에 다음을 수행해야 합니다.
Create your paying organization and create an API key for the paying organization. Store your API key as environment variables by running the following command in the terminal:
export MONGODB_ATLAS_PUBLIC_KEY="<insert your public key here>" export MONGODB_ATLAS_PRIVATE_KEY="<insert your private key here>"
중요
다음 예시에서는 MongoDB Atlas Terraform 제공자 버전 2.x(~> 2.2)를 사용합니다. 제공자 버전 1.x에서 업그레이드하는 경우 2.0.0 업그레이드 가이드에서 호환성이 손상되는 변경 및 마이그레이션 단계를 참조하세요. 이 예시에서는 mongodbatlas_advanced_cluster 리소스를 v2.x 구문과 함께 사용합니다.
프로젝트 및 배포 생성
개발 및 테스트 환경의 경우 각 애플리케이션 및 환경 쌍에 대해 다음 파일을 생성합니다. 각 애플리케이션 및 환경 쌍에 대한 파일을 자체 디렉토리 에 배치합니다. 값을 사용하도록 ID와 이름을 변경합니다.
main.tf
# Create a Project resource "mongodbatlas_project" "atlas-project" { org_id = var.atlas_org_id name = var.atlas_project_name } # Create an Atlas Advanced Cluster resource "mongodbatlas_advanced_cluster" "atlas-cluster" { project_id = mongodbatlas_project.atlas-project.id name = "ClusterPortalDev" cluster_type = "REPLICASET" mongo_db_major_version = var.mongodb_version # MongoDB recommends enabling auto-scaling # When auto-scaling is enabled, Atlas may change the instance size, and this use_effective_fields # block prevents Terraform from reverting Atlas auto-scaling changes use_effective_fields = true replication_specs = [ { region_configs = [ { electable_specs = { instance_size = var.cluster_instance_size_name node_count = 3 } auto_scaling = { compute_enabled = true compute_scale_down_enabled = true compute_max_instance_size = "M60" compute_min_instance_size = "M10" } priority = 7 provider_name = var.cloud_provider region_name = var.atlas_region } ] } ] tags = { BU = "ConsumerProducts" TeamName = "TeamA" AppName = "ProductManagementApp" Env = "Test" Version = "8.0" Email = "marissa@example.com" } } # Outputs to Display output "atlas_cluster_connection_string" { value = mongodbatlas_advanced_cluster.atlas-cluster.connection_strings.0.standard_srv } output "project_name" { value = mongodbatlas_project.atlas-project.name }
참고
멀티 리전 클러스터를 생성하려면 각 리전을 자체 region_configs 객체로 지정하고 이를 replication_specs 객체에 중첩합니다. priority 필드는 내림차순으로 정의되어야 하며 다음 예시와 같이 7과 1 사이의 값으로 구성되어야 합니다.
replication_specs = [ { region_configs = [ { electable_specs = { instance_size = "M10" node_count = 2 } auto_scaling = { compute_enabled = true compute_scale_down_enabled = true compute_max_instance_size = "M60" compute_min_instance_size = "M10" } provider_name = "GCP" priority = 7 region_name = "NORTH_AMERICA_NORTHEAST_1" }, { electable_specs = { instance_size = "M10" node_count = 3 } auto_scaling = { compute_enabled = true compute_scale_down_enabled = true compute_max_instance_size = "M60" compute_min_instance_size = "M10" } provider_name = "GCP" priority = 6 region_name = "WESTERN_US" } ] } ]
variables.tf
# MongoDB Atlas Provider Authentication Variables # Legacy API key authentication (backward compatibility) variable "mongodbatlas_public_key" { type = string description = "MongoDB Atlas API public key" sensitive = true } variable "mongodbatlas_private_key" { type = string description = "MongoDB Atlas API private key" sensitive = true } # Recommended: Service account authentication variable "mongodb_service_account_id" { type = string description = "MongoDB service account ID for authentication" sensitive = true default = null } variable "mongodb_service_account_key_file" { type = string description = "Path to MongoDB service account private key file" sensitive = true default = null } # Atlas Organization ID variable "atlas_org_id" { type = string description = "Atlas Organization ID" } # Atlas Project Name variable "atlas_project_name" { type = string description = "Atlas Project Name" } # Atlas Project Environment variable "environment" { type = string description = "The environment to be built" } # Cluster Instance Size Name variable "cluster_instance_size_name" { type = string description = "Cluster instance size name" } # Cloud Provider to Host Atlas Cluster variable "cloud_provider" { type = string description = "AWS or GCP or Azure" } # Atlas Region variable "atlas_region" { type = string description = "Atlas region where resources will be created" } # MongoDB Version variable "mongodb_version" { type = string description = "MongoDB Version" } # Atlas Group Name variable "atlas_group_name" { type = string description = "Atlas Group Name" }
terraform.tfvars
atlas_org_id = "32b6e34b3d91647abb20e7b8" atlas_project_name = "Customer Portal - Dev" environment = "dev" cluster_instance_size_name = "M10" cloud_provider = "AWS" atlas_region = "US_WEST_2" mongodb_version = "8.0"
provider.tf
# Define the MongoDB Atlas Provider terraform { required_providers { mongodbatlas = { source = "mongodb/mongodbatlas" version = "~> 2.2" } } required_version = ">= 1.0" } # Configure the MongoDB Atlas Provider provider "mongodbatlas" { # Legacy API key authentication (backward compatibility) public_key = var.mongodbatlas_public_key private_key = var.mongodbatlas_private_key # Recommended: Service account authentication # Uncomment and configure the following for service account auth: # service_account_id = var.mongodb_service_account_id # private_key_file = var.mongodb_service_account_key_file }
파일을 생성한 후 각 애플리케이션과 환경 쌍의 디렉토리로 이동하여 다음 명령을 실행하여 Terraform을 초기화합니다.
terraform init
Terraform 계획을 보려면 다음 명령을 실행합니다.
terraform plan
Run the following command to create one project and one deployment for the application and environment pair. The command uses the files and the MongoDB & HashiCorp Terraform to create the projects and clusters:
terraform apply
메시지가 표시되면 yes를 입력하고 Enter 키를 눌러 구성을 적용합니다.
스테이징 및 프로덕션 환경의 경우 각 애플리케이션과 환경 쌍에 대해 다음 파일을 생성하세요. 각 애플리케이션과 환경 쌍의 파일은 별도의 디렉토리에 배치하세요. ID와 이름을 사용자의 값으로 변경하세요.
main.tf
# Create a Group to Assign to Project resource "mongodbatlas_team" "project_group" { org_id = var.atlas_org_id name = var.atlas_group_name usernames = [ "user1@example.com", "user2@example.com" ] } # Create a Project resource "mongodbatlas_project" "atlas-project" { org_id = var.atlas_org_id name = var.atlas_project_name } # Assign the team to project with specific roles resource "mongodbatlas_team_project_assignment" "project_team" { project_id = mongodbatlas_project.atlas-project.id team_id = mongodbatlas_team.project_group.team_id role_names = ["GROUP_READ_ONLY", "GROUP_CLUSTER_MANAGER"] } # Create an Atlas Advanced Cluster resource "mongodbatlas_advanced_cluster" "atlas-cluster" { project_id = mongodbatlas_project.atlas-project.id name = "ClusterPortalProd" cluster_type = "REPLICASET" mongo_db_major_version = var.mongodb_version use_effective_fields = true replication_specs = [ { region_configs = [ { electable_specs = { instance_size = var.cluster_instance_size_name node_count = 3 disk_size_gb = var.disk_size_gb } auto_scaling = { disk_gb_enabled = var.auto_scaling_disk_gb_enabled compute_enabled = var.auto_scaling_compute_enabled compute_max_instance_size = var.compute_max_instance_size } priority = 7 provider_name = var.cloud_provider region_name = var.atlas_region } ] } ] tags = { BU = "ConsumerProducts" TeamName = "TeamA" AppName = "ProductManagementApp" Env = "Production" Version = "8.0" Email = "marissa@example.com" } } # Outputs to Display output "atlas_cluster_connection_string" { value = mongodbatlas_advanced_cluster.atlas-cluster.connection_strings.standard_srv } output "project_name" { value = mongodbatlas_project.atlas-project.name }
참고
멀티 리전 클러스터를 생성하려면 각 리전을 고유한 region_configs 객체에 지정하고, 이를 replication_specs 객체에 중첩시킵니다. 다음 예시를 참조하세요.
replication_specs = [ { region_configs = [ { electable_specs = { instance_size = "M10" node_count = 2 } provider_name = "GCP" priority = 7 region_name = "NORTH_AMERICA_NORTHEAST_1" }, { electable_specs = { instance_size = "M10" node_count = 3 } provider_name = "GCP" priority = 6 region_name = "WESTERN_US" } ] } ]
variables.tf
# MongoDB Atlas Provider Authentication Variables # Legacy API key authentication (backward compatibility) variable "mongodbatlas_public_key" { type = string description = "MongoDB Atlas API public key" sensitive = true } variable "mongodbatlas_private_key" { type = string description = "MongoDB Atlas API private key" sensitive = true } # Recommended: Service account authentication variable "mongodb_service_account_id" { type = string description = "MongoDB service account ID for authentication" sensitive = true default = null } variable "mongodb_service_account_key_file" { type = string description = "Path to MongoDB service account private key file" sensitive = true default = null } # Atlas Organization ID variable "atlas_org_id" { type = string description = "Atlas Organization ID" } # Atlas Project Name variable "atlas_project_name" { type = string description = "Atlas Project Name" } # Atlas Project Environment variable "environment" { type = string description = "The environment to be built" } # Cluster Instance Size Name variable "cluster_instance_size_name" { type = string description = "Cluster instance size name" } # Cloud Provider to Host Atlas Cluster variable "cloud_provider" { type = string description = "AWS or GCP or Azure" } # Atlas Region variable "atlas_region" { type = string description = "Atlas region where resources will be created" } # MongoDB Version variable "mongodb_version" { type = string description = "MongoDB Version" } # Atlas Group Name variable "atlas_group_name" { type = string description = "Atlas Group Name" }
terraform.tfvars
atlas_org_id = "32b6e34b3d91647abb20e7b8" atlas_project_name = "Customer Portal - Prod" environment = "prod" cluster_instance_size_name = "M30" cloud_provider = "AWS" atlas_region = "US_WEST_2" mongodb_version = "8.0" atlas_group_name = "Atlas Group"
provider.tf
# Define the MongoDB Atlas Provider terraform { required_providers { mongodbatlas = { source = "mongodb/mongodbatlas" version = "~> 2.2" } } required_version = ">= 1.0" } # Configure the MongoDB Atlas Provider provider "mongodbatlas" { # Legacy API key authentication (backward compatibility) public_key = var.mongodbatlas_public_key private_key = var.mongodbatlas_private_key # Recommended: Service account authentication # Uncomment and configure the following for service account auth: # service_account_id = var.mongodb_service_account_id # private_key_file = var.mongodb_service_account_key_file }
파일을 생성한 후 각 애플리케이션과 환경 쌍의 디렉토리로 이동하여 다음 명령을 실행하여 Terraform을 초기화합니다.
terraform init
Terraform 계획을 보려면 다음 명령을 실행합니다.
terraform plan
Run the following command to create one project and one deployment for the application and environment pair. The command uses the files and the MongoDB & HashiCorp Terraform to create the projects and clusters:
terraform apply
메시지가 표시되면 yes를 입력하고 Enter 키를 눌러 구성을 적용합니다.
이 예시에 대한 더 많은 구성 옵션 및 정보는 MongoDB & HashiCorp Terraform을 참조하세요.