Skip to content

Cancelled my codepipeline #26

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 31, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
226 changes: 114 additions & 112 deletions codepipeline.tf
Original file line number Diff line number Diff line change
@@ -1,114 +1,116 @@
resource "aws_codepipeline" "codepipeline" {
name = "blog-website-deploy-s3"
role_arn = aws_iam_role.codepipeline_role.arn
# Note: I will attempt to return to this after I have learned more about CI/CD with Terraform

# resource "aws_codepipeline" "codepipeline" {
# name = "blog-website-deploy-s3"
# role_arn = aws_iam_role.codepipeline_role.arn


artifact_store {
location = aws_s3_bucket.codepipeline_bucket.bucket
type = "S3"
region = "us-east-2"
}

stage {
name = "Source"
action {
name = "Source"
category = "Source"
owner = "ThirdParty"
provider = "GitHub"
version = "2"
output_artifacts = ["source_output"]
region = "us-east-2"

configuration = {
ConnectionArn = aws_codestarconnections_connection.gitrepo-to-aws.arn
FullRepositoryId = "RavenEsc/frontend-developer"
BranchName = "master"
}
}
}

stage {
name = "Deploy"
action {
name = "Deploy"
category = "Deploy"
owner = "AWS"
provider = "s3"
input_artifacts = ["source_output"]
version = "1"
region = "us-east-2"
configuration = {
BucketName = aws_s3_bucket.buck.bucket
Extract = true
}
}
}
}

resource "aws_iam_role_policy" "codepipeline_policy" {
name = "codepipeline_policy"
role = aws_iam_role.codepipeline_role.id
policy = data.aws_iam_policy_document.codepipeline_policy.json
}
resource "aws_iam_role" "codepipeline_role" {
name = "deploy-GitHub-role"
assume_role_policy = data.aws_iam_policy_document.assume_role.json
}

data "aws_iam_policy_document" "assume_role" {
statement {
effect = "Allow"

principals {
type = "Service"
identifiers = ["codepipeline.amazonaws.com"]
}

actions = ["sts:AssumeRole"]
}
}

data "aws_iam_policy_document" "codepipeline_policy" {
statement {
effect = "Allow"

actions = [
"s3:GetObject",
"s3:GetObjectVersion",
"s3:GetBucketVersioning",
"s3:PutObjectAcl",
"s3:PutObject",
]

resources = [
aws_s3_bucket.codepipeline_bucket.arn,
"${aws_s3_bucket.codepipeline_bucket.arn}/*"
]
}

statement {
effect = "Allow"
actions = ["codestar-connections:UseConnection"]
resources = [aws_codestarconnections_connection.gitrepo-to-aws.arn]
}

}

resource "aws_s3_bucket" "codepipeline_bucket" {
bucket = "cp-blog-artifact-bucket"
}

resource "aws_s3_bucket_public_access_block" "codepipeline_bucket_pab" {
bucket = aws_s3_bucket.codepipeline_bucket.id

block_public_acls = true
block_public_policy = true
ignore_public_acls = true
restrict_public_buckets = true
}

resource "aws_codestarconnections_connection" "gitrepo-to-aws" {
name = "blog-web-dev-connection"
provider_type = "GitHub"
}
# artifact_store {
# location = aws_s3_bucket.codepipeline_bucket.bucket
# type = "S3"
# region = "us-east-2"
# }

# stage {
# name = "Source"
# action {
# name = "Source"
# category = "Source"
# owner = "ThirdParty"
# provider = "GitHub"
# version = "2"
# output_artifacts = ["source_output"]
# region = "us-east-2"

# configuration = {
# ConnectionArn = aws_codestarconnections_connection.gitrepo-to-aws.arn
# FullRepositoryId = "RavenEsc/frontend-developer"
# BranchName = "master"
# }
# }
# }

# stage {
# name = "Deploy"
# action {
# name = "Deploy"
# category = "Deploy"
# owner = "AWS"
# provider = "s3"
# input_artifacts = ["source_output"]
# version = "1"
# region = "us-east-2"
# configuration = {
# BucketName = aws_s3_bucket.buck.bucket
# Extract = true
# }
# }
# }
# }

# resource "aws_iam_role_policy" "codepipeline_policy" {
# name = "codepipeline_policy"
# role = aws_iam_role.codepipeline_role.id
# policy = data.aws_iam_policy_document.codepipeline_policy.json
# }
# resource "aws_iam_role" "codepipeline_role" {
# name = "deploy-GitHub-role"
# assume_role_policy = data.aws_iam_policy_document.assume_role.json
# }

# data "aws_iam_policy_document" "assume_role" {
# statement {
# effect = "Allow"

# principals {
# type = "Service"
# identifiers = ["codepipeline.amazonaws.com"]
# }

# actions = ["sts:AssumeRole"]
# }
# }

# data "aws_iam_policy_document" "codepipeline_policy" {
# statement {
# effect = "Allow"

# actions = [
# "s3:GetObject",
# "s3:GetObjectVersion",
# "s3:GetBucketVersioning",
# "s3:PutObjectAcl",
# "s3:PutObject",
# ]

# resources = [
# aws_s3_bucket.codepipeline_bucket.arn,
# "${aws_s3_bucket.codepipeline_bucket.arn}/*"
# ]
# }

# statement {
# effect = "Allow"
# actions = ["codestar-connections:UseConnection"]
# resources = [aws_codestarconnections_connection.gitrepo-to-aws.arn]
# }

# }

# resource "aws_s3_bucket" "codepipeline_bucket" {
# bucket = "cp-blog-artifact-bucket"
# }

# resource "aws_s3_bucket_public_access_block" "codepipeline_bucket_pab" {
# bucket = aws_s3_bucket.codepipeline_bucket.id

# block_public_acls = true
# block_public_policy = true
# ignore_public_acls = true
# restrict_public_buckets = true
# }

# resource "aws_codestarconnections_connection" "gitrepo-to-aws" {
# name = "blog-web-dev-connection"
# provider_type = "GitHub"
# }