From bc3c9ce30e5a13794ebb122dfcc4c17f7df0a052 Mon Sep 17 00:00:00 2001 From: zohar-mongo <72696720+zohar-mongo@users.noreply.github.com> Date: Wed, 3 Mar 2021 19:17:41 +0200 Subject: [PATCH] Working example for Atlas-encryptionAtRest-roles with a single tf apply (#415) * Update aws-roles.tf * Update aws-roles.tf * Update aws-roles.tf * Update aws-roles.tf * two options for aws encryption at rest with iam roles * removed extra spaces and notes Co-authored-by: Zohar Meir --- .../aws-roles.tf | 75 +++++++++++++++++++ .../provider.tf | 0 .../second_step/atlas-encryption.tf | 0 .../second_step/provider.tf | 0 .../second_step/variables.tf | 0 .../second_step/versions.tf | 0 .../variables.tf | 0 .../versions.tf | 1 - .../aws-roles.tf | 16 ++-- .../provider.tf | 9 +++ .../second_step/atlas-encryption.tf | 13 ++++ .../second_step/provider.tf | 4 + .../second_step/variables.tf | 33 ++++++++ .../second_step/versions.tf | 9 +++ .../variables.tf | 36 +++++++++ .../versions.tf | 11 +++ 16 files changed, 196 insertions(+), 11 deletions(-) create mode 100644 examples/atlas-encryptionAtRest-roles-one-step-workaround/aws-roles.tf rename examples/{atlas-encryptionAtRest-roles => atlas-encryptionAtRest-roles-one-step-workaround}/provider.tf (100%) rename examples/{atlas-encryptionAtRest-roles => atlas-encryptionAtRest-roles-one-step-workaround}/second_step/atlas-encryption.tf (100%) rename examples/{atlas-encryptionAtRest-roles => atlas-encryptionAtRest-roles-one-step-workaround}/second_step/provider.tf (100%) rename examples/{atlas-encryptionAtRest-roles => atlas-encryptionAtRest-roles-one-step-workaround}/second_step/variables.tf (100%) rename examples/{atlas-encryptionAtRest-roles => atlas-encryptionAtRest-roles-one-step-workaround}/second_step/versions.tf (100%) rename examples/{atlas-encryptionAtRest-roles => atlas-encryptionAtRest-roles-one-step-workaround}/variables.tf (100%) rename examples/{atlas-encryptionAtRest-roles => atlas-encryptionAtRest-roles-one-step-workaround}/versions.tf (86%) rename examples/{atlas-encryptionAtRest-roles => atlas-encryptionAtRest-roles-two-step}/aws-roles.tf (81%) create mode 100644 examples/atlas-encryptionAtRest-roles-two-step/provider.tf create mode 100644 examples/atlas-encryptionAtRest-roles-two-step/second_step/atlas-encryption.tf create mode 100644 examples/atlas-encryptionAtRest-roles-two-step/second_step/provider.tf create mode 100644 examples/atlas-encryptionAtRest-roles-two-step/second_step/variables.tf create mode 100644 examples/atlas-encryptionAtRest-roles-two-step/second_step/versions.tf create mode 100644 examples/atlas-encryptionAtRest-roles-two-step/variables.tf create mode 100644 examples/atlas-encryptionAtRest-roles-two-step/versions.tf diff --git a/examples/atlas-encryptionAtRest-roles-one-step-workaround/aws-roles.tf b/examples/atlas-encryptionAtRest-roles-one-step-workaround/aws-roles.tf new file mode 100644 index 0000000000..9363d31ca8 --- /dev/null +++ b/examples/atlas-encryptionAtRest-roles-one-step-workaround/aws-roles.tf @@ -0,0 +1,75 @@ +resource "mongodbatlas_cloud_provider_access" "test" { + project_id = var.project_id + provider_name = "AWS" + + #(Optional) Since we update the `iam_assumed_role_arn` resource using an HTTP call and not by the `mongodbatlas_cloud_provider_access` resource argument, + #the lifecycle argument was added so that terraform would ignore changes of the `iam_assumed_role_arn` argument in future terraform applies. + lifecycle { + ignore_changes = [ + iam_assumed_role_arn + ] + } +} + +resource "aws_iam_role_policy" "test_policy" { + name = "test_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 = "test_role" + + assume_role_policy = <