Skip to content

Commit

Permalink
INTMDB-128: Modified design when you can get .id from various resourc…
Browse files Browse the repository at this point in the history
…es (#471)

* refactor: added func to get encoded id, when you want to use by implicit depedency with id from various resources instead of another id like container_id

* fixes linter

* added terrates to show it passes

* update sate id

Co-authored-by: Edgar López <[email protected]>
  • Loading branch information
coderGo93 and Edgar López authored Jun 10, 2021
1 parent da9c05a commit 37ab770
Show file tree
Hide file tree
Showing 34 changed files with 553 additions and 38 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
data "mongodbatlas_project" "test" {
name = var.project_name
}

resource "mongodbatlas_alert_configuration" "test" {
project_id = data.mongodbatlas_project.test.id
event_type = "OUTSIDE_METRIC_THRESHOLD"
enabled = true

notification {
type_name = "GROUP"
interval_min = 5
delay_min = 0
sms_enabled = false
email_enabled = true
}

matcher {
field_name = "HOSTNAME_AND_PORT"
operator = "EQUALS"
value = "SECONDARY"
}

metric_threshold = {
metric_name = "ASSERT_REGULAR"
operator = "LESS_THAN"
threshold = 99.0
units = "RAW"
mode = "AVERAGE"
}
}

data "mongodbatlas_alert_configuration" "test" {
project_id = mongodbatlas_alert_configuration.test.project_id
alert_configuration_id = mongodbatlas_alert_configuration.test.id
}

output "alert_id_state" {
value = mongodbatlas_alert_configuration.test.id
}
output "alert_configuration_id" {
value = mongodbatlas_alert_configuration.test.alert_configuration_id
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
variable "public_key" {
description = "The public API key for MongoDB Atlas"
default = ""
}
variable "private_key" {
description = "The private API key for MongoDB Atlas"
default = ""
}
variable "project_name" {
description = "Atlas project name"
default = ""
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
terraform {
required_providers {
mongodbatlas = {
source = "mongodb/mongodbatlas"
version = "0.1.0-dev"
}
}
required_version = ">= 0.13"
}
38 changes: 38 additions & 0 deletions examples/test-upgrade/v100/design-id-reference/network/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
data "mongodbatlas_project" "test" {
name = var.project_name
}

resource "mongodbatlas_network_container" "test" {
project_id = data.mongodbatlas_project.test.id
atlas_cidr_block = "192.168.208.0/21"
provider_name = "AWS"
region_name = var.region_name
}

resource "mongodbatlas_network_peering" "test" {
accepter_region_name = lower(replace(var.region_name, "_", "-"))
project_id = data.mongodbatlas_project.test.id
container_id = mongodbatlas_network_container.test.id
provider_name = "AWS"
route_table_cidr_block = var.route_table_cidr_block
vpc_id = var.vpc_id
aws_account_id = var.aws_account_id
}

data "mongodbatlas_network_peering" "test" {
project_id = data.mongodbatlas_project.test.id
peering_id = mongodbatlas_network_peering.test.peer_id
}

output "container_id_state" {
value = mongodbatlas_network_container.test.id
}
output "container_id" {
value = mongodbatlas_network_container.test.container_id
}
output "peering_id_state" {
value = mongodbatlas_network_peering.test.id
}
output "peer_id" {
value = mongodbatlas_network_peering.test.peer_id
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
variable "public_key" {
description = "The public API key for MongoDB Atlas"
default = ""
}
variable "private_key" {
description = "The private API key for MongoDB Atlas"
default = ""
}
variable "project_name" {
description = "Atlas project name"
default = ""
}
variable "region_name" {
description = "AWS region "
default = ""
}
variable "route_table_cidr_block" {
description = "CIDR Block"
default = ""
}
variable "vpc_id" {
description = "AWS VPC ID"
default = ""
}
variable "aws_account_id" {
description = "AWS account id"
default = ""
}


Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
terraform {
required_providers {
mongodbatlas = {
source = "mongodb/mongodbatlas"
version = "0.1.0-dev"
}
}
required_version = ">= 0.13"
}
56 changes: 56 additions & 0 deletions examples/test-upgrade/v100/design-id-reference/privatelink/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
data "mongodbatlas_project" "test" {
name = var.project_name
}

provider "aws" {
region = "us-west-1"
access_key = var.aws_access_key
secret_key = var.aws_secret_key
}

resource "mongodbatlas_privatelink_endpoint" "test" {
project_id = data.mongodbatlas_project.test.id
provider_name = "AWS"
region = "us-west-1"
}

resource "aws_vpc_endpoint" "ptfe_service" {
vpc_id = var.aws_vpc_id
service_name = mongodbatlas_privatelink_endpoint.test.endpoint_service_name
vpc_endpoint_type = "Interface"
subnet_ids = [var.aws_subnet_ids]
security_group_ids = [var.aws_sg_ids]
}

resource "mongodbatlas_privatelink_endpoint_service" "test" {
project_id = data.mongodbatlas_project.test.id
private_link_id = mongodbatlas_privatelink_endpoint.test.id
endpoint_service_id = aws_vpc_endpoint.ptfe_service.id
provider_name = "AWS"
}

data "mongodbatlas_privatelink_endpoint" "test" {
project_id = data.mongodbatlas_project.test.id
private_link_id = mongodbatlas_privatelink_endpoint.test.id
provider_name = "AWS"
}

data "mongodbatlas_privatelink_endpoint_service" "test" {
project_id = data.mongodbatlas_project.test.id
private_link_id = mongodbatlas_privatelink_endpoint_service.test.id
endpoint_service_id = mongodbatlas_privatelink_endpoint_service.test.endpoint_service_id
provider_name = "AWS"
}

output "privatelink_id_state" {
value = mongodbatlas_privatelink_endpoint.test.id
}
output "private_link_id" {
value = mongodbatlas_privatelink_endpoint.test.private_link_id
}
output "privatelink_endpoint_service_state" {
value = mongodbatlas_privatelink_endpoint_service.test.id
}
output "endpoint_service_id" {
value = mongodbatlas_privatelink_endpoint_service.test.endpoint_service_id
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
variable "public_key" {
description = "The public API key for MongoDB Atlas"
default = ""
}
variable "private_key" {
description = "The private API key for MongoDB Atlas"
default = ""
}
variable "project_name" {
description = "Atlas project name"
default = ""
}
variable "org_id" {
description = "The organization ID"
default = ""
}
variable "role_name" {
description = "The role name"
default = ""
}
variable "aws_access_key" {
description = "The access key for AWS Account"
default = ""
}
variable "aws_secret_key" {
description = "The secret key for AWS Account"
default = ""
}
variable "aws_vpc_id" {
description = "The secret key for AWS Account"
default = ""
}
variable "aws_subnet_ids" {
description = "The secret key for AWS Account"
default = ""
}
variable "aws_sg_ids" {
description = "The secret key for AWS Account"
default = ""
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
terraform {
required_providers {
mongodbatlas = {
source = "mongodb/mongodbatlas"
version = "0.1.0-dev"
}
}
required_version = ">= 0.13"
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
resource "mongodbatlas_project" "test" {
name = var.project_name
org_id = var.org_id
}

output "project_id" {
value = mongodbatlas_project.test.id
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
variable "public_key" {
description = "The public API key for MongoDB Atlas"
default = ""
}
variable "private_key" {
description = "The private API key for MongoDB Atlas"
default = ""
}
variable "project_name" {
description = "Atlas project name"
default = ""
}
variable "org_id" {
description = "The organization ID"
default = ""
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
terraform {
required_providers {
mongodbatlas = {
source = "mongodb/mongodbatlas"
version = "0.1.0-dev"
}
}
required_version = ">= 0.13"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
data "mongodbatlas_project" "test" {
name = var.project_name
}

resource "mongodbatlas_cluster" "my_cluster" {
project_id = data.mongodbatlas_project.test.id
name = var.cluster_name
disk_size_gb = 5

// Provider Settings "block"
provider_name = "AWS"
provider_region_name = "US_EAST_1"
provider_instance_size_name = "M10"
provider_backup_enabled = true //enable cloud provider snapshots
provider_encrypt_ebs_volume = false
}

resource "mongodbatlas_cloud_provider_snapshot" "test" {
project_id = data.mongodbatlas_project.test.id
cluster_name = mongodbatlas_cluster.my_cluster.name
description = var.description
retention_in_days = var.retention_in_days
}

resource "mongodbatlas_cloud_provider_snapshot_restore_job" "test" {
project_id = data.mongodbatlas_project.test.id
cluster_name = mongodbatlas_cloud_provider_snapshot.test.cluster_name
snapshot_id = mongodbatlas_cloud_provider_snapshot.test.id
delivery_type = {
download = true
}
}

data "mongodbatlas_cloud_provider_snapshot_restore_job" "test" {
project_id = data.mongodbatlas_project.test.id
cluster_name = mongodbatlas_cloud_provider_snapshot_restore_job.test.cluster_name
job_id = mongodbatlas_cloud_provider_snapshot_restore_job.test.id
}

output "snapshot_id_state" {
value = mongodbatlas_cloud_provider_snapshot.test.id
}
output "snapshot_id" {
value = mongodbatlas_cloud_provider_snapshot.test.snapshot_id
}
output "snapshot_restore_id_state" {
value = mongodbatlas_cloud_provider_snapshot_restore_job.test.id
}
output "snapshot_restore_job_id" {
value = mongodbatlas_cloud_provider_snapshot_restore_job.test.snapshot_restore_job_id
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
variable "public_key" {
description = "The public API key for MongoDB Atlas"
default = ""
}
variable "private_key" {
description = "The private API key for MongoDB Atlas"
default = ""
}
variable "project_name" {
description = "Atlas project name"
default = ""
}
variable "cluster_name" {
description = "Cluster name"
default = ""
}
variable "description" {
description = "Description"
default = ""
}
variable "retention_in_days" {
description = "Retention in days"
default = ""
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
terraform {
required_providers {
mongodbatlas = {
source = "mongodb/mongodbatlas"
version = "0.1.0-dev"
}
}
required_version = ">= 0.13"
}

Loading

0 comments on commit 37ab770

Please sign in to comment.