Compare commits
2 commits
Author | SHA1 | Date | |
---|---|---|---|
c7927f49eb | |||
00ee290f29 |
6 changed files with 74 additions and 25 deletions
|
@ -11,28 +11,20 @@ module "aws_iam_ci_user" {
|
||||||
source = "git::ssh://git@git.adyxax.org/adyxax/tofu-module-aws-iam-ci-user?depth=1&ref=1.0.1"
|
source = "git::ssh://git@git.adyxax.org/adyxax/tofu-module-aws-iam-ci-user?depth=1&ref=1.0.1"
|
||||||
|
|
||||||
name = local.name
|
name = local.name
|
||||||
}
|
tests_policy_statements = jsonencode([
|
||||||
|
{
|
||||||
resource "aws_iam_policy" "tftest" {
|
|
||||||
provider = aws.all["root"]
|
|
||||||
|
|
||||||
name = "${local.name}-tftest"
|
|
||||||
policy = jsonencode({
|
|
||||||
Statement = [{
|
|
||||||
Action = "iam:*"
|
Action = "iam:*"
|
||||||
Effect = "Allow"
|
Effect = "Allow"
|
||||||
Resource = [
|
Resource = [
|
||||||
"arn:aws:iam::*:user/tftest-user",
|
"arn:aws:iam::*:user/tftest-user",
|
||||||
"arn:aws:iam::*:policy/${local.name}-tftest",
|
"arn:aws:iam::*:policy/${local.name}-tftest",
|
||||||
]
|
]
|
||||||
}]
|
},
|
||||||
Version = "2012-10-17"
|
{
|
||||||
})
|
# Necessary for removing an IAM user
|
||||||
}
|
Action = "iam:ListVirtualMFADevices",
|
||||||
|
Effect = "Allow"
|
||||||
resource "aws_iam_user_policy_attachment" "tftest" {
|
Resource = "*"
|
||||||
provider = aws.all["root"]
|
}
|
||||||
|
])
|
||||||
policy_arn = aws_iam_policy.tftest.arn
|
|
||||||
user = local.name
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,15 +1,14 @@
|
||||||
provider "aws" {
|
provider "aws" {
|
||||||
profile = "root"
|
profile = "tests"
|
||||||
region = "eu-west-3"
|
region = "eu-west-3"
|
||||||
}
|
}
|
||||||
|
|
||||||
run "main" {
|
run "main" {
|
||||||
assert {
|
assert {
|
||||||
condition = output.access_key_id != null
|
condition = data.external.main.result.Arn == local.expected_arn
|
||||||
error_message = "invalid IAM access key ID"
|
error_message = "user ARN mismatch"
|
||||||
|
}
|
||||||
|
module {
|
||||||
|
source = "./test"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
variables {
|
|
||||||
name = "tftest-user"
|
|
||||||
}
|
|
||||||
|
|
4
test/aws_config.tftpl
Normal file
4
test/aws_config.tftpl
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
[default]
|
||||||
|
aws_access_key_id = ${aws_access_key_id}
|
||||||
|
aws_secret_access_key = ${aws_access_key_secret}
|
||||||
|
region = eu-west-3
|
31
test/main.tf
Normal file
31
test/main.tf
Normal file
|
@ -0,0 +1,31 @@
|
||||||
|
module "main" {
|
||||||
|
source = "../"
|
||||||
|
|
||||||
|
name = "tftest-user"
|
||||||
|
}
|
||||||
|
|
||||||
|
data "aws_caller_identity" "current" {}
|
||||||
|
|
||||||
|
# tflint-ignore: terraform_unused_declarations
|
||||||
|
data "external" "main" {
|
||||||
|
program = ["${path.module}/test.sh"]
|
||||||
|
|
||||||
|
depends_on = [local_file.aws_config]
|
||||||
|
}
|
||||||
|
|
||||||
|
locals {
|
||||||
|
# tflint-ignore: terraform_unused_declarations
|
||||||
|
expected_arn = format(
|
||||||
|
"arn:aws:iam::%s:user/tftest-user",
|
||||||
|
data.aws_caller_identity.current.account_id,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
resource "local_file" "aws_config" {
|
||||||
|
filename = "${path.module}/aws_config"
|
||||||
|
file_permission = "0600"
|
||||||
|
content = templatefile("${path.module}/aws_config.tftpl", {
|
||||||
|
aws_access_key_id = module.main.access_key_id
|
||||||
|
aws_access_key_secret = module.main.access_key_secret
|
||||||
|
})
|
||||||
|
}
|
15
test/providers.tf
Normal file
15
test/providers.tf
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
terraform {
|
||||||
|
required_providers {
|
||||||
|
aws = {
|
||||||
|
source = "hashicorp/aws"
|
||||||
|
}
|
||||||
|
external = {
|
||||||
|
source = "hashicorp/external"
|
||||||
|
version = "2.3.4"
|
||||||
|
}
|
||||||
|
local = {
|
||||||
|
source = "hashicorp/local"
|
||||||
|
version = "2.5.2"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
8
test/test.sh
Executable file
8
test/test.sh
Executable file
|
@ -0,0 +1,8 @@
|
||||||
|
#!/usr/bin/env bash
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
|
# Wait a bit for the ACCESS KEY to be usable on AWS
|
||||||
|
sleep 10
|
||||||
|
|
||||||
|
export AWS_CONFIG_FILE="${PWD}/test/aws_config"
|
||||||
|
aws sts get-caller-identity
|
Loading…
Add table
Add a link
Reference in a new issue