-
Notifications
You must be signed in to change notification settings - Fork 187
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
INTMDB 186 - Added authorization resource to split the cloud access provider config #420
Merged
Merged
Changes from 19 commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
28be2a1
splitting schema into two resources
leofigy 8b208a0
added read for second resource
leofigy bf63d3b
auth resource
leofigy a61dc48
fixing linter
leofigy cc0343f
added placeholder foos
leofigy c953bd9
importer for CloudProviderAccessSetup
leofigy d213220
example single apply terraform
leofigy c7b0372
clean up
leofigy 5a7fe8a
documentation update and description
leofigy c7a4b22
terratest single apply
leofigy 57ca2d3
datasource for setup
leofigy 969880f
adding test case for datasource :)
leofigy 6ee487a
update in authorization resource
leofigy 32197c9
testing for setup resource and import
leofigy 26404b5
import test
leofigy 602462d
document for cloud provider access setup datasource
leofigy a9df805
documentation update
leofigy cbf50ba
pr comments :)
leofigy 33ef00b
Update cloud_provider_access.markdown
leofigy 2004650
pr comment :)
leofigy dac7f6f
pr comment typo
leofigy 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
This file contains 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
This file contains 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,41 @@ | ||
resource "aws_iam_role_policy" "test_policy" { | ||
name = "mongo_setup_policy" | ||
role = aws_iam_role.test_role.id | ||
|
||
policy = <<-EOF | ||
{ | ||
"Version": "2012-10-17", | ||
"Statement": [ | ||
{ | ||
"Effect": "Allow", | ||
"Action": "*", | ||
"Resource": "*" | ||
} | ||
] | ||
} | ||
EOF | ||
} | ||
|
||
resource "aws_iam_role" "test_role" { | ||
name = "mongo_setup_test_role" | ||
|
||
assume_role_policy = <<EOF | ||
{ | ||
"Version": "2012-10-17", | ||
"Statement": [ | ||
{ | ||
"Effect": "Allow", | ||
"Principal": { | ||
"AWS": "${mongodbatlas_cloud_provider_access_setup.setup_only.aws.atlas_aws_account_arn}" | ||
}, | ||
"Action": "sts:AssumeRole", | ||
"Condition": { | ||
"StringEquals": { | ||
"sts:ExternalId": "${mongodbatlas_cloud_provider_access_setup.setup_only.aws.atlas_assumed_role_external_id}" | ||
} | ||
} | ||
} | ||
] | ||
} | ||
EOF | ||
} |
This file contains 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,13 @@ | ||
resource "mongodbatlas_cloud_provider_access_setup" "setup_only" { | ||
project_id = var.project_id | ||
provider_name = var.cloud_provider_access_name | ||
} | ||
|
||
resource "mongodbatlas_cloud_provider_access_authorization" "auth_role" { | ||
project_id = var.project_id | ||
role_id = mongodbatlas_cloud_provider_access_setup.setup_only.role_id | ||
|
||
aws = { | ||
iam_assumed_role_arn = aws_iam_role.test_role.arn | ||
} | ||
} |
This file contains 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 = var.aws_region | ||
} |
This file contains 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,25 @@ | ||
// mongo | ||
variable project_id { | ||
type = string | ||
} | ||
variable cloud_provider_access_name { | ||
type = string | ||
default = "AWS" | ||
} | ||
variable public_key { | ||
type = string | ||
} | ||
variable private_key { | ||
type = string | ||
} | ||
|
||
// aws | ||
variable access_key { | ||
type = string | ||
} | ||
variable secret_key { | ||
type = string | ||
} | ||
variable aws_region { | ||
type = string | ||
} |
This file contains 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,8 @@ | ||
terraform { | ||
required_providers { | ||
mongodbatlas = { | ||
source = "mongodb/mongodbatlas" | ||
} | ||
} | ||
required_version = ">= 0.13" | ||
} |
This file contains 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,21 @@ | ||||||
### Integration tests | ||||||
|
||||||
Integration tests required extra credentials, such as for aws and azure, | ||||||
in order to execute the complete terraform cycle (init, apply, destroy) | ||||||
|
||||||
For all the testing it needs the common environment variables | ||||||
``` | ||||||
MONGODB_ATLAS_PROJECT_ID | ||||||
MONGODB_ATLAS_PUBLIC_KEY | ||||||
MONGODB_ATLAS_PRIVATE_KEY | ||||||
``` | ||||||
|
||||||
For especific aws related interactions | ||||||
``` | ||||||
AWS_ACCESS_KEY_ID | ||||||
AWS_SECRET_ACCESS_KEY | ||||||
AWS_REGION | ||||||
|
||||||
AWS_CUSTOMER_MASTER_KEY_ID (only cloud at rest) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
||||||
``` | ||||||
themantissa marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains 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,33 @@ | ||
package integration_testing | ||
|
||
import "os" | ||
|
||
type MongoDBCredentials struct { | ||
ProjectID string | ||
PublicKey string | ||
PrivateKey string | ||
} | ||
|
||
type AWSCredentials struct { | ||
AccessKey string | ||
SecretKey string | ||
CustomerMasterKey string | ||
AwsRegion string | ||
} | ||
|
||
func GetCredentialsFromEnv() MongoDBCredentials { | ||
return MongoDBCredentials{ | ||
ProjectID: os.Getenv("MONGODB_ATLAS_PROJECT_ID"), | ||
PublicKey: os.Getenv("MONGODB_ATLAS_PUBLIC_KEY"), | ||
PrivateKey: os.Getenv("MONGODB_ATLAS_PRIVATE_KEY"), | ||
} | ||
} | ||
|
||
func GetAWSCredentialsFromEnv() AWSCredentials { | ||
return AWSCredentials{ | ||
AccessKey: os.Getenv("AWS_ACCESS_KEY_ID"), | ||
SecretKey: os.Getenv("AWS_SECRET_ACCESS_KEY"), | ||
CustomerMasterKey: os.Getenv("AWS_CUSTOMER_MASTER_KEY_ID"), | ||
AwsRegion: os.Getenv("AWS_REGION"), | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
integration-testing/resource_mongodbatlas_cloud_provider_access_test.go
This file contains 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,44 @@ | ||
// +build integration | ||
|
||
package integration_testing | ||
|
||
import ( | ||
"os" | ||
"testing" | ||
|
||
"github.com/gruntwork-io/terratest/modules/terraform" | ||
) | ||
|
||
const ( | ||
defaultTerratestFilesCPA = "../examples/atlas-cloud-provider-access/aws/" | ||
) | ||
|
||
func TestTerraformResourceMongoDBAtlasCloudProviderAccess_basicAWS(t *testing.T) { | ||
t.Parallel() | ||
|
||
mongoSecrets := GetCredentialsFromEnv() | ||
awsSecrets := GetAWSCredentialsFromEnv() | ||
|
||
testFiles := os.Getenv("TERRATEST_CLOUD_PROVIDER_ACCESS_AWS") | ||
if testFiles == "" { | ||
testFiles = defaultTerratestFilesCPA | ||
} | ||
|
||
terraformOptions := &terraform.Options{ | ||
TerraformDir: testFiles, | ||
Vars: map[string]interface{}{ | ||
"project_id": mongoSecrets.ProjectID, | ||
"cloud_provider_access_name": "AWS", | ||
"public_key": mongoSecrets.PublicKey, | ||
"private_key": mongoSecrets.PrivateKey, | ||
"access_key": awsSecrets.AccessKey, | ||
"secret_key": awsSecrets.SecretKey, | ||
"aws_region": awsSecrets.AwsRegion, | ||
}, | ||
} | ||
|
||
terraformTest := terraform.WithDefaultRetryableErrors(t, terraformOptions) | ||
|
||
defer terraform.Destroy(t, terraformTest) | ||
terraform.InitAndApply(t, terraformTest) | ||
} |
This file contains 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
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.