Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

doc: Updates examples & docs that use replicaSet clusters #2428

Merged
merged 31 commits into from
Jul 18, 2024
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
0e6a89f
update basic examples
lantoli Jul 16, 2024
f148ae7
Merge branch 'master' into CLOUDP-260977_cluster_examples
lantoli Jul 16, 2024
6ea079e
fix linter
lantoli Jul 17, 2024
28e4c82
fix tf-validate
lantoli Jul 17, 2024
47886df
update tflint version
lantoli Jul 17, 2024
c8fb713
fix validate
lantoli Jul 17, 2024
2bffd43
remove tf linter exceptions
lantoli Jul 17, 2024
837cf4f
Merge branch 'master' into CLOUDP-260977_cluster_examples
lantoli Jul 17, 2024
5d918bf
make linter fail
lantoli Jul 17, 2024
164f644
simplify and show linter errors in GH
lantoli Jul 17, 2024
3db3316
tlint problem matcher
lantoli Jul 17, 2024
9976946
problem matcher
lantoli Jul 17, 2024
4cfb163
minimum severity warning
lantoli Jul 17, 2024
744f4c7
fix linter
lantoli Jul 17, 2024
fce2f18
make tf-validate logic easier to be run in local
lantoli Jul 17, 2024
e53b7fa
less verbose tf init
lantoli Jul 17, 2024
945057e
fix /mongodbatlas_network_peering/aws
lantoli Jul 17, 2024
f48f5b2
doc for backup_compliance_policy
lantoli Jul 17, 2024
5c310e4
fix container_id reference
lantoli Jul 17, 2024
54a5751
fix mongodbatlas_network_peering/azure
lantoli Jul 17, 2024
87da7b7
use temp fodler
lantoli Jul 17, 2024
f56d1c8
fix examples/mongodbatlas_network_peering/gcp
lantoli Jul 17, 2024
2401ec9
remaining examples
lantoli Jul 17, 2024
bb71c4a
fix mongodbatlas_clusters
lantoli Jul 17, 2024
c350caa
fix adv_cluster doc
lantoli Jul 17, 2024
115180e
remaining doc changes
lantoli Jul 18, 2024
63c97b8
fix typo
lantoli Jul 18, 2024
8ecaf0f
fix examples with deprecated arguments
lantoli Jul 18, 2024
cf4327e
get the first value for containter_id
lantoli Jul 18, 2024
c5043a0
container_id in doc
lantoli Jul 18, 2024
e27302a
address feedback
lantoli Jul 18, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions .github/tflint-matcher.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"problemMatcher": [
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to show TF linter errors in GH UI

{
"owner": "tflint-compact",
"severity": "warning",
"pattern": [
{
"regexp": "^(.+):(\\d+):(\\d+):\\s(Error|Warning|Notice)\\s-\\s(.+)\\s\\((.+)\\)$",
"file": 1,
"line": 2,
"column": 3,
"severity": 4,
"message": 5,
"code": 6
}
]
}
]
}
33 changes: 4 additions & 29 deletions .github/workflows/examples.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,52 +15,27 @@ env:
jobs:
tf-validate:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
terraform_version: ["${{vars.TF_VERSION_LATEST}}"]
permissions: {}
steps:
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332
with:
fetch-depth: 0
- run: echo "GO_VERSION=$(cat .go-version)" >> "${GITHUB_ENV}"
- uses: actions/setup-go@0a12ed9d6a96ab950c8f026ed9f722fe0da7ef32
with:
go-version-file: 'go.mod'
- name: go build
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

make it easier to run TF validate in local, so no magic is done in GH Actions and everything happens in the script

run: go build -o terraform-plugin-dir/terraform-provider-mongodbatlas-dev_v99.99.99_x5 .
- name: override plugin
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you clarify how the override of our provider is handled now?

Copy link
Member Author

@lantoli lantoli Jul 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

run: |
# For newer versions
mkdir -p ~/.terraform.d/plugins/registry.terraform.io/hashicorp/mongodbatlas-dev/99.99.99/"$(go env GOOS)"_"$(go env GOARCH)"/
cp terraform-plugin-dir/terraform-provider-mongodbatlas-dev_v99.99.99_x5 ~/.terraform.d/plugins/registry.terraform.io/hashicorp/mongodbatlas-dev/99.99.99/"$(go env GOOS)"_"$(go env GOARCH)"/
- name: replace names of provider for local development
run: grep --include=\*versions.tf -rnl './examples' -e 'source = "mongodb/mongodbatlas"' | xargs sed -i s@mongodb/mongodbatlas@hashicorp/mongodbatlas-dev@g
- name: remove version of provider for local development
run: grep --include=\*versions.tf -rnl './examples' -e 'version =' | xargs sed -i '/^\s*version =/d'
- name: Fix format after substitutions
run: grep --include=\*versions.tf -rnl './examples' -e 'source[[:space:]]\+=' | xargs sed -i 's@\(\([[:space:]]*\)source\)[[:space:]]\+=[[:space:]]*@\2source = @g'
- uses: hashicorp/setup-terraform@651471c36a6092792c552e8b1bef71e592b462d8
with:
terraform_version: ${{ matrix.terraform_version }}
# Needed to use the output of `terraform validate -json`
terraform_version: ${{ vars.TF_VERSION_LATEST }}
terraform_wrapper: false
- name: tf-validate
run: make tools tf-validate
tflint:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
terraform_version: ["${{vars.TF_VERSION_LATEST}}"]
permissions: {}
steps:
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332
with:
fetch-depth: 0
- uses: actions/setup-go@0a12ed9d6a96ab950c8f026ed9f722fe0da7ef32
with:
go-version-file: 'go.mod'
- name: tflint
run: make tools tflint
run: |
echo "::add-matcher::.github/tflint-matcher.json"
make tools tflint
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ terraform.tfplan
terraform.tfstate
.terraform.lock.hcl
bin/
bin-examples/
/pkg/
.vagrant/
*.backup
Expand Down
6 changes: 3 additions & 3 deletions GNUmakefile
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ lint:
tools: ## Install dev tools
@echo "==> Installing dependencies..."
go install github.com/icholy/gomajor@latest
go install github.com/terraform-linters/tflint@v0.49.0
go install github.com/terraform-linters/tflint@v0.52.0
go install github.com/rhysd/actionlint/cmd/actionlint@latest
go install golang.org/x/tools/go/analysis/passes/fieldalignment/cmd/fieldalignment@latest
go install github.com/hashicorp/terraform-plugin-docs/cmd/tfplugindocs@latest
Expand All @@ -91,11 +91,11 @@ docs:

.PHONY: tflint
tflint: fmtcheck
@scripts/tflint.sh
tflint -f compact --recursive --minimum-failure-severity=warning

.PHONY: tf-validate
tf-validate: fmtcheck
@scripts/tf-validate.sh
scripts/tf-validate.sh

.PHONY: link-git-hooks
link-git-hooks: ## Install git hooks
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ terraform {
required_providers {
mongodbatlas = {
source = "mongodb/mongodbatlas"
version = "~> 1.13.2"
version = "~> 1.0"
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so it can run with the current provider (version >= 1, < 2)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is it possible that for versions below 1.13.2 this examples does not work? Cant recall in what version we made changes to the pak resources.

}
}
required_version = ">= 1.0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ terraform {
required_providers {
mongodbatlas = {
source = "mongodb/mongodbatlas"
version = "~> 1.13.2"
version = "~> 1.0"
}
}
required_version = ">= 1.0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ terraform {
required_providers {
mongodbatlas = {
source = "mongodb/mongodbatlas"
version = "~> 1.13.2"
version = "~> 1.0"
}
}
required_version = ">= 1.0"
Expand Down
30 changes: 19 additions & 11 deletions examples/mongodbatlas_cloud_backup_snapshot_export_job/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,28 @@ resource "aws_s3_bucket" "test_bucket" {
}
}

resource "mongodbatlas_cluster" "my_cluster" {
project_id = var.project_id
name = "MyCluster"
disk_size_gb = 1

provider_name = "AWS"
provider_region_name = "US_EAST_1"
provider_instance_size_name = "M10"
cloud_backup = true
resource "mongodbatlas_advanced_cluster" "my_cluster" {
project_id = var.project_id
name = "MyCluster"
cluster_type = "REPLICASET"
backup_enabled = true

replication_specs {
region_configs {
priority = 7
provider_name = "AWS"
region_name = "US_EAST_1"
electable_specs {
instance_size = "M10"
node_count = 3
}
}
}
}

resource "mongodbatlas_cloud_backup_snapshot" "test" {
project_id = var.project_id
cluster_name = mongodbatlas_cluster.my_cluster.name
cluster_name = mongodbatlas_advanced_cluster.my_cluster.name
description = "myDescription"
retention_in_days = 1
}
Expand All @@ -50,7 +58,7 @@ resource "mongodbatlas_cloud_backup_snapshot_export_bucket" "test" {

resource "mongodbatlas_cloud_backup_snapshot_export_job" "test" {
project_id = var.project_id
cluster_name = mongodbatlas_cluster.my_cluster.name
cluster_name = mongodbatlas_advanced_cluster.my_cluster.name
snapshot_id = mongodbatlas_cloud_backup_snapshot.test.snapshot_id
export_bucket_id = mongodbatlas_cloud_backup_snapshot_export_bucket.test.export_bucket_id

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,31 @@ resource "mongodbatlas_project" "project_test" {
org_id = var.org_id
}

resource "mongodbatlas_cluster" "cluster_test" {
project_id = mongodbatlas_project.project_test.id
name = var.cluster_name
resource "mongodbatlas_advanced_cluster" "cluster_test" {
project_id = mongodbatlas_project.project_test.id
name = var.cluster_name
cluster_type = "REPLICASET"

# Provider Settings "block"
provider_name = "AWS"
provider_region_name = "US_EAST_1"
provider_instance_size_name = "M10"
cloud_backup = true # enable cloud provider snapshots
pit_enabled = true
retain_backups_enabled = true # keep the backup snapshopts once the cluster is deleted
}
backup_enabled = true # enable cloud provider snapshots
pit_enabled = true
retain_backups_enabled = true # keep the backup snapshopts once the cluster is deleted

replication_specs {
region_configs {
priority = 7
provider_name = "AWS"
region_name = "US_EAST_1"
electable_specs {
instance_size = "M10"
node_count = 3
}
}
}
}

resource "mongodbatlas_cloud_backup_snapshot" "test" {
project_id = mongodbatlas_cluster.cluster_test.project_id
cluster_name = mongodbatlas_cluster.cluster_test.name
project_id = mongodbatlas_advanced_cluster.cluster_test.project_id
cluster_name = mongodbatlas_advanced_cluster.cluster_test.name
description = "My description"
retention_in_days = "1"
}
Expand All @@ -34,8 +42,8 @@ resource "mongodbatlas_cloud_backup_snapshot_restore_job" "test" {

delivery_type_config {
point_in_time = true
target_cluster_name = mongodbatlas_cluster.cluster_test.name
target_project_id = mongodbatlas_cluster.cluster_test.project_id
target_cluster_name = mongodbatlas_advanced_cluster.cluster_test.name
target_project_id = mongodbatlas_advanced_cluster.cluster_test.project_id
point_in_time_utc_seconds = var.point_in_time_utc_seconds
}
}
34 changes: 16 additions & 18 deletions examples/mongodbatlas_database_user/atlas_cluster.tf
Original file line number Diff line number Diff line change
@@ -1,24 +1,22 @@
resource "mongodbatlas_cluster" "cluster" {
project_id = mongodbatlas_project.project1.id
name = "MongoDB_Atlas"
mongo_db_major_version = "7.0"
cluster_type = "REPLICASET"
resource "mongodbatlas_advanced_cluster" "cluster" {
project_id = mongodbatlas_project.project1.id
name = "MongoDB_Atlas"
cluster_type = "REPLICASET"
backup_enabled = true

replication_specs {
num_shards = 1
regions_config {
region_name = var.region
electable_nodes = 3
priority = 7
read_only_nodes = 0
region_configs {
priority = 7
provider_name = "AWS"
region_name = var.region
electable_specs {
instance_size = "M10"
node_count = 3
}
}
}
# Provider Settings "block"
cloud_backup = true
auto_scaling_disk_gb_enabled = true
provider_name = "AWS"
disk_size_gb = 10
provider_instance_size_name = "M10"
}

output "atlasclusterstring" {
value = mongodbatlas_cluster.cluster.connection_strings
value = mongodbatlas_advanced_cluster.cluster.connection_strings
}
2 changes: 1 addition & 1 deletion examples/mongodbatlas_database_user/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ resource "mongodbatlas_database_user" "user1" {
}

scopes {
name = mongodbatlas_cluster.cluster.name
name = mongodbatlas_advanced_cluster.cluster.name
type = "CLUSTER"
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
locals {
mongodb_uri = mongodbatlas_cluster.this.connection_strings[0].standard
mongodb_uri = mongodbatlas_advanced_cluster.this.connection_strings[0].standard
}

data "mongodbatlas_federated_settings" "this" {
Expand All @@ -16,25 +16,22 @@ resource "mongodbatlas_project_ip_access_list" "mongo-access" {
cidr_block = "0.0.0.0/0"
}

resource "mongodbatlas_cluster" "this" {
project_id = mongodbatlas_project.this.id
name = var.project_name
mongo_db_major_version = "7.0"
cluster_type = "REPLICASET"
resource "mongodbatlas_advanced_cluster" "this" {
project_id = mongodbatlas_project.this.id
name = var.project_name
cluster_type = "REPLICASET"

replication_specs {
num_shards = 1
regions_config {
region_name = var.region
electable_nodes = 3
priority = 7
read_only_nodes = 0
region_configs {
priority = 7
provider_name = "AWS"
region_name = var.region
electable_specs {
instance_size = "M10"
node_count = 3
}
}
}
cloud_backup = false
auto_scaling_disk_gb_enabled = false
provider_name = "AWS"
disk_size_gb = 10
provider_instance_size_name = "M10"
}

resource "mongodbatlas_federated_settings_identity_provider" "oidc" {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ output "ssh_connection_string" {
}

output "user_test_conn_string" {
value = "mongodb+srv://${local.test_user_username}:${local.test_user_password}@${replace(mongodbatlas_cluster.this.srv_address, "mongodb+srv://", "")}/?retryWrites=true"
value = "mongodb+srv://${local.test_user_username}:${local.test_user_password}@${replace(mongodbatlas_advanced_cluster.this.connection_strings[0].standard_srv, "mongodb+srv://", "")}/?retryWrites=true"
sensitive = true
description = "Useful for connecting to the database from Compass or other tool to validate data"
}
Expand Down
34 changes: 15 additions & 19 deletions examples/mongodbatlas_network_peering/aws/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,23 @@ resource "mongodbatlas_project" "aws_atlas" {
org_id = var.atlas_org_id
}

resource "mongodbatlas_cluster" "cluster-atlas" {
project_id = mongodbatlas_project.aws_atlas.id
name = "cluster-atlas"
cluster_type = "REPLICASET"
resource "mongodbatlas_advanced_cluster" "cluster-atlas" {
project_id = mongodbatlas_project.aws_atlas.id
name = "cluster-atlas"
cluster_type = "REPLICASET"
backup_enabled = true

replication_specs {
num_shards = 1
regions_config {
region_name = var.atlas_region
electable_nodes = 3
priority = 7
read_only_nodes = 0
region_configs {
priority = 7
provider_name = "AWS"
region_name = var.atlas_region
electable_specs {
instance_size = "M10"
node_count = 3
}
}
}
cloud_backup = true
auto_scaling_disk_gb_enabled = true
mongo_db_major_version = "7.0"

# Provider Settings "block"
provider_name = "AWS"
disk_size_gb = 10
provider_instance_size_name = "M10"
}

resource "mongodbatlas_database_user" "db-user" {
Expand All @@ -46,7 +42,7 @@ resource "mongodbatlas_database_user" "db-user" {
resource "mongodbatlas_network_peering" "aws-atlas" {
accepter_region_name = var.aws_region
project_id = mongodbatlas_project.aws_atlas.id
container_id = mongodbatlas_cluster.cluster-atlas.container_id
container_id = mongodbatlas_advanced_cluster.cluster-atlas.container_id
provider_name = "AWS"
route_table_cidr_block = aws_vpc.primary.cidr_block
vpc_id = aws_vpc.primary.id
Expand Down
Loading
Loading