Procházet zdrojové kódy

Clean up old files

Brad Poulton před 4 roky
rodič
revize
14938cf7dd

+ 15 - 0
base/codebuild_artifact/README.md

@@ -0,0 +1,15 @@
+# How to Use this Module
+
+This module is where the CodeBuild artifacts are created. It uses the Terraform GitHub Provider and requires a Personal Access Token. This should be your Personal Access Token not mdr-aws-codebuild's token. The provider will look in the environmental variables for the token. 
+
+```
+export GITHUB_TOKEN=<gihub_token>
+```
+
+This module should NOT create the github repo. That is a manual process. I am not comfortable with terraform adding/removing github repos. The github repo should have the same name as the name variable in the terrafgrunt.hcl file. The user associated with the Personal Access Token needs to have admin permissions on the github repo. 
+
+## Github Service Account ( mdr-aws-codebuild )
+
+AWS CodeBuild needs a Github Personal Access Token to pull code after the code in a repository has been updated. Terraform is capable of storing the Github Personal Access Token, but that is a bad idea. A better idea is a service account in Github that gives CodeBuild access to specific repositories. This user will need access to repositories in different organizations. The login credentials as well as the Personal Access Token for mdr-aws-codebuild are stored in Vault. 
+
+The service account (mdr-aws-codebuild) needs to have a personal access token manually placed into the aws console. 

+ 56 - 0
base/codebuild_artifact/main.tf

@@ -0,0 +1,56 @@
+data "github_repository" "this" {
+    name    = var.name
+}
+
+resource "aws_codebuild_project" "this" {
+  count                 = var.artifact_s3_bucket=="" ? 0 : 1
+
+  name                  = var.name
+  description           = "Project for ${var.name}"
+  service_role          = var.service_role
+  encryption_key        = var.kms_key
+  badge_enabled         = var.badge_enabled
+
+  source {
+    type                = "GITHUB_ENTERPRISE"
+    location            = data.github_repository.this.http_clone_url
+    report_build_status = true
+  }
+
+  environment {
+    compute_type        = "BUILD_GENERAL1_SMALL"
+    image               = var.codebuild_image
+    type                = "LINUX_CONTAINER"
+  }
+
+  artifacts {
+    type                = "S3"
+    location            = var.artifact_s3_bucket
+    name                = "/"
+    path                = var.name
+    namespace_type      = "BUILD_ID"
+    packaging           = "NONE"
+  }
+
+  tags = merge(var.standard_tags, var.tags)
+}
+
+resource "aws_codebuild_webhook" "this" {
+  project_name  = var.name
+  branch_filter = var.webhook_branch_filter
+
+  depends_on = [ aws_codebuild_project.this  ]
+}
+
+resource "github_repository_webhook" "this" {
+  active     = true
+  events     = ["push"]
+  repository = data.github_repository.this.name
+
+  configuration {
+    url          = aws_codebuild_webhook.this.payload_url
+    secret       = aws_codebuild_webhook.this.secret
+    content_type = "json"
+    insecure_ssl = false
+  }
+}

+ 29 - 0
base/codebuild_artifact/vars.tf

@@ -0,0 +1,29 @@
+variable "tags" {
+  description = "Tags to add to the resource (in addition to global standard tags)"
+  type        = map
+  default     = { }
+}
+variable "standard_tags" { type = map }
+variable "environment" { type = string }
+variable "aws_partition" { type = string }
+variable "aws_partition_alias" { type = string }
+variable "aws_account_id" { type = string }
+variable "name" { type = string }
+variable "service_role" { type = string }
+variable "artifact_s3_bucket" { type = string }
+variable "codebuild_image" {type = string }
+
+variable "kms_key" {
+    type = string
+    default = ""
+}
+
+variable "badge_enabled" {
+    type = string
+    default = "false"
+}
+
+variable "webhook_branch_filter" {
+    type = string
+    default = "^(master|develop)$"
+}

+ 0 - 9
base/codebuild_ecr_project/aws-efs-utils.tf

@@ -1,9 +0,0 @@
-# module "aws-efs-utils" {
-#     source             = "../modules/codebuild_plus_repo"
-#     name               = "aws-efs-utils"
-#     description        = "EFS utilities RPM"
-#     service_role       = "${data.aws_iam_role.codebuild_role.arn}"
-#     kms_key            = "${aws_kms_key.s3_codebuild_artifacts.arn}"
-#     codebuild_image    = "${aws_ecr_repository.codebuild-rhel7.repository_url}"
-#     artifact_s3_bucket = "${aws_s3_bucket.artifacts.id}"
-# }

+ 0 - 31
base/codebuild_ecr_project/collectd-project.tf

@@ -1,31 +0,0 @@
-# resource "aws_codecommit_repository" "collectd-rpm" {
-#   repository_name = "collectd-rpm"
-#   description     = "MDR collectd RPMs based on EPEL spec file"
-# }
-
-# resource "aws_codebuild_project" "collectd-rpm" {
-#   name           = "collectd-rpm"
-#   description    = "MDR collects RPMs based on EPEL spec file"
-#   service_role   = "${data.aws_iam_role.codebuild_role.arn}"
-#   encryption_key = "${aws_kms_key.s3_codebuild_artifacts.arn}"
-
-#   source {
-#     type            = "CODECOMMIT"
-#     location        = "${aws_codecommit_repository.collectd-rpm.clone_url_http}"
-#   }
-
-#   artifacts {
-#     type           = "S3"
-#     location       = "${aws_s3_bucket.artifacts.id}"
-#     name           = "/"
-#     path           = "collectd"
-#     namespace_type = "BUILD_ID"
-#     packaging      = "NONE"
-#   }
-
-#   environment {
-#     compute_type = "BUILD_GENERAL1_SMALL"
-#     image        = "${aws_ecr_repository.codebuild-rhel7.repository_url}"
-#     type         = "LINUX_CONTAINER"
-#   }
-# }

+ 0 - 69
base/codebuild_ecr_project/ecr.tf

@@ -1,69 +0,0 @@
-# #ecr.tf is for the basic building blocks for ECR. Not for individual images.
-# # individual images are in separate files 
-# # with the naming scheme project-container.tf 
-
-# #TODO: add codebuild image for codebuild to use when building images
-# # centos7 - customer portal
-# # rhel - syslog-ng
-
-# #Base RHEL repository used for building XDR images like syslog-ng in CodeBuild
-# resource "aws_ecr_repository" "codebuild-rhel7" {
-#   name  = "codebuild-rhel7"
-#   tags = merge(var.standard_tags, var.tags)
-# }
-
-# #Allow codebuild to access the ECR Repository
-# resource "aws_ecr_repository_policy" "codebuild-rhel7" {
-#   repository = aws_ecr_repository.codebuild-rhel7.name
-
-#   policy = <<EOF
-# {
-#     "Version": "2008-10-17",
-#     "Statement": [
-#         {
-#             "Sid": "new statement",
-#             "Effect": "Allow",
-#             "Principal": {
-#                 "Service": "codebuild.amazonaws.com"
-#             },
-#             "Action": [
-#                 "ecr:GetDownloadUrlForLayer",
-#                 "ecr:BatchGetImage",
-#                 "ecr:BatchCheckLayerAvailability"
-#             ]
-#         }
-#     ]
-# }
-# EOF
-# }
-
-# #base centos7 image used for building portal
-# resource "aws_ecr_repository" "codebuild-centos7" {
-#   name     = "codebuild-centos7"
-#   tags = merge(var.standard_tags, var.tags)
-# }
-
-# #Allow codebuild to access the ECR Repository
-# resource "aws_ecr_repository_policy" "codebuild-centos7" {
-#   repository = aws_ecr_repository.codebuild-centos7.name
-
-#   policy = <<EOF
-# {
-#     "Version": "2008-10-17",
-#     "Statement": [
-#         {
-#             "Sid": "new statement",
-#             "Effect": "Allow",
-#             "Principal": {
-#                 "Service": "codebuild.amazonaws.com"
-#             },
-#             "Action": [
-#                 "ecr:GetDownloadUrlForLayer",
-#                 "ecr:BatchGetImage",
-#                 "ecr:BatchCheckLayerAvailability"
-#             ]
-#         }
-#     ]
-# }
-# EOF
-# }

+ 0 - 57
base/codebuild_ecr_project/ecr_pop_user.tf

@@ -1,57 +0,0 @@
-# Defines an IAM user that can only download ECR images, intended for
-# use in POP nodes where we need containers, but won't necessarily have
-# EC2 instance role credentials.  Maybe one day this goes to vault, I
-# hope.   It would be nice.
-
-# data "aws_iam_policy_document" "ecr_policy_pop" {
-#   statement {
-#     sid       = "AllowECRReadOnly"
-#     effect    = "Allow"
-
-#     actions   = [
-#       "ecr:GetAuthorizationToken",
-#       "ecr:BatchCheckLayerAvailability",
-#       "ecr:GetDownloadUrlForLayer",
-#       "ecr:GetRepositoryPolicy",
-#       "ecr:DescribeRepositories",
-#       "ecr:ListImages",
-#       "ecr:DescribeImages",
-#       "ecr:BatchGetImage"
-#     ]
-    
-#     resources = [
-#       "*"
-#     ]
-
-#   }
-# }
-
-# resource "aws_iam_policy" "ecr_policy_pop" {
-#   name   = "ecr_policy_pop"
-#   path   = "/"
-#   policy = "${data.aws_iam_policy_document.ecr_policy_pop.json}"
-# }
-
-# resource "aws_iam_user" "pop_service_account" {
-#   name = "svc-mdrpop"
-#   path = "/service/"
-# }
-
-# resource "aws_iam_user_policy_attachment" "pop_service_account_1" {
-#   user       = "${aws_iam_user.pop_service_account.name}"
-#   policy_arn = "${aws_iam_policy.ecr_policy_pop.arn}"
-# }
-
-
-# resource "aws_iam_access_key" "pop_service_account" {
-#   user    = "${aws_iam_user.pop_service_account.name}"
-#   pgp_key = "${file("../00-organizations-and-iam/duane_waddle.pgp")}"
-# }
-
-# output "pop_service_account_key_id" {
-#   value = "${aws_iam_access_key.pop_service_account.id}"
-# }
-
-# output "pop_service_account_secret" {
-#   value = "${aws_iam_access_key.pop_service_account.encrypted_secret}"
-# }

+ 0 - 23
base/codebuild_ecr_project/github-webhooks.tf

@@ -1,23 +0,0 @@
-# provider "github" { 
-#   base_url     = "https://github.mdr.defpoint.com/api/v3/"
-#   version = "~> 4.1.0"
-#   organization = "mdr-engineering"
-# }
-
-# data "github_repository" "syslog-ng-container" {
-#   full_name = "mdr-engineering/mdr-syslog-ng-container"
-# }
-
-# resource "github_repository_webhook" "syslog-ng-container" {
-#   active     = true
-#   events     = ["push"]
-#   repository = "${data.github_repository.syslog-ng-container.name}"
-
-#   configuration {
-#     url          = "${aws_codebuild_webhook.syslog-ng-container.payload_url}"
-#     secret       = "${aws_codebuild_webhook.syslog-ng-container.secret}"
-#     content_type = "json"
-#     insecure_ssl = false
-#   }
-# }
-

+ 0 - 101
base/codebuild_ecr_project/iam.tf

@@ -1,101 +0,0 @@
-# resource "aws_iam_role" "codebuild_role" {
-#   name     = "codebuild_role"
-
-#   assume_role_policy = <<EOF
-# {
-#     "Version": "2012-10-17",
-#     "Statement": [
-#       {
-#         "Effect": "Allow",
-#         "Principal": {
-#           "Service": [
-#             "codebuild.amazonaws.com"
-#             ]
-#         },
-#         "Action": "sts:AssumeRole"
-#       }
-#     ]
-#   }
-# EOF
-# }
-
-# resource "aws_iam_role_policy_attachment" "codebuild_role_policy_attach" {
-#   role       = aws_iam_role.codebuild_role.name
-#   policy_arn = aws_iam_policy.codebuild_policy.arn
-# }
-
-# # Some things about this policy I'm not perfectly sure about, like
-# # should the account number be hardcoded?  Also, it reads like we'll have to
-# # update it each time we have a new repository added to codecommit - that
-# # or we'll need to authorize the codebuild role to be able to pull from any 
-# # codecommit repo.  Which may be fine?
-# resource "aws_iam_policy" "codebuild_policy" {
-#   name        = "codebuild_policy"
-#   description = "Policy for AWS codebuild to build and store artifacts"
-
-#   policy = <<EOF
-# {
-#     "Version": "2012-10-17",
-#     "Statement": [
-#         {
-#             "Effect": "Allow",
-#             "Resource": [
-#                 "arn:aws-us-gov:logs:us-gov-east-1:701290387780:log-group:/aws/codebuild/*"
-#             ],
-#             "Action": [
-#                 "logs:CreateLogGroup",
-#                 "logs:CreateLogStream",
-#                 "logs:PutLogEvents"
-#             ]
-#         },
-#         {
-#             "Effect": "Allow",
-#             "Resource": [
-#                 "arn:aws-us-gov:s3:::codepipeline-us-gov-east-1-*"
-#             ],
-#             "Action": [
-#                 "s3:PutObject",
-#                 "s3:GetObject",
-#                 "s3:GetObjectVersion"
-#             ]
-#         },
-#         {
-#             "Effect": "Allow",
-#             "Resource": [
-#                 "arn:aws-us-gov:codecommit:us-gov-east-1:701290387780:*"
-#             ],
-#             "Action": [
-#                 "codecommit:GitPull"
-#             ]
-#         },
-#         {
-#             "Effect": "Allow",
-#             "Resource": [
-#                 "arn:aws-us-gov:s3:::xdr-codebuild-artifacts/*",
-#                 "arn:aws-us-gov:s3:::*"
-#             ],
-#             "Action": [
-#                 "s3:PutObject",
-#                 "s3:GetObject*",
-#                 "s3:ListBucket"
-#             ]
-#         },
-#         {
-#             "Effect": "Allow",
-#             "Resource": [
-#                 "*"
-#             ],
-#             "Action": [
-#               "ecr:GetAuthorizationToken",
-#               "ecr:BatchCheckLayerAvailability",
-#               "ecr:CompleteLayerUpload",
-#               "ecr:GetAuthorizationToken",
-#               "ecr:InitiateLayerUpload",
-#               "ecr:PutImage",
-#               "ecr:UploadLayerPart"
-#             ]
-#         }
-#     ]
-# }
-# EOF
-# }

+ 1 - 34
base/codebuild_ecr_project/main.tf

@@ -2,39 +2,6 @@ data "github_repository" "this" {
     name    = var.name
 }
 
-resource "aws_codebuild_project" "this" {
-  count                 = var.artifact_s3_bucket=="" ? 0 : 1
-
-  name                  = var.name
-  description           = "Project for ${var.name}"
-  service_role          = var.service_role
-  encryption_key        = var.kms_key
-  badge_enabled         = var.badge_enabled
-
-  source {
-    type                = "GITHUB_ENTERPRISE"
-    location            = data.github_repository.this.http_clone_url
-    report_build_status = true
-  }
-
-  environment {
-    compute_type        = "BUILD_GENERAL1_SMALL"
-    image               = var.codebuild_image
-    type                = "LINUX_CONTAINER"
-  }
-
-  artifacts {
-    type                = "S3"
-    location            = var.artifact_s3_bucket
-    name                = "/"
-    path                = var.name
-    namespace_type      = "BUILD_ID"
-    packaging           = "NONE"
-  }
-
-  tags = merge(var.standard_tags, var.tags)
-}
-
 resource "aws_codebuild_project" "this_no_artifact" {
   count                 = var.artifact_s3_bucket=="" ? 1 : 0
 
@@ -111,7 +78,7 @@ resource "aws_codebuild_webhook" "this" {
   project_name  = var.name
   branch_filter = var.webhook_branch_filter
 
-  depends_on = [ aws_codebuild_project.this_no_artifact, aws_codebuild_project.this  ]
+  depends_on = [ aws_codebuild_project.this_no_artifact ]
 }
 
 resource "github_repository_webhook" "this" {

+ 0 - 10
base/codebuild_ecr_project/portal_container.tf

@@ -1,10 +0,0 @@
-# module "portal-container" {
-#     source             = "../../submodules/codebuild/pipeline"
-#     name               = "customer_portal"
-#     github_org         = "MDR-Content"
-#     description        = "Container for Customer Portal"
-#     service_role       = aws_iam_role.codebuild_role.arn
-#     kms_key            = aws_kms_key.s3_codebuild_artifacts.arn
-#     codebuild_image    = aws_ecr_repository.codebuild-rhel7.repository_url
-#     artifact_s3_bucket = ""
-# }

+ 0 - 11
base/codebuild_ecr_project/stunnel.tf

@@ -1,11 +0,0 @@
-# module "stunnel" {
-#     source             = "../modules/codebuild_plus_repo"
-#     name               = "stunnel"
-#     description        = "stunnel is an open source TLS tunnel"
-#     service_role       = "${data.aws_iam_role.codebuild_role.arn}"
-#     kms_key            = "${aws_kms_key.s3_codebuild_artifacts.arn}"
-#     codebuild_image    = "${aws_ecr_repository.codebuild-rhel7.repository_url}"
-#     artifact_s3_bucket = "${aws_s3_bucket.artifacts.id}"
-
-
-# }

+ 0 - 31
base/codebuild_ecr_project/tmux-project.tf

@@ -1,31 +0,0 @@
-# resource "aws_codecommit_repository" "tmux-rpm" {
-#   repository_name = "tmux-rpm"
-#   description     = "MDR tmux RPMs based on RHEL spec file"
-# }
-
-# resource "aws_codebuild_project" "tmux-rpm" {
-#   name           = "tmux-rpm"
-#   description    = "MDR collects RPMs based on EPEL spec file"
-#   service_role   = "${data.aws_iam_role.codebuild_role.arn}"
-#   encryption_key = "${aws_kms_key.s3_codebuild_artifacts.arn}"
-
-#   source {
-#     type            = "CODECOMMIT"
-#     location        = "${aws_codecommit_repository.tmux-rpm.clone_url_http}"
-#   }
-
-#   artifacts {
-#     type           = "S3"
-#     location       = "${aws_s3_bucket.artifacts.id}"
-#     name           = "/"
-#     path           = "tmux"
-#     namespace_type = "BUILD_ID"
-#     packaging      = "NONE"
-#   }
-
-#   environment {
-#     compute_type = "BUILD_GENERAL1_SMALL"
-#     image        = "${aws_ecr_repository.codebuild-rhel7.repository_url}"
-#     type         = "LINUX_CONTAINER"
-#   }
-# }

+ 0 - 9
base/codebuild_ecr_project/xdr-unbound-container.tf

@@ -1,9 +0,0 @@
-# module "xdr-container-unbound" {
-#     source             = "../modules/codebuild_plus_repo"
-#     name               = "xdr-container-unbound"
-#     description        = "Container for Unbound DNS"
-#     service_role       = "${data.aws_iam_role.codebuild_role.arn}"
-#     kms_key            = "${aws_kms_key.s3_codebuild_artifacts.arn}"
-#     codebuild_image    = "${aws_ecr_repository.codebuild-rhel7.repository_url}"
-#     artifact_s3_bucket = ""
-# }