Skip to content

Commit e141866

Browse files
AirhisAirhis
Airhis
authored and
Airhis
committed
updated iam_policy for the codepipeline
1 parent fb8d044 commit e141866

File tree

5 files changed

+54
-10
lines changed

5 files changed

+54
-10
lines changed

examples/complete/main.tf

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ module "codepipeline" {
2424
#create_s3_source = var.create_s3_source
2525
#source_s3_bucket = var.a
2626
artifact_bucket_name = var.artifact_bucket_name
27-
stages = var.stages
28-
pipeline_type = var.pipeline_type
29-
execution_mode = var.execution_mode
27+
stages = var.stages
28+
pipeline_type = var.pipeline_type
29+
execution_mode = var.execution_mode
3030

3131
tags = var.tags
3232
}

examples/complete/variables.tf

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ variable "stages" {
3131
description = "One or more stage blocks."
3232
type = any
3333
}
34-
3534
variable "pipeline_type" {
3635
description = "The CodePipeline pipeline_type. Valid options are V1, V2"
3736
type = string
@@ -51,7 +50,7 @@ variable "execution_mode" {
5150

5251
variable "artifact_bucket_name" {
5352
description = "the name of the S3 bucket used for storing the artifacts in the Codepipeline"
54-
type = string
53+
type = string
5554
}
5655

5756
variable "tags" {

locals.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ locals {
1414
default_tags = {
1515
provisioner = "Terraform"
1616
}
17-
#account_id = data.aws_caller_identity.current.account_id
17+
account_id = data.aws_caller_identity.current.account_id
1818
#bucket_prefix = length(var.log_target_prefix) == 0 ? "AWSLogs/${local.account_id}/s3audit" : var.log_target_prefix
1919

2020
tags = merge(local.default_tags, var.tags)

main.tf

Lines changed: 49 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,11 @@
1010
// See the License for the specific language governing permissions and
1111
// limitations under the License.
1212

13-
#data "aws_caller_identity" "current" {}
13+
data "aws_caller_identity" "current" {}
14+
15+
data "aws_s3_bucket" "artifact_bucket" {
16+
bucket = var.artifact_bucket_name
17+
}
1418

1519
resource "aws_codepipeline" "this" {
1620
name = var.name
@@ -26,7 +30,7 @@ resource "aws_codepipeline" "this" {
2630
}]
2731

2832
content {
29-
location = var.artifact_bucket_name
33+
location = data.aws_s3_bucket.artifact_bucket.bucket
3034
type = "S3"
3135

3236
dynamic "encryption_key" {
@@ -90,8 +94,50 @@ resource "aws_iam_role" "codepipeline_role" {
9094
assume_role_policy = data.aws_iam_policy_document.assume_role.json
9195
}
9296

97+
data "aws_iam_policy_document" "codepipeline_policy" {
98+
99+
# Eventbridge trigger
100+
statement {
101+
effect = "Allow"
102+
actions = [
103+
"cloudwatch:*",
104+
"sns:*",
105+
"sqs:*"
106+
]
107+
resources = ["*"]
108+
}
109+
110+
# Start any stage CodeBuild projects
111+
statement {
112+
effect = "Allow"
113+
actions = [
114+
"codebuild:BatchGetBuilds",
115+
"codebuild:StartBuild",
116+
"codebuild:BatchGetBuildBatches",
117+
"codebuild:StartBuildBatch"
118+
]
119+
resources = ["*"]
120+
}
121+
122+
statement {
123+
effect = "Allow"
124+
actions = [
125+
"s3:*"
126+
]
127+
resources = [
128+
data.aws_s3_bucket.artifact_bucket.arn,
129+
"${data.aws_s3_bucket.artifact_bucket.arn}/*",
130+
]
131+
}
132+
}
93133
resource "aws_iam_role_policy" "codepipeline_policy" {
94134
name = "codepipeline_policy"
95135
role = aws_iam_role.codepipeline_role.id
96-
policy = data.aws_iam_policy_document.assume_role.json
136+
policy = data.aws_iam_policy_document.codepipeline_policy.json
137+
}
138+
139+
resource "random_string" "random" {
140+
length = 10
141+
special = false
142+
upper = false
97143
}

variables.tf

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ variable "stages" {
2929
description = "One or more stage blocks."
3030
type = any
3131
}
32-
3332
# variable "codepipeline_iam" {
3433
# description = "Additional IAM actions to add to CodePipeline IAM role."
3534
# type = map(list(string))

0 commit comments

Comments
 (0)