Skip to content

Commit

Permalink
INTMDB-249: Lint and fix linting for examples (#538)
Browse files Browse the repository at this point in the history
  • Loading branch information
gssbzn committed Sep 29, 2021
1 parent f5bd28f commit aec862a
Show file tree
Hide file tree
Showing 101 changed files with 242 additions and 597 deletions.
25 changes: 23 additions & 2 deletions .github/workflows/examples.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
strategy:
fail-fast: false
matrix:
terraform_version: ["0.12.29"]
terraform_version: ["0.13.0"]
steps:
- uses: actions/checkout@v2
with:
Expand All @@ -35,4 +35,25 @@ jobs:
- name: install tflint
run: go install github.com/terraform-linters/tflint@v0.31.0
- name: terraform
run: make tflint
run: |
for DIR in $(find ./examples -type f -name '*.tf' -exec dirname {} \; | sort -u); do
pushd "${DIR}"
if [ -f terraform.template.tfvars ]; then
cp terraform.template.tfvars terraform.tfvars
fi
echo; echo -e "\e[1;35m===> Initializing Example: $DIR <===\e[0m"; echo
terraform init
echo; echo -e "\e[1;35m===> Format Checking Example: $DIR <===\e[0m"; echo
terraform fmt -check
echo; echo -e "\e[1;35m===> Validating Example: $DIR <===\e[0m"; echo
# Catch errors
terraform validate
# Terraform syntax checks
tflint \
--enable-rule=terraform_deprecated_interpolation \
--enable-rule=terraform_deprecated_index \
--enable-rule=terraform_unused_declarations \
--enable-rule=terraform_comment_syntax \
--enable-rule=terraform_required_version
popd
done
2 changes: 1 addition & 1 deletion examples/Atlas_Database_Users/atlas_cluster.tf
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ resource "mongodbatlas_cluster" "cluster" {
read_only_nodes = 0
}
}
//Provider Settings "block"
# Provider Settings "block"
provider_backup_enabled = true
auto_scaling_disk_gb_enabled = true
provider_name = "AWS"
Expand Down
4 changes: 2 additions & 2 deletions examples/Atlas_Database_Users/database_user.tf
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//DATABASE USER
# DATABASE USER
resource "mongodbatlas_database_user" "user1" {
username = var.user[0]
password = var.password[0]
Expand All @@ -22,7 +22,7 @@ resource "mongodbatlas_database_user" "user1" {
output "user1" {
value = mongodbatlas_database_user.user1.username
}
//DATA LAKE USER
# DATA LAKE USER
resource "mongodbatlas_database_user" "user2" {
username = var.user[1]
password = var.password[1]
Expand Down
10 changes: 0 additions & 10 deletions examples/MongoDB Atlas-GCP VPC Peering/provider.tf

This file was deleted.

5 changes: 3 additions & 2 deletions examples/MongoDB-Atlas-AWS-VPC-Peering/atlas.tf
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ resource "mongodbatlas_cluster" "cluster-atlas" {
auto_scaling_disk_gb_enabled = true
mongo_db_major_version = "5.0"

//Provider Settings "block"
# Provider Settings "block"
provider_name = "AWS"
disk_size_gb = 10
provider_instance_size_name = "M10"
Expand All @@ -49,6 +49,7 @@ resource "mongodbatlas_network_container" "atlas_container" {
region_name = var.atlas_region
}

# tflint-ignore: terraform_unused_declarations
data "mongodbatlas_network_container" "atlas_container" {
container_id = mongodbatlas_network_container.atlas_container.container_id
project_id = mongodbatlas_project.aws_atlas.id
Expand All @@ -68,4 +69,4 @@ resource "mongodbatlas_project_ip_access_list" "test" {
project_id = mongodbatlas_project.aws_atlas.id
cidr_block = aws_vpc.primary.cidr_block
comment = "cidr block for AWS VPC"
}
}
10 changes: 5 additions & 5 deletions examples/MongoDB-Atlas-AWS-VPC-Peering/aws-vpc.tf
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,19 @@ provider "aws" {
secret_key = var.secret_key
}

//Create Primary VPC
# Create Primary VPC
resource "aws_vpc" "primary" {
cidr_block = "10.0.0.0/16"
enable_dns_hostnames = true
enable_dns_support = true
}

//Create IGW
# Create IGW
resource "aws_internet_gateway" "primary" {
vpc_id = aws_vpc.primary.id
}

//Route Table
# Route Table
resource "aws_route" "primary-internet_access" {
route_table_id = aws_vpc.primary.main_route_table_id
destination_cidr_block = "0.0.0.0/0"
Expand All @@ -30,15 +30,15 @@ resource "aws_route" "peeraccess" {
depends_on = [aws_vpc_peering_connection_accepter.peer]
}

//Subnet-A
# Subnet-A
resource "aws_subnet" "primary-az1" {
vpc_id = aws_vpc.primary.id
cidr_block = "10.0.1.0/24"
map_public_ip_on_launch = true
availability_zone = "${var.aws_region}a"
}

//Subnet-B
# Subnet-B
resource "aws_subnet" "primary-az2" {
vpc_id = aws_vpc.primary.id
cidr_block = "10.0.2.0/24"
Expand Down
2 changes: 1 addition & 1 deletion examples/MongoDB-Atlas-AWS-VPC-Peering/versions.tf
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ terraform {
source = "hashicorp/aws"
}
}
required_version = ">= 0.15"
required_version = ">= 0.13"
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@ data "google_compute_network" "default" {

# Create the GCP peer
resource "google_compute_network_peering" "peering" {
name = "peering-gcp-terraform-test"
//The URI of the GCP VPC. self_link which is found by enabling the [Compute Engine API](https://console.cloud.google.com/apis/api/compute.googleapis.com)
network = data.google_compute_network.default.self_link
//The URI of the Atlas VPC
name = "peering-gcp-terraform-test"
# The URI of the GCP VPC. self_link which is found by enabling the [Compute Engine API](https://console.cloud.google.com/apis/api/compute.googleapis.com)
network = data.google_compute_network.default.self_link
# The URI of the Atlas VPC
peer_network = "https://www.googleapis.com/compute/v1/projects/${mongodbatlas_network_peering.test.atlas_gcp_project_id}/global/networks/${mongodbatlas_network_peering.test.atlas_vpc_name}"
}

#Create IP Access List for connection from GCP
//You will need to add the private IP ranges of the subnets in which your application is hosted to the IP access list in order to connect to your Atlas cluster. GCP networks generated in auto-mode use a CIDR range of 10.128.0.0/9
# Create IP Access List for connection from GCP
# You will need to add the private IP ranges of the subnets in which your application is hosted to the IP access list in order to connect to your Atlas cluster. GCP networks generated in auto-mode use a CIDR range of 10.128.0.0/9
resource "mongodbatlas_project_ip_access_list" "test" {
project_id = var.project_id
cidr_block = var.gcp_cidr
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//This cluster is in GCP cloud-provider with VPC peering enabled
# This cluster is in GCP cloud-provider with VPC peering enabled

resource "mongodbatlas_cluster" "cluster" {
project_id = var.project_id
Expand All @@ -24,7 +24,7 @@ resource "mongodbatlas_cluster" "cluster" {
auto_scaling_compute_scale_down_enabled = true


//Provider Settings "block"
# Provider Settings "block"
provider_name = "GCP"
provider_instance_size_name = "M10"
provider_auto_scaling_compute_max_instance_size = "M20"
Expand All @@ -39,7 +39,7 @@ resource "mongodbatlas_cluster" "cluster" {
]
}
}
//The connection strings available for the GCP MognoDB Atlas cluster
# The connection strings available for the GCP MognoDB Atlas cluster
output "connection_string" {
value = mongodbatlas_cluster.cluster.connection_strings
}
10 changes: 10 additions & 0 deletions examples/MongoDB-Atlas-GCP-VPC-Peering/provider.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
provider "mongodbatlas" {
public_key = var.public_key
private_key = var.private_key
}
provider "google" {
# credentials = file("service-account.json")
project = var.gcpprojectid
region = var.gcp_region
# zone="us-central-1c"
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@ variable "public_key" {
variable "private_key" {
description = "Private API key to authenticate to Atlas"
}
variable "mongodbversion" {
description = "The Major MongoDB Version"
default = "4.2"
}
variable "project_id" {
description = "The Atlas Project Name"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ terraform {
source = "hashicorp/google"
}
}
required_version = ">= 0.15"
required_version = ">= 0.13"
}
4 changes: 2 additions & 2 deletions examples/atlas-cloud-provider-access/aws/aws-roles.tf
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ resource "aws_iam_role" "test_role" {
{
"Effect": "Allow",
"Principal": {
"AWS": "${mongodbatlas_cloud_provider_access_setup.setup_only.aws.0.atlas_aws_account_arn}"
"AWS": "${mongodbatlas_cloud_provider_access_setup.setup_only.aws_config[0].atlas_aws_account_arn}"
},
"Action": "sts:AssumeRole",
"Condition": {
"StringEquals": {
"sts:ExternalId": "${mongodbatlas_cloud_provider_access_setup.setup_only.aws.0.atlas_assumed_role_external_id}"
"sts:ExternalId": "${mongodbatlas_cloud_provider_access_setup.setup_only.aws_config[0].atlas_assumed_role_external_id}"
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions examples/atlas-cloud-provider-access/aws/variables.tf
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// mongo
# mongo
variable "project_id" {
type = string
}
Expand All @@ -13,7 +13,7 @@ variable "private_key" {
type = string
}

// aws
# aws
variable "access_key" {
type = string
}
Expand All @@ -22,4 +22,4 @@ variable "secret_key" {
}
variable "aws_region" {
type = string
}
}
6 changes: 3 additions & 3 deletions examples/atlas-dataLake-roles/aws-roles.tf
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,17 @@ resource "aws_iam_role" "test_role" {
{
"Effect": "Allow",
"Principal": {
"AWS": "${mongodbatlas_cloud_provider_access_setup.setup_only.aws.0.atlas_aws_account_arn}"
"AWS": "${mongodbatlas_cloud_provider_access_setup.setup_only.aws_config[0].atlas_aws_account_arn}"
},
"Action": "sts:AssumeRole",
"Condition": {
"StringEquals": {
"sts:ExternalId": "${mongodbatlas_cloud_provider_access_setup.setup_only.aws.0.atlas_assumed_role_external_id}"
"sts:ExternalId": "${mongodbatlas_cloud_provider_access_setup.setup_only.aws_config[0].atlas_assumed_role_external_id}"
}
}
}
]
}
EOF

}
}
4 changes: 2 additions & 2 deletions examples/atlas-dataLake-roles/import/aws-roles.tf
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ resource "aws_iam_role" "test_role" {
{
"Effect": "Allow",
"Principal": {
"AWS": "${mongodbatlas_cloud_provider_access_setup.setup_only.aws.0.atlas_aws_account_arn}"
"AWS": "${mongodbatlas_cloud_provider_access_setup.setup_only.aws_config[0].atlas_aws_account_arn}"
},
"Action": "sts:AssumeRole",
"Condition": {
"StringEquals": {
"sts:ExternalId": "${mongodbatlas_cloud_provider_access_setup.setup_only.aws.0.atlas_assumed_role_external_id}"
"sts:ExternalId": "${mongodbatlas_cloud_provider_access_setup.setup_only.aws_config[0].atlas_assumed_role_external_id}"
}
}
}
Expand Down
12 changes: 5 additions & 7 deletions examples/atlas-dataLake-roles/import/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,10 @@ resource "mongodbatlas_cloud_provider_access_authorization" "auth_role" {
}

resource "mongodbatlas_data_lake" "test" {
project_id = mongodbatlas_project.test.id
name = var.data_lake_name
aws_role_id = mongodbatlas_cloud_provider_access_authorization.auth_role.role_id
aws_test_s3_bucket = var.test_s3_bucket
data_process_region = {
cloud_provider = "AWS"
region = var.data_lake_region
project_id = mongodbatlas_project.test.id
name = var.data_lake_name
aws {
role_id = mongodbatlas_cloud_provider_access_authorization.auth_role.role_id
test_s3_bucket = var.test_s3_bucket
}
}
16 changes: 0 additions & 16 deletions examples/atlas-dataLake-roles/import/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -26,22 +26,10 @@ variable "secret_key" {
description = "The secret key for AWS Account"
default = ""
}
variable "customer_master_key" {
description = "The customer master secret key for AWS Account"
default = ""
}
variable "atlas_region" {
default = "US_EAST_1"
description = "Atlas Region"
}
variable "aws_region" {
default = "us-east-1"
description = "AWS Region"
}
variable "aws_iam_role_arn" {
description = "AWS IAM ROLE ARN"
default = ""
}
variable "test_s3_bucket" {
description = "The name of s3 bucket"
default = ""
Expand All @@ -50,7 +38,3 @@ variable "data_lake_name" {
description = "The data lake name"
default = ""
}
variable "data_lake_region" {
default = "VIRGINIA_USA"
description = "The data lake region"
}
5 changes: 2 additions & 3 deletions examples/atlas-dataLake-roles/import/versions.tf
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@ terraform {
source = "hashicorp/aws"
}
mongodbatlas = {
source = "mongodb/mongodbatlas"
version = "0.1.0-dev"
source = "mongodb/mongodbatlas"
}
}
required_version = ">= 0.15"
required_version = ">= 0.13"
}
32 changes: 5 additions & 27 deletions examples/atlas-dataLake-roles/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -19,32 +19,10 @@ resource "mongodbatlas_cloud_provider_access_authorization" "auth_role" {
}

resource "mongodbatlas_data_lake" "test" {
project_id = mongodbatlas_project.test.id
name = var.data_lake_name
aws_role_id = mongodbatlas_cloud_provider_access_authorization.auth_role.role_id
aws_test_s3_bucket = var.test_s3_bucket
data_process_region = {
cloud_provider = "AWS"
region = var.data_lake_region
project_id = mongodbatlas_project.test.id
name = var.data_lake_name
aws {
role_id = mongodbatlas_cloud_provider_access_authorization.auth_role.role_id
test_s3_bucket = var.test_s3_bucket
}
}


output "project_id" {
value = mongodbatlas_project.test.id
}
output "role_id" {
value = mongodbatlas_cloud_provider_access_setup.setup_only.role_id
}
output "role_name" {
value = aws_iam_role.test_role.name
}
output "policy_name" {
value = aws_iam_role_policy.test_policy.name
}
output "data_lake_name" {
value = mongodbatlas_data_lake.test.name
}
output "s3_bucket" {
value = mongodbatlas_data_lake.test.aws_test_s3_bucket
}

0 comments on commit aec862a

Please sign in to comment.