Skip to content

Commit 5d01dfc

Browse files
INTMDB-299: Support Cloud Backup Export Jobs (#673)
* added snapshot export bucket resource and datasource * added integration test * fix go.mod issue * minor fixes * added snapshot export job support Co-authored-by: Abner Garcia <[email protected]>
1 parent bece783 commit 5d01dfc

File tree

33 files changed

+2351
-3
lines changed

33 files changed

+2351
-3
lines changed
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
resource "aws_iam_role_policy" "test_policy" {
2+
name = "mongo_setup_policy"
3+
role = aws_iam_role.test_role.id
4+
5+
policy = <<-EOF
6+
{
7+
"Version": "2012-10-17",
8+
"Statement": [
9+
{
10+
"Effect": "Allow",
11+
"Action": "*",
12+
"Resource": "*"
13+
}
14+
]
15+
}
16+
EOF
17+
}
18+
19+
resource "aws_iam_role" "test_role" {
20+
name = "mongo_setup_test_role"
21+
22+
assume_role_policy = <<EOF
23+
{
24+
"Version": "2012-10-17",
25+
"Statement": [
26+
{
27+
"Effect": "Allow",
28+
"Principal": {
29+
"AWS": "${mongodbatlas_cloud_provider_access_setup.setup_only.aws_config[0].atlas_aws_account_arn}"
30+
},
31+
"Action": "sts:AssumeRole",
32+
"Condition": {
33+
"StringEquals": {
34+
"sts:ExternalId": "${mongodbatlas_cloud_provider_access_setup.setup_only.aws_config[0].atlas_assumed_role_external_id}"
35+
}
36+
}
37+
}
38+
]
39+
}
40+
EOF
41+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
resource "mongodbatlas_cloud_provider_access_setup" "setup_only" {
2+
project_id = var.project_id
3+
provider_name = "AWS"
4+
}
5+
6+
resource "mongodbatlas_cloud_provider_access_authorization" "auth_role" {
7+
project_id = var.project_id
8+
role_id = mongodbatlas_cloud_provider_access_setup.setup_only.role_id
9+
10+
aws {
11+
iam_assumed_role_arn = aws_iam_role.test_role.arn
12+
}
13+
}
14+
15+
16+
resource "aws_s3_bucket" "test_bucket" {
17+
bucket = "mongo-test-bucket-1"
18+
19+
tags = {
20+
Name = "My bucket"
21+
Environment = "Dev"
22+
}
23+
}
24+
25+
resource "mongodbatlas_cloud_backup_snapshot_export_bucket" "test" {
26+
project_id = var.project_id
27+
28+
iam_role_id = mongodbatlas_cloud_provider_access_authorization.auth_role.role_id
29+
bucket_name = aws_s3_bucket.test_bucket.bucket
30+
cloud_provider = "AWS"
31+
}
32+
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
provider "mongodbatlas" {
2+
public_key = var.public_key
3+
private_key = var.private_key
4+
}
5+
provider "aws" {
6+
access_key = var.access_key
7+
secret_key = var.secret_key
8+
region = var.aws_region
9+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
variable "public_key" {
2+
description = "The public API key for MongoDB Atlas"
3+
default = ""
4+
}
5+
variable "private_key" {
6+
description = "The private API key for MongoDB Atlas"
7+
default = ""
8+
}
9+
variable "project_id" {
10+
description = "Atlas project ID"
11+
default = ""
12+
}
13+
variable "access_key" {
14+
description = "The access key for AWS Account"
15+
default = ""
16+
}
17+
variable "secret_key" {
18+
description = "The secret key for AWS Account"
19+
default = ""
20+
}
21+
variable "aws_region" {
22+
default = ""
23+
description = "AWS Region"
24+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
terraform {
2+
required_providers {
3+
aws = {
4+
source = "hashicorp/aws"
5+
}
6+
mongodbatlas = {
7+
source = "mongodb/mongodbatlas"
8+
}
9+
}
10+
required_version = ">= 0.13"
11+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
resource "aws_iam_role_policy" "test_policy" {
2+
name = "mongo_setup_policy"
3+
role = aws_iam_role.test_role.id
4+
5+
policy = <<-EOF
6+
{
7+
"Version": "2012-10-17",
8+
"Statement": [
9+
{
10+
"Effect": "Allow",
11+
"Action": "*",
12+
"Resource": "*"
13+
}
14+
]
15+
}
16+
EOF
17+
}
18+
19+
resource "aws_iam_role" "test_role" {
20+
name = "mongo_setup_test_role"
21+
22+
assume_role_policy = <<EOF
23+
{
24+
"Version": "2012-10-17",
25+
"Statement": [
26+
{
27+
"Effect": "Allow",
28+
"Principal": {
29+
"AWS": "${mongodbatlas_cloud_provider_access_setup.setup_only.aws_config[0].atlas_aws_account_arn}"
30+
},
31+
"Action": "sts:AssumeRole",
32+
"Condition": {
33+
"StringEquals": {
34+
"sts:ExternalId": "${mongodbatlas_cloud_provider_access_setup.setup_only.aws_config[0].atlas_assumed_role_external_id}"
35+
}
36+
}
37+
}
38+
]
39+
}
40+
EOF
41+
}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
resource "mongodbatlas_cloud_provider_access_setup" "setup_only" {
2+
project_id = var.project_id
3+
provider_name = "AWS"
4+
}
5+
6+
resource "mongodbatlas_cloud_provider_access_authorization" "auth_role" {
7+
project_id = var.project_id
8+
role_id = mongodbatlas_cloud_provider_access_setup.setup_only.role_id
9+
10+
aws {
11+
iam_assumed_role_arn = aws_iam_role.test_role.arn
12+
}
13+
}
14+
15+
16+
resource "aws_s3_bucket" "test_bucket" {
17+
bucket = "mongo-test-bucket-1"
18+
19+
tags = {
20+
Name = "My bucket"
21+
Environment = "Dev"
22+
}
23+
}
24+
25+
resource "mongodbatlas_cluster" "my_cluster" {
26+
project_id = var.project_id
27+
name = "MyCluster"
28+
disk_size_gb = 1
29+
30+
provider_name = "AWS"
31+
provider_region_name = "US_EAST_1"
32+
provider_instance_size_name = "M10"
33+
cloud_backup = true
34+
}
35+
36+
resource "mongodbatlas_cloud_backup_snapshot" "test" {
37+
project_id = var.project_id
38+
cluster_name = mongodbatlas_cluster.my_cluster.name
39+
description = "myDescription"
40+
retention_in_days = 1
41+
}
42+
43+
resource "mongodbatlas_cloud_backup_snapshot_export_bucket" "test" {
44+
project_id = var.project_id
45+
46+
iam_role_id = mongodbatlas_cloud_provider_access_authorization.auth_role.role_id
47+
bucket_name = aws_s3_bucket.test_bucket.bucket
48+
cloud_provider = "AWS"
49+
}
50+
51+
resource "mongodbatlas_cloud_backup_snapshot_export_job" "test" {
52+
project_id = var.project_id
53+
cluster_name = mongodbatlas_cluster.my_cluster.name
54+
snapshot_id = mongodbatlas_cloud_backup_snapshot.test.snapshot_id
55+
export_bucket_id = mongodbatlas_cloud_backup_snapshot_export_bucket.test.export_bucket_id
56+
57+
58+
custom_data {
59+
key = "exported by"
60+
value = "myName"
61+
}
62+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
provider "mongodbatlas" {
2+
public_key = var.public_key
3+
private_key = var.private_key
4+
}
5+
provider "aws" {
6+
access_key = var.access_key
7+
secret_key = var.secret_key
8+
region = "us-east-1"
9+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
variable "public_key" {
2+
description = "The public API key for MongoDB Atlas"
3+
default = ""
4+
}
5+
variable "private_key" {
6+
description = "The private API key for MongoDB Atlas"
7+
default = ""
8+
}
9+
variable "project_id" {
10+
description = "Atlas project ID"
11+
default = ""
12+
}
13+
variable "access_key" {
14+
description = "The access key for AWS Account"
15+
default = ""
16+
}
17+
variable "secret_key" {
18+
description = "The secret key for AWS Account"
19+
default = ""
20+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
terraform {
2+
required_providers {
3+
aws = {
4+
source = "hashicorp/aws"
5+
}
6+
mongodbatlas = {
7+
source = "mongodb/mongodbatlas"
8+
}
9+
}
10+
required_version = ">= 0.13"
11+
}

0 commit comments

Comments
 (0)