Skip to content

Commit 55280ad

Browse files
authored
feat: Support s3 table (#111)
1 parent cc5d04f commit 55280ad

File tree

5 files changed

+107
-1
lines changed

5 files changed

+107
-1
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
module "sn_managed_cloud_access_bucket" {
2+
source = "../../modules/aws/volume-access"
3+
4+
external_id = "<your-organization>"
5+
role = "<your-role-name>"
6+
buckets = [
7+
]
8+
9+
account_ids = [
10+
]
11+
}
12+
13+
module "sn_managed_cloud_access_s3_table" {
14+
source = "../../modules/aws/s3-table-access"
15+
role = module.sn_managed_cloud_access_bucket.role
16+
s3_tables = []
17+
depends_on = [module.sn_managed_cloud_access_bucket]
18+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
data "aws_caller_identity" "current" {}
2+
locals {
3+
s3_tables_resource = distinct([for item in var.s3_tables : endswith(item, "/*") ? "${item}" : "${item}/*"])
4+
tag_set = merge({ Vendor = "StreamNative", Module = "StreamNative S3 Table Access", SNVersion = var.sn_policy_version }, var.tags)
5+
}
6+
7+
######
8+
#-- Create the IAM role inline policy for the the StreamNative Cloud access to s3 table
9+
######
10+
resource "aws_iam_role_policy" "s3_access_policy" {
11+
name = "${var.role}-s3-table"
12+
role = var.role
13+
policy = jsonencode({
14+
"Version" : "2012-10-17",
15+
"Statement" : [
16+
{
17+
"Sid" : "LakeFormationPermissionsForS3ListTableBucket",
18+
"Effect" : "Allow",
19+
"Action" : [
20+
"s3tables:ListTableBuckets"
21+
],
22+
"Resource" : [
23+
"*"
24+
]
25+
},
26+
{
27+
"Sid" : "LakeFormationDataAccessPermissionsForS3TableBucket",
28+
"Effect" : "Allow",
29+
"Action" : [
30+
"s3tables:CreateTableBucket",
31+
"s3tables:GetTableBucket",
32+
"s3tables:CreateNamespace",
33+
"s3tables:GetNamespace",
34+
"s3tables:ListNamespaces",
35+
"s3tables:DeleteNamespace",
36+
"s3tables:DeleteTableBucket",
37+
"s3tables:CreateTable",
38+
"s3tables:DeleteTable",
39+
"s3tables:GetTable",
40+
"s3tables:ListTables",
41+
"s3tables:RenameTable",
42+
"s3tables:UpdateTableMetadataLocation",
43+
"s3tables:GetTableMetadataLocation",
44+
"s3tables:GetTableData",
45+
"s3tables:PutTableData"
46+
],
47+
"Resource" : local.s3_tables_resource
48+
}
49+
]
50+
})
51+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
variable "sn_policy_version" {
2+
description = "The value of SNVersion tag"
3+
default = "3.16.1" # {{ x-release-please-version }}
4+
type = string
5+
}
6+
7+
variable "tags" {
8+
default = {}
9+
description = "Extra tags to apply to the resources created by this module."
10+
type = map(string)
11+
}
12+
13+
variable "s3_tables" {
14+
default = []
15+
description = "User s3 tables and path name"
16+
type = list(string)
17+
}
18+
19+
variable "role" {
20+
description = "Your aws iam role for access s3 bucket"
21+
type = string
22+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
terraform {
2+
required_version = ">= 1.0"
3+
4+
required_providers {
5+
aws = {
6+
source = "hashicorp/aws"
7+
version = ">= 5.30"
8+
}
9+
}
10+
}

modules/aws/volume-access/main.tf

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ data "aws_iam_policy_document" "streamnative_management_access" {
3636
#-- Create the IAM role for the the StreamNative Cloud data plane access to s3 bucket
3737
######
3838
resource "aws_iam_role_policy" "access_bucket_role" {
39-
name = var.role
39+
name = "${var.role}-s3-bucket"
4040
role = aws_iam_role.access_bucket_role.id
4141
policy = jsonencode({
4242
"Version" : "2012-10-17",
@@ -76,4 +76,9 @@ resource "aws_iam_role" "access_bucket_role" {
7676
path = "/StreamNative/"
7777
tags = local.tag_set
7878
max_session_duration = 43200
79+
}
80+
81+
output "role" {
82+
value = var.role
83+
description = "role name"
7984
}

0 commit comments

Comments
 (0)