diff --git a/modules/aws/volume-access/main.tf b/modules/aws/volume-access/main.tf index 6d4800d..120fd98 100644 --- a/modules/aws/volume-access/main.tf +++ b/modules/aws/volume-access/main.tf @@ -1,10 +1,10 @@ data "aws_caller_identity" "current" {} locals { - external_id = (var.external_id != "" ? [{ test : "StringEquals", variable : "sts:ExternalId", values : [var.external_id] }] : []) - account_ids = distinct(concat(var.account_ids, local.default_account_ids)) - bucket_list = distinct([for item in var.buckets : "arn:aws:s3:::${split("/", item)[0]}"]) - bucket_path_list = distinct([for item in var.buckets: "arn:aws:s3:::${item}"]) - tag_set = merge({ Vendor = "StreamNative", Module = "StreamNative Volume", SNVersion = var.sn_policy_version }, var.tags) + external_id = (var.external_id != "" ? [{ test : "StringEquals", variable : "sts:ExternalId", values : [var.external_id] }] : []) + account_ids = distinct(concat(var.account_ids, local.default_account_ids)) + bucket_list = distinct([for item in var.buckets : "arn:aws:s3:::${split("/", item)[0]}"]) + bucket_path_list = distinct([for item in var.buckets : "arn:aws:s3:::${item}"]) + tag_set = merge({ Vendor = "StreamNative", Module = "StreamNative Volume", SNVersion = var.sn_policy_version }, var.tags) default_account_ids = compact([ # will add it in the next pr ]) @@ -65,10 +65,9 @@ data "aws_iam_policy_document" "streamnative_management_access" { ###### #-- Create the IAM role for the the StreamNative Cloud data access to s3 bucket ###### -resource "aws_iam_policy" "access_bucket_role" { - name = "${var.role}" - description = "This policy sets the limits for the access s3 bucket for StreamNative's vendor access." - path = "/StreamNative/" +resource "aws_iam_role_policy" "access_bucket_role" { + name = var.role + role = var.role policy = jsonencode({ "Version" : "2012-10-17", "Statement" : [ @@ -86,7 +85,7 @@ resource "aws_iam_policy" "access_bucket_role" { "s3:GetObject", "s3:DeleteObject" ], - "Resource" : [for item in local.bucket_path_list: "${item}/*"] + "Resource" : [for item in local.bucket_path_list : "${item}/*"] }, { "Effect" : "Allow", @@ -101,15 +100,10 @@ resource "aws_iam_policy" "access_bucket_role" { } resource "aws_iam_role" "access_bucket_role" { - name = "${var.role}" + name = var.role description = "This role is used by StreamNative for the access s3 bucket." assume_role_policy = data.aws_iam_policy_document.streamnative_management_access.json path = "/StreamNative/" tags = local.tag_set max_session_duration = 43200 -} - -resource "aws_iam_role_policy_attachment" "access_bucket_role" { - policy_arn = aws_iam_policy.access_bucket_role.arn - role = aws_iam_role.access_bucket_role.name } \ No newline at end of file diff --git a/modules/aws/volume-access/variables.tf b/modules/aws/volume-access/variables.tf index 7e96fdb..3773061 100644 --- a/modules/aws/volume-access/variables.tf +++ b/modules/aws/volume-access/variables.tf @@ -23,18 +23,18 @@ variable "tags" { } variable "buckets" { - default = [] + default = [] description = "User bucket and path name" type = list(string) } variable "role" { description = "Your aws iam role for access s3 bucket" - type = string + type = string } variable "account_ids" { - default = [] + default = [] description = "Your account id" - type = list(string) + type = list(string) } \ No newline at end of file