-
Notifications
You must be signed in to change notification settings - Fork 203
INTMDB-803: [Terraform] Create a new Private Endpoint resource and data sources which supports Federated Database Instance and Online Archive #1182
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
Changes from all commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
94c179b
fix: microsoft_teams_webhook_url keeps updating on every apply (#1148)
maastha 6a1b0c1
INTMDB-783: Point in Time Restore is not enabled when should_copy_opl…
andreaangiolillo 8078fe5
Merge remote-tracking branch 'origin/release-staging-v.1.10.0' into r…
andreaangiolillo 9609c1f
Merge remote-tracking branch 'origin/release-staging-v.1.10.0' into r…
andreaangiolillo 32d36a3
Merge remote-tracking branch 'origin/release-staging-v.1.10.0' into r…
andreaangiolillo 8786618
Merge remote-tracking branch 'origin/release-staging-v.1.10.0' into r…
andreaangiolillo 7b99a88
INTMDB-803: [Terraform] Create a new Private Endpoint resource and da…
andreaangiolillo cf317de
Updated test
andreaangiolillo f991076
Add data sources
andreaangiolillo 6462334
renamed resources and data sourceds
andreaangiolillo d931f2d
Added documentation
andreaangiolillo 2f2d1be
Update data_source_mongodbatlas_privatelink_endpoint_service_data_fed…
andreaangiolillo 0541c94
Added import
andreaangiolillo 768d13a
Update data_source_mongodbatlas_privatelink_endpoint_service_data_fed…
andreaangiolillo 0797fc8
added example after testing it
andreaangiolillo a011245
Addressed Melissa's comments
andreaangiolillo 2680fb1
Merge remote-tracking branch 'origin/release-staging-v.1.10.0' into I…
andreaangiolillo ad38db1
Update provider.go
andreaangiolillo 01341fd
Addressed comments
andreaangiolillo 49e8468
Update privatelink_endpoint_service_data_federation_online_archive.ma…
andreaangiolillo 4b92266
Merge remote-tracking branch 'origin/release-staging-v.1.10.0' into I…
andreaangiolillo 588fb61
merged release branch
andreaangiolillo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
85 changes: 85 additions & 0 deletions
85
examples/aws-privatelink-endpoint/data-federation-online-archive/README.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
# Example - Privatelink for Data Federation and Online Archive | ||
|
||
Setup private connection to a [Data Federation or Online Archive](https://www.mongodb.com/docs/atlas/data-federation/tutorial/config-private-endpoint/) utilizing [Amazon Virtual Private Cloud (aws vpc)](https://docs.aws.amazon.com/vpc/latest/userguide/what-is-amazon-vpc.html). | ||
|
||
|
||
## Dependencies | ||
|
||
* Terraform v0.13 | ||
* An AWS account - provider.aws: version = "~> 4" | ||
* A MongoDB Atlas account - provider.mongodbatlas: version = "~> 1.10" | ||
|
||
## Usage | ||
|
||
**1\. Ensure your AWS and MongoDB Atlas credentials are set up.** | ||
|
||
This can be done using environment variables: | ||
|
||
```bash | ||
export MONGODB_ATLAS_PUBLIC_KEY="xxxx" | ||
export MONGODB_ATLAS_PRIVATE_KEY="xxxx" | ||
``` | ||
|
||
``` bash | ||
$ export AWS_SECRET_ACCESS_KEY='your secret key' | ||
$ export AWS_ACCESS_KEY_ID='your key id' | ||
``` | ||
|
||
... or the `~/.aws/credentials` file. | ||
|
||
``` | ||
$ cat ~/.aws/credentials | ||
[default] | ||
aws_access_key_id = your key id | ||
aws_secret_access_key = your secret key | ||
|
||
``` | ||
... or follow as in the `variables.tf` file and create **terraform.tfvars** file with all the variable values, ex: | ||
``` | ||
access_key = "<AWS_ACCESS_KEY_ID>" | ||
secret_key = "<AWS_SECRET_ACCESS_KEY>" | ||
public_key = "<MONGODB_ATLAS_PUBLIC_KEY>" | ||
private_key = "<MONGODB_ATLAS_PRIVATE_KEY>" | ||
project_id = "<MONGODB_ATLAS_PROJECT_ID>" | ||
``` | ||
|
||
**2\. Review the Terraform plan.** | ||
|
||
Execute the below command and ensure you are happy with the plan. | ||
|
||
``` bash | ||
$ terraform plan | ||
``` | ||
This project currently performs the below deployments: | ||
|
||
- MongoDB Atlas Dedicated Cluster - M10 | ||
- AWS Custom VPC, Internet Gateway, Route Tables, Subnets with Public and Private access | ||
- PrivateLink Connection at MongoDB Atlas | ||
- Create VPC Endpoint in AWS | ||
|
||
**3\. Configure the security group as required.** | ||
|
||
The security group in this configuration allows All Traffic access in Inbound and Outbound Rules. | ||
|
||
**4\. Execute the Terraform apply.** | ||
|
||
Now execute the plan to provision the AWS and Atlas resources. | ||
|
||
``` bash | ||
$ terraform apply | ||
``` | ||
|
||
**5\. Destroy the resources.** | ||
|
||
Once you are finished your testing, ensure you destroy the resources to avoid unnecessary charges. | ||
|
||
``` bash | ||
$ terraform destroy | ||
``` | ||
|
||
**What's the resource dependency chain?** | ||
1. `mongodbatlas_project` must exist for any of the following | ||
2. `aws_vpc_endpoint` is dependent on the `mongodbatlas_privatelink_endpoint`, and its dependencies. | ||
3. `mongodbatlas_privatelink_endpoint_service` is dependent on `aws_vpc_endpoint` and its dependencies. | ||
4. `mongodbatlas_privatelink_endpoint_service_data_federation_online_archive` is dependent on the `mongodbatlas_project` and `aws_vpc_endpoint` | ||
|
12 changes: 12 additions & 0 deletions
12
examples/aws-privatelink-endpoint/data-federation-online-archive/atlas-privatelink.tf
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
resource "mongodbatlas_privatelink_endpoint" "pe_east" { | ||
project_id = var.project_id | ||
provider_name = "AWS" | ||
region = "us-east-1" | ||
} | ||
|
||
resource "mongodbatlas_privatelink_endpoint_service_data_federation_online_archive" "test" { | ||
project_id = var.project_id | ||
endpoint_id = aws_vpc_endpoint.vpce_east.id | ||
provider_name = "AWS" | ||
comment = "Terraform Acceptance Test" | ||
} |
57 changes: 57 additions & 0 deletions
57
examples/aws-privatelink-endpoint/data-federation-online-archive/aws-vpc.tf
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
resource "aws_vpc_endpoint" "vpce_east" { | ||
vpc_id = aws_vpc.vpc_east.id | ||
service_name = mongodbatlas_privatelink_endpoint.pe_east.endpoint_service_name | ||
vpc_endpoint_type = "Interface" | ||
subnet_ids = [aws_subnet.subnet_east_a.id, aws_subnet.subnet_east_b.id] | ||
security_group_ids = [aws_security_group.sg_east.id] | ||
} | ||
|
||
resource "aws_vpc" "vpc_east" { | ||
cidr_block = "10.0.0.0/16" | ||
enable_dns_hostnames = true | ||
enable_dns_support = true | ||
} | ||
|
||
resource "aws_internet_gateway" "ig_east" { | ||
vpc_id = aws_vpc.vpc_east.id | ||
} | ||
|
||
resource "aws_route" "route_east" { | ||
route_table_id = aws_vpc.vpc_east.main_route_table_id | ||
destination_cidr_block = "0.0.0.0/0" | ||
gateway_id = aws_internet_gateway.ig_east.id | ||
} | ||
|
||
resource "aws_subnet" "subnet_east_a" { | ||
vpc_id = aws_vpc.vpc_east.id | ||
cidr_block = "10.0.1.0/24" | ||
map_public_ip_on_launch = true | ||
availability_zone = "us-east-1a" | ||
} | ||
|
||
resource "aws_subnet" "subnet_east_b" { | ||
vpc_id = aws_vpc.vpc_east.id | ||
cidr_block = "10.0.2.0/24" | ||
map_public_ip_on_launch = false | ||
availability_zone = "us-east-1b" | ||
} | ||
|
||
resource "aws_security_group" "sg_east" { | ||
name_prefix = "default-" | ||
description = "Default security group for all instances in vpc" | ||
vpc_id = aws_vpc.vpc_east.id | ||
ingress { | ||
from_port = 0 | ||
to_port = 0 | ||
protocol = "tcp" | ||
cidr_blocks = [ | ||
"0.0.0.0/0", | ||
] | ||
} | ||
egress { | ||
from_port = 0 | ||
to_port = 0 | ||
protocol = "-1" | ||
cidr_blocks = ["0.0.0.0/0"] | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
examples/aws-privatelink-endpoint/data-federation-online-archive/provider.tf
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
provider "mongodbatlas" { | ||
public_key = var.public_key | ||
private_key = var.private_key | ||
} | ||
provider "aws" { | ||
access_key = var.access_key | ||
secret_key = var.secret_key | ||
region = "us-east-1" | ||
} |
15 changes: 15 additions & 0 deletions
15
examples/aws-privatelink-endpoint/data-federation-online-archive/variables.tf
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
variable "public_key" { | ||
description = "The public API key for MongoDB Atlas" | ||
} | ||
variable "private_key" { | ||
description = "The private API key for MongoDB Atlas" | ||
} | ||
variable "access_key" { | ||
description = "The access key for AWS Account" | ||
} | ||
variable "secret_key" { | ||
description = "The secret key for AWS Account" | ||
} | ||
variable "project_id" { | ||
description = "Atlas project ID" | ||
} |
11 changes: 11 additions & 0 deletions
11
examples/aws-privatelink-endpoint/data-federation-online-archive/versions.tf
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
terraform { | ||
required_providers { | ||
aws = { | ||
source = "hashicorp/aws" | ||
} | ||
mongodbatlas = { | ||
source = "mongodb/mongodbatlas" | ||
} | ||
} | ||
required_version = ">= 0.13" | ||
} |
66 changes: 66 additions & 0 deletions
66
...s/data_source_mongodbatlas_privatelink_endpoint_service_data_federation_online_archive.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package mongodbatlas | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/v2/diag" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||
) | ||
|
||
func dataSourceMongoDBAtlasPrivatelinkEndpointServiceDataFederationOnlineArchive() *schema.Resource { | ||
return &schema.Resource{ | ||
ReadContext: dataSourceMongoDBAtlasPrivatelinkEndpointServiceDataFederationOnlineArchiveRead, | ||
Schema: map[string]*schema.Schema{ | ||
"project_id": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
}, | ||
"endpoint_id": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
}, | ||
"provider_name": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"comment": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"type": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func dataSourceMongoDBAtlasPrivatelinkEndpointServiceDataFederationOnlineArchiveRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { | ||
conn := meta.(*MongoDBClient).Atlas | ||
projectID := d.Get("project_id").(string) | ||
endopointID := d.Get("endpoint_id").(string) | ||
|
||
privateEndpoint, _, err := conn.DataLakes.GetPrivateLinkEndpoint(context.Background(), projectID, endopointID) | ||
if err != nil { | ||
return diag.Errorf(errorPrivateEndpointServiceDataFederationOnlineArchiveRead, endopointID, projectID, err) | ||
} | ||
|
||
if err := d.Set("comment", privateEndpoint.Comment); err != nil { | ||
return diag.Errorf(errorPrivateEndpointServiceDataFederationOnlineArchiveRead, endopointID, projectID, err) | ||
} | ||
|
||
if err := d.Set("provider_name", privateEndpoint.Provider); err != nil { | ||
return diag.Errorf(errorPrivateEndpointServiceDataFederationOnlineArchiveRead, endopointID, projectID, err) | ||
} | ||
|
||
if err := d.Set("type", privateEndpoint.Type); err != nil { | ||
return diag.Errorf(errorPrivateEndpointServiceDataFederationOnlineArchiveRead, endopointID, projectID, err) | ||
} | ||
|
||
d.SetId(encodeStateID(map[string]string{ | ||
"project_id": projectID, | ||
"endpoint_id": endopointID, | ||
})) | ||
|
||
return nil | ||
} |
50 changes: 50 additions & 0 deletions
50
...a_source_mongodbatlas_privatelink_endpoint_service_data_federation_online_archive_test.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package mongodbatlas | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" | ||
) | ||
|
||
var ( | ||
dataSourcePrivatelinkEndpointServiceDataFederetionDataArchive = "data.mongodbatlas_privatelink_endpoint_service_data_federation_online_archive.test" | ||
) | ||
|
||
func TestAccDataSourceMongoDBAtlasPrivatelinkEndpointServiceDataFederationOnlineArchive_basic(t *testing.T) { | ||
testCheckPrivateEndpointServiceDataFederationOnlineArchiveRun(t) | ||
resource.Test(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
ProviderFactories: testAccProviderFactories, | ||
CheckDestroy: testAccCheckMongoDBAtlasPrivateEndpointServiceDataFederationOnlineArchiveDestroy, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccDataSourceMongoDBAtlasPrivateEndpointServiceDataFederationOnlineArchiveConfig(projectID, endpointID), | ||
Check: resource.ComposeTestCheckFunc( | ||
testAccCheckMongoDBAtlasPrivateEndpointServiceDataFederationOnlineArchiveExists(resourceNamePrivatelinkEdnpointServiceDataFederationOnlineArchive), | ||
resource.TestCheckResourceAttr(dataSourcePrivatelinkEndpointServiceDataFederetionDataArchive, "project_id", projectID), | ||
resource.TestCheckResourceAttr(dataSourcePrivatelinkEndpointServiceDataFederetionDataArchive, "endpoint_id", endpointID), | ||
resource.TestCheckResourceAttrSet(dataSourcePrivatelinkEndpointServiceDataFederetionDataArchive, "comment"), | ||
resource.TestCheckResourceAttrSet(dataSourcePrivatelinkEndpointServiceDataFederetionDataArchive, "type"), | ||
resource.TestCheckResourceAttrSet(dataSourcePrivatelinkEndpointServiceDataFederetionDataArchive, "provider_name"), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func testAccDataSourceMongoDBAtlasPrivateEndpointServiceDataFederationOnlineArchiveConfig(projectID, endpointID string) string { | ||
return fmt.Sprintf(` | ||
resource "mongodbatlas_privatelink_endpoint_service_data_federation_online_archive" "test" { | ||
project_id = %[1]q | ||
endpoint_id = %[2]q | ||
provider_name = "AWS" | ||
comment = "Terraform Acceptance Test" | ||
} | ||
|
||
data "mongodbatlas_privatelink_endpoint_service_data_federation_online_archive" "test" { | ||
project_id = mongodbatlas_privatelink_endpoint_service_data_federation_online_archive.test.project_id | ||
endpoint_id = mongodbatlas_privatelink_endpoint_service_data_federation_online_archive.test.endpoint_id | ||
} | ||
`, projectID, endpointID) | ||
} |
86 changes: 86 additions & 0 deletions
86
.../data_source_mongodbatlas_privatelink_endpoint_service_data_federation_online_archives.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
package mongodbatlas | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/v2/diag" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/id" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||
matlas "go.mongodb.org/atlas/mongodbatlas" | ||
) | ||
|
||
const errorPrivateEndpointServiceDataFederationOnlineArchiveList = "error reading Private Endpoings for projectId %s: %s" | ||
|
||
func dataSourceMongoDBAtlasPrivatelinkEndpointServiceDataFederationOnlineArchives() *schema.Resource { | ||
return &schema.Resource{ | ||
ReadContext: dataSourceMongoDBAtlasPrivatelinkEndpointServiceDataFederationOnlineArchivesRead, | ||
Schema: map[string]*schema.Schema{ | ||
"project_id": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
}, | ||
"results": { | ||
Type: schema.TypeList, | ||
Computed: true, | ||
Elem: &schema.Resource{ | ||
Schema: map[string]*schema.Schema{ | ||
"endpoint_id": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
}, | ||
"provider_name": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"comment": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"type": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func dataSourceMongoDBAtlasPrivatelinkEndpointServiceDataFederationOnlineArchivesRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { | ||
conn := meta.(*MongoDBClient).Atlas | ||
projectID := d.Get("project_id").(string) | ||
|
||
privateEndpoints, _, err := conn.DataLakes.ListPrivateLinkEndpoint(context.Background(), projectID) | ||
if err != nil { | ||
return diag.Errorf(errorPrivateEndpointServiceDataFederationOnlineArchiveList, projectID, err) | ||
} | ||
|
||
if err := d.Set("results", flattenPrivateLinkEndpointDataLakeResponse(privateEndpoints.Results)); err != nil { | ||
return diag.FromErr(fmt.Errorf(errorDataLakeSetting, "results", projectID, err)) | ||
} | ||
|
||
d.SetId(id.UniqueId()) | ||
|
||
return nil | ||
} | ||
|
||
func flattenPrivateLinkEndpointDataLakeResponse(atlasPrivateLinkEndpointDataLakes []*matlas.PrivateLinkEndpointDataLake) []map[string]interface{} { | ||
if len(atlasPrivateLinkEndpointDataLakes) == 0 { | ||
return []map[string]interface{}{} | ||
} | ||
|
||
results := make([]map[string]interface{}, len(atlasPrivateLinkEndpointDataLakes)) | ||
|
||
for i, atlasPrivateLinkEndpointDataLake := range atlasPrivateLinkEndpointDataLakes { | ||
results[i] = map[string]interface{}{ | ||
"endpoint_id": atlasPrivateLinkEndpointDataLake.EndpointID, | ||
"provider_name": atlasPrivateLinkEndpointDataLake.Provider, | ||
"comment": atlasPrivateLinkEndpointDataLake.Comment, | ||
"type": atlasPrivateLinkEndpointDataLake.Type, | ||
} | ||
} | ||
|
||
return results | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome section, really helpful how you listed all the options. great work!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1, really nicely done