Skip to content

Commit c64b5bf

Browse files
committed
Move sqs policy for webhook to root module
1 parent d920cf2 commit c64b5bf

File tree

7 files changed

+20
-34
lines changed

7 files changed

+20
-34
lines changed

main.tf

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,22 @@ module "webhook" {
3737
lambda_timeout = var.webhook_lambda_timeout
3838
}
3939

40+
resource "aws_iam_policy" "webhook" {
41+
name = "${var.environment}-lambda-webhook-publish-sqs-policy"
42+
description = "Lambda webhook sqs policy"
43+
44+
policy = templatefile("${path.module}/policies/lambda-publish-sqs-policy.json", {
45+
sqs_resource_arn = aws_sqs_queue.queued_builds.arn
46+
})
47+
}
48+
49+
resource "aws_iam_policy_attachment" "webhook" {
50+
name = "${var.environment}-webhook-sqs"
51+
roles = [module.webhook.role.name]
52+
policy_arn = aws_iam_policy.webhook.arn
53+
}
54+
55+
4056
module "runners" {
4157
source = "./modules/runners"
4258

modules/runners/templates/user-data.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#!/bin/bash -e
22
exec > >(tee /var/log/user-data.log | logger -t user-data -s 2>/dev/console) 2>&1
33

4+
${pre_install}
5+
46
yum update -y
57

68
# Install docker
@@ -10,8 +12,6 @@ usermod -a -G docker ec2-user
1012

1113
yum install -y curl jq git
1214

13-
${pre_install}
14-
1515
# Install runner
1616
cd /home/ec2-user
1717
mkdir actions-runner && cd actions-runner

modules/webhook/main.tf

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -104,22 +104,3 @@ resource "aws_iam_policy_attachment" "webhook_logging" {
104104
roles = [aws_iam_role.webhook_lambda.name]
105105
policy_arn = aws_iam_policy.webhook_logging.arn
106106
}
107-
108-
resource "aws_iam_policy" "webhook" {
109-
count = var.create_sqs_publish_policy ? 1 : 0
110-
111-
name = "${var.environment}-lamda-webhook-sqs-publish-policy"
112-
description = "Lambda webhook policy"
113-
114-
policy = templatefile("${path.module}/policies/lambda-webhook.json", {
115-
sqs_resource_arn = var.sqs_build_queue.arn
116-
})
117-
}
118-
119-
resource "aws_iam_policy_attachment" "webhook" {
120-
count = var.create_sqs_publish_policy ? 1 : 0
121-
122-
name = "${var.environment}-webhook"
123-
roles = [aws_iam_role.webhook_lambda.name]
124-
policy_arn = aws_iam_policy.webhook[0].arn
125-
}

modules/webhook/outputs.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@ output "lambda" {
66
value = aws_lambda_function.webhook
77
}
88

9-
output "lambda_role" {
9+
output "role" {
1010
value = aws_iam_role.webhook_lambda
1111
}

outputs.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,6 @@ output "webhook" {
1818
value = {
1919
gateway = module.webhook.gateway
2020
lambda = module.webhook.lambda
21-
lambda_role = module.webhook.lambda_role
21+
lambda_role = module.webhook.role
2222
}
2323
}

policies/action-runner-s3-policy.json

Lines changed: 0 additions & 11 deletions
This file was deleted.

0 commit comments

Comments
 (0)