Skip to content

Commit b840ed9

Browse files
committed
Set s3 bucket name dynamically in ec2 instance profile permissions policy
1 parent 13c030a commit b840ed9

File tree

4 files changed

+20
-2
lines changed

4 files changed

+20
-2
lines changed

ec2_external-dependencies.tfvars

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ enable_eks_deployment = false
44

55
enable_external_dependencies = true
66

7-
s3_bucket_name = "cometml-use2-tftest-dev"
7+
s3_bucket_name = "cometml-use2"

main.tf

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ module "ec2_deployment" {
5454
vpc_id = module.vpc.vpc_id
5555
allinone_ami = "ami-05842f1afbf311a43"
5656
allinone_subnet = module.vpc.public_subnets[count.index % length(module.vpc.public_subnets)]
57+
58+
comet_ml_s3_bucket = var.s3_bucket_name
5759
}
5860

5961
module "eks_deployment" {

modules/ec2_deployment/main.tf

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,17 @@ resource "aws_iam_instance_profile" "comet-ml-s3-access-profile" {
124124
resource "aws_iam_policy" "comet-ml-s3-policy" {
125125
name = "comet-ml-s3-access-policy"
126126
description = "comet-ml-s3-access-policy"
127-
policy = file("${path.module}/templates/s3bucketpolicy.json")
127+
#policy = file("${path.module}/templates/s3bucketpolicy.json")
128+
policy = jsonencode({
129+
"Version": "2012-10-17",
130+
"Statement": [
131+
{
132+
"Effect": "Allow",
133+
"Action": "s3:*",
134+
"Resource":"arn:aws:s3:::${var.comet_ml_s3_bucket}"
135+
}
136+
]
137+
})
128138
}
129139

130140
resource "aws_iam_role_policy_attachment" "comet-ml-s3-access-attachment" {

modules/ec2_deployment/variables.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,4 +50,10 @@ variable "allinone_subnet" {
5050
description = "ID of VPC subnet to launch EC2 instance in"
5151
type = string
5252
default = ""
53+
}
54+
55+
variable "comet_ml_s3_bucket" {
56+
description = "Name of the S3 bucket provisioned for Comet"
57+
type = string
58+
default = null
5359
}

0 commit comments

Comments
 (0)