@@ -26,6 +26,58 @@ const keyPair = new aws.ec2.KeyPair("worker-key-pair", {
2626 publicKey : sshKey . publicKeyOpenssh ,
2727} , { provider } ) ;
2828
29+ // S3 Bucket for reports
30+ const bucket = new aws . s3 . BucketV2 ( "reports-bucket" , {
31+ bucket : `distributed-job-reports-${ githubUsername } ` ,
32+ forceDestroy : true , // Allow deletion if not empty during cleanup
33+ } , { provider } ) ;
34+
35+ // Enable Public Access Block (disable it to allow public read)
36+ const bucketPublicAccessBlock = new aws . s3 . BucketPublicAccessBlock ( "reports-bucket-pab" , {
37+ bucket : bucket . id ,
38+ blockPublicAcls : false ,
39+ blockPublicPolicy : false ,
40+ ignorePublicAcls : false ,
41+ restrictPublicBuckets : false ,
42+ } , { provider } ) ;
43+
44+ // IAM Role for EC2
45+ const ec2Role = new aws . iam . Role ( "worker-ec2-role" , {
46+ assumeRolePolicy : JSON . stringify ( {
47+ Version : "2012-10-17" ,
48+ Statement : [ {
49+ Action : "sts:AssumeRole" ,
50+ Effect : "Allow" ,
51+ Principal : { Service : "ec2.amazonaws.com" } ,
52+ } ] ,
53+ } ) ,
54+ } , { provider } ) ;
55+
56+ // IAM Policy for S3 access
57+ const s3Policy = new aws . iam . RolePolicy ( "worker-s3-policy" , {
58+ role : ec2Role . id ,
59+ policy : pulumi . all ( [ bucket . arn ] ) . apply ( ( [ arn ] ) => JSON . stringify ( {
60+ Version : "2012-10-17" ,
61+ Statement : [
62+ {
63+ Action : [ "s3:PutObject" , "s3:PutObjectAcl" , "s3:GetObject" ] ,
64+ Effect : "Allow" ,
65+ Resource : [ `${ arn } /*` ] ,
66+ } ,
67+ {
68+ Action : [ "s3:ListBucket" ] ,
69+ Effect : "Allow" ,
70+ Resource : [ arn ] ,
71+ } ,
72+ ] ,
73+ } ) ) ,
74+ } , { provider } ) ;
75+
76+ // Instance Profile
77+ const instanceProfile = new aws . iam . InstanceProfile ( "worker-instance-profile" , {
78+ role : ec2Role . name ,
79+ } , { provider } ) ;
80+
2981// VPC
3082const vpc = new aws . ec2 . Vpc ( "job-queue-vpc" , {
3183 cidrBlock : "10.0.0.0/16" ,
@@ -161,6 +213,7 @@ const ec2Instance = new aws.ec2.Instance("worker-instance", {
161213 vpcSecurityGroupIds : [ sgWorkers . id ] ,
162214 keyName : keyPair . keyName ,
163215 userData : userDataScript ,
216+ iamInstanceProfile : instanceProfile . name ,
164217 associatePublicIpAddress : true ,
165218 rootBlockDevice : {
166219 volumeSize : 20 ,
@@ -174,6 +227,6 @@ const ec2Instance = new aws.ec2.Instance("worker-instance", {
174227export const publicIp = ec2Instance . publicIp ;
175228export const publicDns = ec2Instance . publicDns ;
176229export const ec2InstanceId = ec2Instance . id ;
177- export const reportsBucket = "distributed-job-reports" ;
230+ export const reportsBucket = bucket . id ;
178231export const dockerHubUsernameOut = dockerHubUsername ;
179232export const privateKey = sshKey . privateKeyPem ;
0 commit comments