-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🚩 (backend): Allows omitting the backend user and role (#7)
- Loading branch information
Showing
9 changed files
with
192 additions
and
37 deletions.
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
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,27 @@ | ||
terraform { | ||
required_version = ">= 0.13" | ||
required_providers { | ||
aws = { | ||
source = "hashicorp/aws" | ||
version = "~> 5.0" | ||
} | ||
} | ||
} | ||
|
||
provider "aws" { | ||
region = "us-east-1" | ||
} | ||
|
||
variable "namespace" { | ||
type = string | ||
} | ||
|
||
module "context" { | ||
source = "bendoerr-terraform-modules/context/null" | ||
version = "0.4.1" | ||
namespace = var.namespace | ||
environment = "example" | ||
role = "tfuser" | ||
region = "us-east-1" | ||
project = "simple" | ||
} |
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,5 @@ | ||
# You can use this file to define resource usage estimates for Infracost to use when calculating | ||
# the cost of usage-based resource, such as AWS S3 or Lambda. | ||
# `infracost breakdown --usage-file infracost-usage.yml [other flags]` | ||
# See https://infracost.io/usage-file/ for docs | ||
version: 0.1 |
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,28 @@ | ||
module "tfuser" { | ||
source = "../.." | ||
context = module.context.shared | ||
|
||
apply_user = { | ||
create = true, | ||
pgp_key = "keybase:bendoerr" | ||
} | ||
|
||
apply_role = { | ||
create = true | ||
budgets = true | ||
dynamodb = true | ||
ec2_account = true | ||
ec2_networking = true | ||
ec2_tags = true | ||
ecs = true | ||
efs = true | ||
iam = true | ||
kms = true | ||
lambda = true | ||
logs = true | ||
route53 = true | ||
s3 = true | ||
sns = true | ||
ssm_params = true | ||
} | ||
} |
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 |
---|---|---|
@@ -1,63 +1,63 @@ | ||
output "backend_user_arn" { | ||
value = var.backend_user.create ? aws_iam_user.backend[0].arn : "" | ||
value = try(aws_iam_user.backend[0].arn, data.aws_iam_user.backend[0].arn, null) | ||
} | ||
|
||
output "backend_user_name" { | ||
value = var.backend_user.create ? aws_iam_user.backend[0].name : "" | ||
value = try(aws_iam_user.backend[0].id, data.aws_iam_user.backend[0].user_name, null) | ||
} | ||
|
||
output "backend_user_unique_id" { | ||
value = var.backend_user.create ? aws_iam_user.backend[0].unique_id : "" | ||
value = try(aws_iam_user.backend[0].unique_id, data.aws_iam_user.backend[0].id, null) | ||
} | ||
|
||
output "backend_user_access_key_id" { | ||
value = var.backend_user.create ? aws_iam_access_key.backend[0].id : "" | ||
value = var.backend_user.create ? aws_iam_access_key.backend[0].id : null | ||
} | ||
|
||
output "backend_user_access_key_encrypted_secret" { | ||
value = var.backend_user.create ? aws_iam_access_key.backend[0].encrypted_secret : "" | ||
value = var.backend_user.create ? aws_iam_access_key.backend[0].encrypted_secret : null | ||
} | ||
|
||
output "backend_role_arn" { | ||
value = var.backend_role.create ? aws_iam_role.backend[0].arn : data.aws_iam_role.backend[0].arn | ||
value = try(aws_iam_role.backend[0].arn, data.aws_iam_role.backend[0].arn, null) | ||
} | ||
|
||
output "backend_role_name" { | ||
value = var.backend_role.create ? aws_iam_role.backend[0].name : data.aws_iam_role.backend[0].name | ||
value = try(aws_iam_role.backend[0].name, data.aws_iam_role.backend[0].name, null) | ||
} | ||
|
||
output "backend_dynamodb_rw_policy_arn" { | ||
value = var.backend_role.dynamodb_policy.create ? aws_iam_policy.backend_s3_rw[0].arn : var.backend_role.s3_policy.policy_arn | ||
value = try(aws_iam_policy.backend_dynamodb_rw[0].arn, var.backend_role.dynamodb_policy.policy_arn) | ||
} | ||
|
||
output "backend_s3_rw_policy_arn" { | ||
value = var.backend_role.s3_policy.create ? aws_iam_policy.backend_s3_rw[0].arn : var.backend_role.s3_policy.policy_arn | ||
value = try(aws_iam_policy.backend_s3_rw[0].arn, var.backend_role.s3_policy.policy_arn) | ||
} | ||
|
||
output "apply_user_arn" { | ||
value = var.apply_user.create ? aws_iam_user.apply[0].arn : "" | ||
value = try(aws_iam_user.apply[0].arn, data.aws_iam_user.apply[0].arn, null) | ||
} | ||
|
||
output "apply_user_name" { | ||
value = var.apply_user.create ? aws_iam_user.apply[0].name : "" | ||
value = try(aws_iam_user.apply[0].name, data.aws_iam_user.apply[0].user_name, null) | ||
} | ||
|
||
output "apply_user_unique_id" { | ||
value = var.apply_user.create ? aws_iam_user.apply[0].unique_id : "" | ||
value = try(aws_iam_user.apply[0].unique_id, data.aws_iam_user.apply[0].id, null) | ||
} | ||
|
||
output "apply_user_access_key_id" { | ||
value = var.apply_user.create ? aws_iam_access_key.apply[0].id : "" | ||
value = var.apply_user.create ? aws_iam_access_key.apply[0].id : null | ||
} | ||
|
||
output "apply_user_access_key_encrypted_secret" { | ||
value = var.apply_user.create ? aws_iam_access_key.apply[0].encrypted_secret : "" | ||
value = var.apply_user.create ? aws_iam_access_key.apply[0].encrypted_secret : null | ||
} | ||
|
||
output "apply_role_arn" { | ||
value = var.apply_role.create ? aws_iam_role.apply[0].arn : data.aws_iam_role.apply[0].arn | ||
value = try(aws_iam_role.apply[0].arn, data.aws_iam_role.apply[0].arn, null) | ||
} | ||
|
||
output "apply_role_name" { | ||
value = var.apply_role.create ? aws_iam_role.apply[0].name : data.aws_iam_role.apply[0].name | ||
value = try(aws_iam_role.apply[0].name, data.aws_iam_role.apply[0].name, null) | ||
} |
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,47 @@ | ||
package test_test | ||
|
||
import ( | ||
"context" | ||
"strings" | ||
"testing" | ||
|
||
"github.com/gruntwork-io/terratest/modules/random" | ||
|
||
"github.com/aws/aws-sdk-go-v2/config" | ||
"github.com/gruntwork-io/terratest/modules/terraform" | ||
test_structure "github.com/gruntwork-io/terratest/modules/test-structure" | ||
) | ||
|
||
func TestOnlyApply(t *testing.T) { | ||
rootFolder := "../" | ||
terraformFolderRelativeToRoot := "examples/only_apply" | ||
|
||
tempTestFolder := test_structure.CopyTerraformFolderToTemp(t, rootFolder, terraformFolderRelativeToRoot) | ||
|
||
rndns := strings.ToLower(random.UniqueId()) | ||
|
||
terraformOptions := &terraform.Options{ | ||
// The path to where our Terraform code is located | ||
TerraformDir: tempTestFolder, | ||
Upgrade: true, | ||
Vars: map[string]interface{}{ | ||
"namespace": rndns, | ||
}, | ||
} | ||
|
||
// At the end of the test, run `terraform destroy` to clean up any resources that were created | ||
defer terraform.Destroy(t, terraformOptions) | ||
|
||
// This will run `terraform init` and `terraform apply` and fail the test if there are any errors | ||
terraform.InitAndApply(t, terraformOptions) | ||
|
||
// AWS Session | ||
_, err := config.LoadDefaultConfig( | ||
context.TODO(), | ||
config.WithRegion("us-east-1"), | ||
) | ||
|
||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
} |
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