-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Re-org with a rw and ro environment (#16)
* Re-org with a rw and ro environment * Add ENVIRONMENT variable * Grant s3:HeadObject * Fix S3 permissions * Fix S3 permissions for real * Some linter ignores * Some linter ignores
- Loading branch information
1 parent
ac7a349
commit 516adbc
Showing
14 changed files
with
657 additions
and
89 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,38 +2,43 @@ | |
|
||
Wildsea companion app | ||
|
||
## Repository Setup | ||
## Setup | ||
|
||
To set up a github repository: | ||
* Clone `[email protected]:jarrod-lowe/wildsea.git` and then `cd wildsea` | ||
* Configure git: | ||
|
||
```bash | ||
git config gpg.format ssh | ||
git config user.signingkey ~/.ssh/id_rsa | ||
git config commit.gpgsign true | ||
``` | ||
|
||
* Create an AWS Account for deployment | ||
* Define a profile in your `~/.aws/config` to access it as admin for the initial setup deploys | ||
* Create an S3 bucket `terraform-state-<accountid>` | ||
* Create `terraform/environment/aws/terraform.tfvars` | ||
* Add `workspace = "<your github org>"` to the vars file | ||
* Run `.AWS_PROFILE=<profile> ./terraform/environment/github/aws.sh <aws account id>` | ||
* Log into Codacy, and connect the repo | ||
* Configure the rule to maximum | ||
* Create a branch restriction rule called "main": | ||
* Enforcement: Active | ||
* Target Branches: Include default branch | ||
* Tick Restrict creations | ||
* Tick Restrict deletions | ||
* Tick Require linear history | ||
* Tick Require a pull request before merging | ||
* Require 0 Approvals | ||
* Require review from code owners | ||
* Tick Require status checks to pass | ||
* Tick require branches to be up to date before merging | ||
* Add "Codacy Static Code Analysis" to status checks that are required | ||
* Block force pushes | ||
* TODO: Require code scanning results | ||
* In Codacy, in the repo, go to code patterns, and edit the coding standard: | ||
* Set the languages to: CSS, Go, JSON, Javascript, Markdown, Python, Shell, Terraform, Typescript, XML, YAML | ||
* Select every tool that is: | ||
* NOT client-side | ||
* NOT deprecated | ||
* NOT remark-lint | ||
* Matches one of the above languages | ||
* Log into Github and create a personal access token with the "repo" scope, and 7 days expiry | ||
* Create `terraform/environment/github/terraform.tfvars` | ||
* Add `token = "<the token>"` to the vars file | ||
* Add `workspace = "<your github org>"` to the vars file | ||
* Run `.AWS_PROFILE=<profile> ./terraform/environment/github/deploy.sh <aws account id>` | ||
|
||
* Install <https://github.com/apps/renovate> into the repo | ||
* Under settings, "Set up code scanning" | ||
* Enable everything exeept Dependabot version updates | ||
|
||
To automate: | ||
|
||
* In Github, Under settings, "Set up code scanning" | ||
* Enable everything except Dependabot version updates | ||
* Set up CodeQL to default | ||
* Set the Protection rules to Any/Any | ||
* Create an AWS Account for deployment | ||
* Set up OIDC as per <https://aws.amazon.com/blogs/security/use-iam-roles-to-connect-github-actions-to-actions-in-aws/> | ||
* Restrict it to the repo and branch main | ||
* Add AdministratorAccess, for now, and call it GitHubAccess-Wildsea-main | ||
* Add another role with ReadyOnlyAccess, don't restrict the branch, and call it GitHubAccess-Wildsea | ||
* Add an environment "main" | ||
* Add an Environment Variable in the environment "AWS_ACCOUNT" with the ID of the AWS Account | ||
* Add an Environment Variable in the environment "AWS_REGION" with the AWS Region you want to use | ||
* Add an Environment Variable in the environment "STATE_BUCKET" with the name of the state bucket you created | ||
* Add an Environment Variable in the environment "ENVIRONMENT" with the name of the environment |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
#!/bin/bash -eu | ||
if [ -z "${1:-}" ] ; then | ||
echo >&2 "Usage: $0 <aws-account-id> [environment] [region]" | ||
echo >&2 "Eg: $0 0123456789012" | ||
exit 2 | ||
fi | ||
|
||
DIR="$( dirname "$0" )" | ||
cd "${DIR}" | ||
|
||
ACCOUNT_ID="$1" | ||
ENVIRONMENT="${2:-primary}" | ||
AWS_REGION="${3:-ap-southeast-2}" | ||
STATE_BUCKET="terraform-state-${ACCOUNT_ID}" | ||
|
||
if ! aws help >/dev/null ; then | ||
echo >&2 "Error: aws cli not installed" | ||
exit 3 | ||
fi | ||
|
||
if ! aws sts get-caller-identity >/dev/null ; then | ||
echo >&2 "Error: not logged into AWS" | ||
exit 4 | ||
fi | ||
|
||
if ! aws s3 ls "s3://${STATE_BUCKET}/" >/dev/null ; then | ||
echo >&2 "Error: AWS Role does not have access to the state bucket" | ||
aws sts get-caller-identity | ||
exit 5 | ||
fi | ||
|
||
terraform init \ | ||
-backend-config="bucket=${STATE_BUCKET}" \ | ||
-backend-config="key=${ENVIRONMENT}/aws.tfstate" \ | ||
-backend-config="region=${AWS_REGION}" | ||
|
||
terraform apply \ | ||
-var environment="${ENVIRONMENT}" \ | ||
-var state_bucket="${STATE_BUCKET}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
data "aws_partition" "current" {} | ||
data "aws_caller_identity" "current" {} | ||
|
||
variable "app_name" { | ||
default = "Wildsea" | ||
} | ||
|
||
variable "action_prefix" { | ||
default = "GitHubAction" | ||
} | ||
|
||
variable "workspace" { | ||
description = "Github Organisation name" | ||
type = string | ||
} | ||
|
||
variable "repo" { | ||
description = "Repository name" | ||
type = string | ||
default = "wildsea" | ||
} | ||
|
||
variable "state_bucket" { | ||
description = "State Bucket to use for deploys" | ||
type = string | ||
} | ||
|
||
variable "environment" { | ||
description = "Unique name for the deployment" | ||
type = string | ||
default = "primary" | ||
} | ||
|
||
terraform { | ||
backend "s3" { | ||
// region, bucket and key come from -backend-config | ||
} | ||
} | ||
|
||
provider "aws" { | ||
default_tags { | ||
tags = { | ||
Application = "Wildsea-setup-${var.environment}" | ||
} | ||
} | ||
} |
Oops, something went wrong.