-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added AWS service account and SQS module to ArmoniK.Infra
- Loading branch information
1 parent
f8a6459
commit 096b190
Showing
11 changed files
with
246 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
|
||
|
||
locals { | ||
prefix = var.prefix | ||
tags = merge(var.tags, { module = "aws-service-account" }) | ||
oidc_arn = var.oidc_provider_arn | ||
oidc_url = trimprefix(var.oidc_issuer_url, "https://") | ||
} | ||
|
||
resource "aws_iam_role" "armonik" { | ||
name = "${local.prefix}-eks-pod-identity-armonik" | ||
assume_role_policy = jsonencode({ | ||
Version = "2012-10-17" | ||
Statement = [ | ||
{ | ||
Effect = "Allow" | ||
Principal = { | ||
Federated = local.oidc_arn | ||
} | ||
Action = "sts:AssumeRoleWithWebIdentity" | ||
Condition = { | ||
StringEquals = { | ||
"${local.oidc_url}:aud" = "sts.amazonaws.com" | ||
"${local.oidc_url}:sub" = [ | ||
"system:serviceaccount:${var.namespace}:${var.service_account_name}", | ||
] | ||
} | ||
} | ||
} | ||
] | ||
}) | ||
tags = local.tags | ||
} | ||
|
||
resource "aws_iam_policy_attachment" "armonik_decrypt_object" { | ||
name = "${local.prefix}-s3-encrypt-decrypt-armonik" | ||
roles = [aws_iam_role.armonik.name] | ||
policy_arn = var.decrypt_policy_arn | ||
} | ||
|
||
resource "kubernetes_service_account" "armonik" { | ||
metadata { | ||
name = var.service_account_name | ||
namespace = var.namespace | ||
|
||
annotations = { | ||
"eks.amazonaws.com/role-arn" = aws_iam_role.armonik.arn | ||
} | ||
} | ||
automount_service_account_token = var.automount_service_account_token | ||
} |
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,4 @@ | ||
output "service_account_iam_role_name" { | ||
description = "name of the IAM role associated to the created Kubernetes service account" | ||
value = aws_iam_role.armonik.name | ||
} |
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,43 @@ | ||
variable "prefix" { | ||
description = "Prefix to use for service account related resources" | ||
type = string | ||
} | ||
|
||
# Tags | ||
variable "tags" { | ||
description = "Tags for resource" | ||
type = map(string) | ||
default = {} | ||
} | ||
|
||
variable "namespace" { | ||
description = "Namespace of ArmoniK service account related resources" | ||
type = string | ||
default = "armonik" | ||
} | ||
|
||
variable "service_account_name" { | ||
description = "Name of the service account to create" | ||
type = string | ||
} | ||
|
||
variable "automount_service_account_token" { | ||
description = "To enable automatic mounting of the Kubernetes service account token." | ||
type = bool | ||
default = true | ||
} | ||
|
||
variable "oidc_provider_arn" { | ||
description = "ARN of the OIDC provider" | ||
type = string | ||
} | ||
|
||
variable "decrypt_policy_arn" { | ||
description = "ARN of the S3 encrypt/decrypt IAM policy" | ||
type = string | ||
} | ||
|
||
variable "oidc_issuer_url" { | ||
description = "URL of the OIDC issuer" | ||
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,13 @@ | ||
terraform { | ||
required_version = ">= 1.0" | ||
required_providers { | ||
aws = { | ||
source = "hashicorp/aws" | ||
version = ">= 5.61" | ||
} | ||
kubernetes = { | ||
source = "hashicorp/kubernetes" | ||
version = ">= 2.7.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
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,36 @@ | ||
locals { | ||
prefix = var.prefix | ||
region = var.region | ||
tags = merge(var.tags, { module = "amazon-sqs" }) | ||
} | ||
|
||
|
||
data "aws_iam_policy_document" "sqs" { | ||
statement { | ||
sid = "SqsAdmin" | ||
actions = [ | ||
"sqs:CreateQueue", | ||
"sqs:DeleteQueue", | ||
"sqs:PurgeQueue", | ||
"sqs:GetQueueUrl", | ||
"sqs:ReceiveMessage", | ||
"sqs:SendMessage", | ||
"sqs:ChangeMessageVisibility" | ||
] | ||
effect = "Allow" | ||
resources = ["*"] | ||
} | ||
} | ||
|
||
resource "aws_iam_policy" "sqs" { | ||
name_prefix = "${local.prefix}-sqs-admin" | ||
description = "Policy for allowing SQS admin access" | ||
policy = data.aws_iam_policy_document.sqs.json | ||
tags = local.tags | ||
} | ||
|
||
resource "aws_iam_policy_attachment" "sqs" { | ||
name = "${local.prefix}-sqs" | ||
roles = [var.service_account_role_name] | ||
policy_arn = aws_iam_policy.sqs.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 @@ | ||
output "env" { | ||
description = "Environment variables to pass to ArmoniK.Core" | ||
value = { | ||
"Components__QueueAdaptorSettings__ClassName" = "ArmoniK.Core.Adapters.SQS.QueueBuilder" | ||
"Components__QueueAdaptorSettings__AdapterAbsolutePath" = "/adapters/queue/sqs/ArmoniK.Core.Adapters.SQS.dll" | ||
"SQS__ServiceURL" = "https://sqs.${local.region}.amazonaws.com" | ||
"SQS__Prefix" = local.prefix | ||
} | ||
} |
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,20 @@ | ||
variable "region" { | ||
description = "Region" | ||
type = string | ||
} | ||
|
||
variable "prefix" { | ||
description = "Prefix to use for SQS queues" | ||
type = string | ||
} | ||
|
||
variable "tags" { | ||
description = "Tags for resource" | ||
type = map(string) | ||
default = {} | ||
} | ||
|
||
variable "service_account_role_name" { | ||
description = "Name of the IAM role to give the SQS permissions to" | ||
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,9 @@ | ||
terraform { | ||
required_version = ">= 1.0" | ||
required_providers { | ||
aws = { | ||
source = "hashicorp/aws" | ||
version = ">= 5.61" | ||
} | ||
} | ||
} |