Skip to content

INTMDB-802: Create new TF Data Federation Query Limit resource and data sources #1173

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

Merged
merged 56 commits into from
Jun 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
0edb8e3
INTMDB-802: Add data_source and resource for Federated Database Query…
maastha May 15, 2023
085be14
INTMDB-802: update provider.go
maastha May 15, 2023
5accd9d
INTMDB-802: Add AtlasDataFederation Query Limit resource
maastha May 17, 2023
8deb8a5
INTMDB-802: Add AtlasDataFederation Query Limit resource
maastha May 17, 2023
5529a94
Update data_source_mongodbatlas_federated_query_limit.go
maastha May 17, 2023
3fe2ae0
Update resource_mongodbatlas_federated_query_limit.go
maastha May 17, 2023
b28e6f5
INTMDB-802: temp
maastha May 18, 2023
da92b05
Merge branch 'release-staging-v.1.10.0' into INTMDB-802
maastha May 22, 2023
5704fbb
INTMDB-802: Add example
maastha May 22, 2023
13e4998
INTMDB-802: Add example
maastha May 23, 2023
8a026a3
INTMDB-802: minor
maastha May 23, 2023
c04684a
INTMDB-802: example fix
maastha May 24, 2023
8dcee52
Acceptance tests
maastha May 25, 2023
d8eefab
Merge branch 'release-staging-v.1.10.0' into INTMDB-802
maastha May 25, 2023
76143b3
Acceptance tests
maastha May 25, 2023
17a61c2
Fix docs
maastha May 25, 2023
1cd8d7c
Update main.tf
maastha May 25, 2023
a0b1714
Update mongodbatlas/resource_mongodbatlas_federated_query_limit.go
maastha May 30, 2023
21dfe22
Update mongodbatlas/resource_mongodbatlas_federated_query_limit.go
maastha May 30, 2023
9ebe9c7
Update mongodbatlas/data_source_mongodbatlas_federated_query_limit.go
maastha May 30, 2023
ce381a8
Update mongodbatlas/resource_mongodbatlas_federated_query_limit.go
maastha May 30, 2023
a7b37ed
Update mongodbatlas/resource_mongodbatlas_federated_query_limit.go
maastha May 30, 2023
e3c2e99
Update website/docs/d/federated_query_limit.html.markdown
maastha May 31, 2023
4097e13
Update website/docs/d/federated_query_limit.html.markdown
maastha May 31, 2023
64b384a
Update website/docs/r/federated_query_limit.html.markdown
maastha May 31, 2023
331b45b
Update website/docs/r/federated_query_limit.html.markdown
maastha May 31, 2023
72fa943
Update website/docs/r/federated_query_limit.html.markdown
maastha May 31, 2023
f484e48
Update website/docs/d/federated_query_limits.html.markdown
maastha May 31, 2023
5820727
Update website/docs/r/federated_query_limit.html.markdown
maastha May 31, 2023
c0e2d22
Update federated_query_limit.html.markdown
maastha May 31, 2023
d297d52
Update federated_query_limit.html.markdown
maastha May 31, 2023
ce72ab8
Merge branch 'release-staging-v.1.10.0' into INTMDB-802
maastha May 31, 2023
557407a
Address PR comments
maastha May 31, 2023
d8fe9af
Address PR comments
maastha May 31, 2023
b0f8046
Update website/docs/d/federated_query_limit.html.markdown
maastha May 31, 2023
b374945
Update website/docs/d/federated_query_limits.html.markdown
maastha May 31, 2023
143482c
Update examples/federated-database-query-limit/README.md
maastha May 31, 2023
ec4e7d3
Update examples/federated-database-query-limit/README.md
maastha May 31, 2023
a1ba64a
Update examples/federated-database-query-limit/README.md
maastha May 31, 2023
14b6fd4
Update federated_query_limit.html.markdown
maastha May 31, 2023
4075765
Update federated_query_limits.html.markdown
maastha May 31, 2023
411ddcf
Update README.md
maastha May 31, 2023
43a63cb
Address PR comments
maastha May 31, 2023
69ecb6f
Address PR comments
maastha May 31, 2023
6c690dc
Apply suggestions from code review
maastha Jun 2, 2023
e68dff1
INTMDB-805: [Terraform] Create new TF Data Lake Pipelines Run data so…
andreaangiolillo Jun 1, 2023
473d316
INTMDB-803: [Terraform] Create a new Private Endpoint resource and da…
andreaangiolillo Jun 2, 2023
fae6f14
Merge branch 'release-staging-v.1.10.0' into INTMDB-802
maastha Jun 2, 2023
4ebb85e
Fix AWS provider version and example
maastha Jun 2, 2023
7030c34
fix merge
andreaangiolillo Jun 5, 2023
f8d01b1
Merge branch 'INTMDB-802' of github.com:mongodb/terraform-provider-mo…
andreaangiolillo Jun 5, 2023
665f9a1
Merge remote-tracking branch 'origin/release-staging-v.1.10.0' into I…
andreaangiolillo Jun 7, 2023
e21aecc
updated federated instance
andreaangiolillo Jun 7, 2023
daf8930
Addressed Comments
andreaangiolillo Jun 8, 2023
0b8794f
Update mongodbatlas/data_source_mongodbatlas_federated_query_limits.go
Zuhairahmed Jun 9, 2023
172faa5
Update data_source_mongodbatlas_federated_query_limits.go
andreaangiolillo Jun 9, 2023
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
48 changes: 48 additions & 0 deletions examples/federated-database-query-limit/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# Example - MongoDB Atlas Federated Database Query Limit with Atlas clusters

This project aims to provide an example of using [MongoDB Atlas Federated Database Query Limit](https://www.mongodb.com/docs/atlas/data-federation/overview/).


## Dependencies

* Terraform MongoDB Atlas Provider v1.10.0
* A MongoDB Atlas account

```
Terraform v1.4.6
+ provider registry.terraform.io/terraform-providers/mongodbatlas v1.10.0
```

## Usage
**1\. Create a .tfvars file**

This example requires an Atlas Project to already exist. Once a project is created create the terraform.tfvars file and enter the values for all the required variables, including the project, and make sure **not to commit it**.

**2\. Review the Terraform plan**

Execute the below command and ensure you are happy with the plan. The `terraform plan` command lets you to preview the actions Terraform would take to modify your infrastructure, or save a speculative plan which you can apply later.

``` bash
$ terraform plan
```
This project currently supports the below deployments:

- Two MongoDB Atlas clusters in the specified project
- MongoDB Atlas Federated Database Instance based on Atlas clusters
- MongoDB Atlas Federated Database Query Limit

**3\. Execute the Terraform apply.**

Now execute the plan to provision the Federated settings resources. The `terraform apply` command performs a plan just like `terraform plan` does, but then actually carries out the planned changes to each resource using the relevant infrastructure provider's API. It asks for confirmation from the user before making any changes, unless it was explicitly told to skip approval.

``` bash
$ terraform apply
```

**4\. Destroy the resources.**

Once you are finished your testing, ensure you destroy the resources to avoid unnecessary Atlas charges. Calling the `terraform destroy` command will instruct Terraform to terminate / destroy all the resources managed. This will enable you to completely tear down and remove all resources defined in the Terraform State that have previously been deployed.

``` bash
$ terraform destroy
```
84 changes: 84 additions & 0 deletions examples/federated-database-query-limit/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
resource "mongodbatlas_advanced_cluster" "atlas_cluster_1" {
project_id = var.project_id
name = var.atlas_cluster_name_1
cluster_type = "REPLICASET"

replication_specs {
region_configs {
electable_specs {
instance_size = var.provider_instance_size_name
}
provider_name = var.provider_name
backing_provider_name = var.backing_provider_name
region_name = var.provider_region_name
priority = 7
}
}
}

resource "mongodbatlas_advanced_cluster" "atlas_cluster_2" {
project_id = var.project_id
name = var.atlas_cluster_name_2
cluster_type = "REPLICASET"

replication_specs {
region_configs {
electable_specs {
instance_size = var.provider_instance_size_name
}
provider_name = var.provider_name
backing_provider_name = var.backing_provider_name
region_name = var.provider_region_name
priority = 7
}
}
}

resource "mongodbatlas_federated_database_instance" "test-instance" {
project_id = var.project_id
name = var.federated_instance_name
storage_databases {
name = "VirtualDatabase0"
collections {
name = "VirtualCollection0"
data_sources {
collection = var.collection_1
database = var.database_1
store_name = mongodbatlas_advanced_cluster.atlas_cluster_1.name
}
data_sources {
collection = var.collection_2
database = var.database_2
store_name = mongodbatlas_advanced_cluster.atlas_cluster_2.name
}
}
}

storage_stores {
name = mongodbatlas_advanced_cluster.atlas_cluster_1.name
cluster_name = mongodbatlas_advanced_cluster.atlas_cluster_1.name
project_id = var.project_id
provider = "atlas"
read_preference {
mode = "secondary"
}
}

storage_stores {
name = mongodbatlas_advanced_cluster.atlas_cluster_2.name
cluster_name = mongodbatlas_advanced_cluster.atlas_cluster_2.name
project_id = var.project_id
provider = "atlas"
read_preference {
mode = "secondary"
}
}
}

resource "mongodbatlas_federated_query_limit" "query_limit" {
project_id = var.project_id
tenant_name = mongodbatlas_federated_database_instance.test-instance.name
limit_name = var.federated_query_limit
overrun_policy = var.overrun_policy
value = var.limit_value
}
7 changes: 7 additions & 0 deletions examples/federated-database-query-limit/output.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
output "mongodbatlas_federated_query_limit_name" {
value = mongodbatlas_federated_query_limit.query_limit.limit_name
}

output "mongodbatlas_federated_query_limit_default_limit" {
value = mongodbatlas_federated_query_limit.query_limit.default_limit
}
4 changes: 4 additions & 0 deletions examples/federated-database-query-limit/provider.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
provider "mongodbatlas" {
public_key = var.public_key
private_key = var.private_key
}
90 changes: 90 additions & 0 deletions examples/federated-database-query-limit/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
variable "public_key" {
type = string
description = "Public Programmatic API key to authenticate to Atlas"
}
variable "private_key" {
type = string
description = "Private Programmatic API key to authenticate to Atlas"
}
variable "project_id" {
type = string
description = "MongoDB Project ID"
}

variable "collection_1" {
type = string
description = "Human-readable label that identifies the collection in the database in first cluster"
}

variable "database_1" {
type = string
description = "Human-readable label that identifies the database, which contains the collection in the first cluster"
}

variable "collection_2" {
type = string
description = "Human-readable label that identifies the collection in the database in second cluster"
}

variable "database_2" {
type = string
description = "Human-readable label that identifies the database, which contains the collection in the second cluster"
}

variable "federated_instance_name" {
type = string
description = "MongoDB Federated Database Instance Name."
default = "FederatedDatabaseInstance0"
}

variable "atlas_cluster_name_1" {
type = string
description = "First Atlas Cluster Name."
default = "ClusterFederatedTest1"
}

variable "atlas_cluster_name_2" {
type = string
description = "Second Atlas Cluster Name."
default = "ClusterFederatedTest2"
}

variable "provider_region_name" {
type = string
description = "Physical location where MongoDB Cloud deploys your AWS-hosted MongoDB cluster nodes."
default = "US_EAST_1"
}

variable "provider_instance_size_name" {
type = string
description = "Cluster tier. Default is M10"
default = "M10"
}

variable "backing_provider_name" {
type = string
default = "AWS"
}

variable "provider_name" {
type = string
default = "AWS"
}

variable "federated_query_limit" {
type = string
description = "Human-readable label that identifies the user-managed limit to modify."
default = "bytesProcessed.monthly"
}

variable "overrun_policy" {
type = string
description = "Action to take when the usage limit is exceeded."
default = "BLOCK"
}

variable "limit_value" {
type = number
description = "Amount to set the federated query limit to."
default = 5147483648
}
8 changes: 8 additions & 0 deletions examples/federated-database-query-limit/versions.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
terraform {
required_providers {
mongodbatlas = {
source = "mongodb/mongodbatlas"
}
}
required_version = ">= 0.13"
}
83 changes: 83 additions & 0 deletions mongodbatlas/data_source_mongodbatlas_federated_query_limit.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
package mongodbatlas

import (
"context"
"fmt"

"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)

func dataSourceMongoDBAtlasFederatedDatabaseQueryLimit() *schema.Resource {
return &schema.Resource{
ReadContext: dataSourceMongoDBAtlasFederatedDatabaseQueryLimitRead,
Schema: schemaMongoDBAtlasFederatedDatabaseQueryLimitDataSource(),
}
}

func schemaMongoDBAtlasFederatedDatabaseQueryLimitDataSource() map[string]*schema.Schema {
return map[string]*schema.Schema{
"project_id": {
Type: schema.TypeString,
Required: true,
},
"limit_name": {
Type: schema.TypeString,
Required: true,
},
"tenant_name": {
Type: schema.TypeString,
Required: true,
},
"overrun_policy": {
Type: schema.TypeString,
Computed: true,
},
"value": {
Type: schema.TypeInt,
Computed: true,
},
"current_usage": {
Type: schema.TypeInt,
Computed: true,
},
"default_limit": {
Type: schema.TypeInt,
Computed: true,
},
"last_modified_date": {
Type: schema.TypeString,
Computed: true,
},
"maximum_limit": {
Type: schema.TypeInt,
Computed: true,
},
}
}

func dataSourceMongoDBAtlasFederatedDatabaseQueryLimitRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
conn := meta.(*MongoDBClient).Atlas

projectID := d.Get("project_id").(string)
tenantName := d.Get("tenant_name").(string)
limitName := d.Get("limit_name").(string)

queryLimit, _, err := conn.DataFederation.GetQueryLimit(ctx, projectID, tenantName, limitName)

if err != nil {
return diag.FromErr(fmt.Errorf("couldn't import federated database query limit(%s) for project (%s), tenant (%s), error: %s", limitName, projectID, tenantName, err))
}

if err = setResourceFieldsFromFederatedDatabaseQueryLimit(d, projectID, queryLimit); err != nil {
return diag.FromErr(err)
}

d.SetId(encodeStateID(map[string]string{
"project_id": projectID,
"tenant_name": queryLimit.TenantName,
"limit_name": queryLimit.Name,
}))

return nil
}
Loading