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 25 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
8 changes: 4 additions & 4 deletions docs/data-sources/advanced_clusters.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Data Source: mongodbatlas_clusters

`mongodbatlas_cluster` describes all Advanced Clusters by the provided project_id. The data source requires your Project ID.
`mongodbatlas_advanced_cluster` describes all Advanced Clusters by the provided project_id. The data source requires your Project ID.
Copy link
Member Author

Choose a reason for hiding this comment

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

header for adv_cluster plural ds was wrong


-> **NOTE:** Groups and projects are synonymous terms. You may find group_id in the official documentation.

Expand All @@ -11,7 +11,7 @@
## Example Usage

```terraform
resource "mongodbatlas_cluster" "example" {
resource "mongodbatlas_advanced_cluster" "example" {
project_id = "<YOUR-PROJECT-ID>"
name = "cluster-test"
cluster_type = "REPLICASET"
Expand All @@ -29,8 +29,8 @@ resource "mongodbatlas_cluster" "example" {
}
}

data "mongodbatlas_clusters" "example" {
project_id = mongodbatlas_cluster.example.project_id
data "mongodbatlas_advanced_clusters" "example" {
project_id = mongodbatlas_advanced_cluster.example.project_id
}
```

Expand Down
30 changes: 19 additions & 11 deletions docs/data-sources/backup_compliance_policy.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,28 @@
## Example Usage

```terraform
resource "mongodbatlas_cluster" "my_cluster" {
project_id = "<PROJECT-ID>"
name = "clusterTest"

//Provider Settings "block"
provider_name = "AWS"
provider_region_name = "EU_CENTRAL_1"
provider_instance_size_name = "M10"
cloud_backup = true // enable cloud backup snapshots
resource "mongodbatlas_advanced_cluster" "my_cluster" {
project_id = "<PROJECT-ID>"
name = "clusterTest"
cluster_type = "REPLICASET"
backup_enabled = true # enable cloud backup snapshots

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

resource "mongodbatlas_cloud_backup_schedule" "test" {
project_id = mongodbatlas_cluster.my_cluster.project_id
cluster_name = mongodbatlas_cluster.my_cluster.name
project_id = mongodbatlas_advanced_cluster.my_cluster.project_id
cluster_name = mongodbatlas_advanced_cluster.my_cluster.name

reference_hour_of_day = 3
reference_minute_of_hour = 45
Expand Down
8 changes: 4 additions & 4 deletions docs/resources/advanced_cluster.md
Original file line number Diff line number Diff line change
Expand Up @@ -303,29 +303,29 @@ resource "mongodbatlas_advanced_cluster" "cluster" {
Standard
```terraform
output "standard" {
value = mongodbatlas_cluster.cluster-test.connection_strings[0].standard
value = mongodbatlas_advanced_cluster.cluster.connection_strings[0].standard
lantoli marked this conversation as resolved.
Show resolved Hide resolved
}
# Example return string: standard = "mongodb://cluster-atlas-shard-00-00.ygo1m.mongodb.net:27017,cluster-atlas-shard-00-01.ygo1m.mongodb.net:27017,cluster-atlas-shard-00-02.ygo1m.mongodb.net:27017/?ssl=true&authSource=admin&replicaSet=atlas-12diht-shard-0"
```
Standard srv
```terraform
output "standard_srv" {
value = mongodbatlas_cluster.cluster-test.connection_strings[0].standard_srv
value = mongodbatlas_advanced_cluster.cluster.connection_strings[0].standard_srv
}
# Example return string: standard_srv = "mongodb+srv://cluster-atlas.ygo1m.mongodb.net"
```
Private with Network peering and Custom DNS AWS enabled
```terraform
output "private" {
value = mongodbatlas_cluster.cluster-test.connection_strings[0].private
value = mongodbatlas_advanced_cluster.cluster.connection_strings[0].private
}
# Example return string: private = "mongodb://cluster-atlas-shard-00-00-pri.ygo1m.mongodb.net:27017,cluster-atlas-shard-00-01-pri.ygo1m.mongodb.net:27017,cluster-atlas-shard-00-02-pri.ygo1m.mongodb.net:27017/?ssl=true&authSource=admin&replicaSet=atlas-12diht-shard-0"
private = "mongodb+srv://cluster-atlas-pri.ygo1m.mongodb.net"
```
Private srv with Network peering and Custom DNS AWS enabled
```terraform
output "private_srv" {
value = mongodbatlas_cluster.cluster-test.connection_strings[0].private_srv
value = mongodbatlas_advanced_cluster.cluster.connection_strings[0].private_srv
}
# Example return string: private_srv = "mongodb+srv://cluster-atlas-pri.ygo1m.mongodb.net"
```
Expand Down
4 changes: 2 additions & 2 deletions docs/resources/backup_compliance_policy.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ We first suggest disabling `mongodbatlas_backup_compliance_policy` resource, whi
* For example, replace:
```
resource "mongodbatlas_cloud_backup_schedule" "test" {
project_id = mongodbatlas_cluster.my_cluster.project_id
cluster_name = mongodbatlas_cluster.my_cluster.name
project_id = mongodbatlas_advanced_cluster.my_cluster.project_id
cluster_name = mongodbatlas_advanced_cluster.my_cluster.name
...
}
```
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
}
Loading