Skip to content
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ changes to Concourse instance itself. Make sure to export all necessary environm

#### Setting up a pipeline

When setting up our pipelines, we use ecs-infra-user on sdp-dev to be able to interact with our infrastructure on AWS. The credentials for this are stored on
When setting up our pipelines, we use IAM roles to be able to interact with our infrastructure on AWS. The credentials for this are stored on
AWS Secrets Manager so you do not need to set up anything yourself.

To set the pipeline, run the following script:
Expand Down
3 changes: 3 additions & 0 deletions concourse/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ terraform-task: &terraform-task
secrets: ((sdp_((env))_repository_archive_script_secrets))
# kics-scan ignore-line
github_access_token: ((github_access_token))
aws_role_arn: arn:aws:iam::((aws_account_sdp_((env)))):role/sdp-concourse-((env))
env: ((env))
branch: ((branch))
run:
Expand All @@ -76,7 +77,9 @@ terraform-task: &terraform-task
echo "ERROR: Tag '$tag' is not in semantic versioning format (vX.Y.Z)"
exit 1
fi
chmod u+x ./resource-repo/concourse/scripts/assume_role.sh
chmod u+x ./resource-repo/concourse/scripts/terraform_infra.sh
source ./resource-repo/concourse/scripts/assume_role.sh
./resource-repo/concourse/scripts/terraform_infra.sh
timeout: 30m

Expand Down
10 changes: 0 additions & 10 deletions concourse/scripts/terraform_infra.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,6 @@ set -euo pipefail

apk add --no-cache jq

aws_account_id=$(echo "$secrets" | jq -r .aws_account_id)
aws_access_key_id=$(echo "$secrets" | jq -r .aws_access_key_id)
aws_secret_access_key=$(echo "$secrets" | jq -r .aws_secret_access_key)

lambda_name=$(echo "$secrets" | jq -r .lambda_name)
env_name=$(echo "$secrets" | jq -r .env_name)
ecr_repository=$(echo "$secrets" | jq -r .ecr_repository)
Expand All @@ -23,9 +19,6 @@ aws_bucket_name=$(echo "$secrets" | jq -r .aws_bucket_name)
lambda_timeout=$(echo "$secrets" | jq -r .lambda_timeout)
lambda_memory=$(echo "$secrets" | jq -r .lambda_memory)

export AWS_ACCESS_KEY_ID="$aws_access_key_id"
export AWS_SECRET_ACCESS_KEY="$aws_secret_access_key"

# kingfisher:ignore
git config --global url."https://x-access-token:$github_access_token@github.com/".insteadOf "https://github.com/"

Expand All @@ -42,9 +35,6 @@ terraform init -backend-config=env/"${env}"/backend-"${env}".tfbackend -reconfig
# The following terraform-apply may need to change if the environment variables change

terraform apply \
-var "aws_account_id=$aws_account_id" \
-var "aws_access_key_id=$aws_access_key_id" \
-var "aws_secret_access_key=$aws_secret_access_key" \
-var "env_name=$env_name" \
-var "lambda_name=${lambda_name}" \
-var "github_app_client_id=$github_app_client_id" \
Expand Down
1,172 changes: 654 additions & 518 deletions poetry.lock

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions terraform/service/data.tf
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ data "aws_ecr_image" "lambda_image" {
image_tag = var.container_ver
}

data "aws_caller_identity" "current" {}

# Get the ecs infrastructure outputs from the remote state data source
data "terraform_remote_state" "vpc" {
backend = "s3"
Expand Down
14 changes: 8 additions & 6 deletions terraform/service/env/dev/example_tfvars.txt
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
# Do NOT commit the real tfvars file to GitHub
aws_account_id = "99999999999"
aws_access_key_id = "AWSACCCESSKEYID"
aws_secret_access_key = "AWSSECRETASSOCIATEDWITHACCESSKEY"
aws_secret_name = "path-to-pem"
aws_bucket_name = "github-repository-archive-script"
env_name = "sdp-dev"
lambda_name = "github-repository-archive-script"
lambda_version = "v0.0.1"
lambda_arch = "x86_64"
lambda_timeout = 900
lambda_memory = 512
schedule = "cron(0 6 ? * 2 *)"
log_retention_days = 90
github_org = "ONS-Innovation"
github_app_client_id = "123456789"
ecr_repository = "sdp-dev-address-book-lambda"
container_ver = "v1.0.0"
ecr_repository = "sdp-dev-github-repository-archive-script"
container_ver = "v1.0.0"
region = "eu-west-2"
project_tag = "SDP"
team_owner_tag = "Knowledge Exchange Hub"
business_owner_tag = "DST"
18 changes: 18 additions & 0 deletions terraform/service/env/prod/example_tfvars.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Do NOT commit the real tfvars file to GitHub
aws_secret_name = "path-to-pem"
aws_bucket_name = "github-repository-archive-script"
env_name = "sdp-prod"
lambda_name = "github-repository-archive-script"
lambda_arch = "x86_64"
lambda_timeout = 900
lambda_memory = 512
schedule = "cron(0 6 ? * 2 *)"
log_retention_days = 90
github_org = "ONS-Innovation"
github_app_client_id = "123456789"
ecr_repository = "sdp-prod-github-repository-archive-script"
container_ver = "v1.0.0"
region = "eu-west-2"
project_tag = "SDP"
team_owner_tag = "Knowledge Exchange Hub"
business_owner_tag = "DST"
4 changes: 2 additions & 2 deletions terraform/service/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,12 @@ resource "aws_iam_role" "lambda_function_role" {
Action = "sts:AssumeRole"
Effect = "Allow"
Principal = {
AWS = "arn:aws:iam::${var.aws_account_id}:root"
AWS = "arn:aws:iam::${local.aws_account_id}:root"
}
Condition = {
ArnLike = {
"aws:PrincipalArn" = [
"arn:aws:iam::${var.aws_account_id}:role/aws-reserved/sso.amazonaws.com/eu-west-2/AWSReservedSSO_Standard_Administrator_Access_*"
"arn:aws:iam::${local.aws_account_id}:role/aws-reserved/sso.amazonaws.com/eu-west-2/AWSReservedSSO_Standard_Administrator_Access_*"
]
}
}
Expand Down
18 changes: 2 additions & 16 deletions terraform/service/variables.tf
Original file line number Diff line number Diff line change
@@ -1,18 +1,3 @@
variable "aws_account_id" {
description = "AWS Account ID"
type = string
}

variable "aws_access_key_id" {
description = "AWS Access Key ID"
type = string
}

variable "aws_secret_access_key" {
description = "AWS Secret Access Key"
type = string
}

variable "aws_secret_name" {
description = "The path to the AWS Secret Manager resource which contains the Github App .pem file"
type = string
Expand Down Expand Up @@ -113,5 +98,6 @@ variable "business_owner_tag" {
}

locals {
bucket_name = "${var.env_name}-${var.aws_bucket_name}"
bucket_name = "${var.env_name}-${var.aws_bucket_name}"
aws_account_id = data.aws_caller_identity.current.account_id
}
Loading