-
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.
Showing
23 changed files
with
513 additions
and
108 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,3 +33,5 @@ override.tf.json | |
.terraformrc | ||
terraform.rc | ||
.validate | ||
.apply | ||
.plan |
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 |
---|---|---|
@@ -1,11 +1,38 @@ | ||
default: all | ||
|
||
TERRAFORM_ENVIRONMENTS := aws github wildsea | ||
TERRAFORM_ENVIRONMENTS := aws github wildsea aws-dev wildsea-dev | ||
TERRAFOM_VALIDATE := $(addsuffix /.validate,$(addprefix terraform/environment/, $(TERRAFORM_ENVIRONMENTS))) | ||
ACCOUNT_ID := $(shell aws sts get-caller-identity --query 'Account' --output text) | ||
AWS_REGION ?= "ap-southeast-2" | ||
RO_ROLE = arn:aws:iam::$(ACCOUNT_ID):role/GitHubAction-Wildsea-ro-dev | ||
RW_ROLE = arn:aws:iam::$(ACCOUNT_ID):role/GitHubAction-Wildsea-rw-dev | ||
|
||
all: $(TERRAFOM_VALIDATE) | ||
|
||
terraform/environment/%/.validate: terraform/environment/%/*.tf | ||
cd terraform/environment/$* ; terraform fmt | ||
cd terraform/environment/$* ; terraform validate | ||
touch $@ | ||
|
||
.PHONY: dev | ||
dev: terraform/environment/aws-dev/.apply terraform/environment/wildsea-dev/.apply | ||
@true | ||
|
||
terraform/environment/aws-dev/.apply: terraform/environment/aws-dev/*.tf terraform/module/iac-roles/*.tf | ||
./terraform/environment/aws-dev/deploy.sh $(ACCOUNT_ID) dev | ||
touch $@ | ||
|
||
terraform/environment/wildsea-dev/.plan: terraform/environment/wildsea-dev/*.tf terraform/module/wildsea/*.tf terraform/environment/wildsea-dev/.terraform | ||
cd terraform/environment/wildsea-dev ; ../../../scripts/run-as.sh $(RO_ROLE) \ | ||
terraform plan -out=./plan | ||
|
||
terraform/environment/wildsea-dev/.apply: terraform/environment/wildsea-dev/.plan | ||
cd terraform/environment/wildsea-dev ; ../../../scripts/run-as.sh $(RW_ROLE) \ | ||
terraform apply ./plan | ||
touch $@ | ||
|
||
terraform/environment/wildsea-dev/.terraform: terraform/environment/wildsea-dev/*.tf terraform/module/wildsea/*.tf | ||
cd terraform/environment/wildsea-dev ; terraform init \ | ||
-backend-config=bucket=terraform-state-$(ACCOUNT_ID) \ | ||
-backend-config=key=dev/terraform.tfstate \ | ||
-backend-config=region=$(AWS_REGION) |
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 |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#!/bin/bash -eu | ||
|
||
ROLE_ARN=$1 | ||
shift | ||
COMMAND=$@ | ||
|
||
CREDS=$(aws sts assume-role --role-arn "$ROLE_ARN" --role-session-name "terraform-${RANDOM}" --query 'Credentials.[AccessKeyId,SecretAccessKey,SessionToken]' --output text) | ||
|
||
export AWS_ACCESS_KEY_ID="$(echo "${CREDS}" | awk '{print $1}')" | ||
export AWS_SECRET_ACCESS_KEY="$(echo "${CREDS}" | awk '{print $2}')" | ||
export AWS_SESSION_TOKEN="$(echo "${CREDS}" | awk '{print $3}')" | ||
|
||
exec $COMMAND |
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 @@ | ||
../aws/deploy.sh |
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,58 @@ | ||
data "aws_partition" "current" {} | ||
data "aws_caller_identity" "current" {} | ||
data "aws_region" "current" {} | ||
|
||
variable "app_name" { | ||
default = "Wildsea" | ||
} | ||
|
||
variable "action_prefix" { | ||
default = "GitHubAction" | ||
} | ||
|
||
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 | ||
} | ||
} | ||
|
||
locals { | ||
prefix = "${var.app_name}-${var.environment}" | ||
} | ||
|
||
provider "aws" { | ||
default_tags { | ||
tags = { | ||
Application = "${var.app_name}-setup-${var.environment}" | ||
} | ||
} | ||
} | ||
|
||
module "iac-roles" { | ||
source = "../../module/iac-roles" | ||
app_name = var.app_name | ||
environment = var.environment | ||
action_prefix = var.action_prefix | ||
workspace = "none" | ||
repo = var.repo | ||
state_bucket_arn = "arn:${data.aws_partition.current.id}:s3:::${var.state_bucket}" | ||
oidc_type = "AWS" | ||
oidc_arn = data.aws_caller_identity.current.account_id | ||
} |
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
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,32 @@ | ||
variable "saml_metadata_url" { | ||
description = "SAML Metadata URL" | ||
type = string | ||
sensitive = true | ||
default = "" | ||
} | ||
|
||
locals { | ||
app_name = "Wildsea" | ||
prefix = "${local.app_name}-dev" | ||
} | ||
|
||
terraform { | ||
backend "s3" { | ||
// region, bucket and key come from -backend-config | ||
} | ||
} | ||
|
||
provider "aws" { | ||
default_tags { | ||
tags = { | ||
Application = local.prefix | ||
} | ||
} | ||
} | ||
|
||
module "wildsea" { | ||
source = "../../module/wildsea" | ||
|
||
saml_metadata_url = var.saml_metadata_url | ||
prefix = local.prefix | ||
} |
Binary file not shown.
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 |
---|---|---|
@@ -0,0 +1,48 @@ | ||
data "aws_partition" "current" {} | ||
data "aws_caller_identity" "current" {} | ||
data "aws_region" "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 "environment" { | ||
description = "Unique name for the deployment" | ||
type = string | ||
default = "primary" | ||
} | ||
|
||
variable "state_bucket_arn" { | ||
description = "ARN of the state bucket" | ||
type = string | ||
} | ||
|
||
variable "oidc_arn" { | ||
description = "ARN of the OIDC provider" | ||
type = string | ||
} | ||
|
||
variable "oidc_type" { | ||
description = "Type of principal for the OIDC Provider" | ||
type = string | ||
default = "Federated" | ||
} | ||
|
||
locals { | ||
prefix = "${var.app_name}-${var.environment}" | ||
} |
Oops, something went wrong.