This guideline provides step-by-step instructions to create, update, and destroy the AWS infrastructure that hosts the services of the Data Marketplace platform.
There are multiple environments:
gen
– Shared/general environment for common resources (must be deployed first)dev
– Development environmenttst
– Test environmentstg
– Staging/Pre-production environmentpro
– Production environment
dev
andtst
are deployed in the development AWS account.
stg
andpro
are deployed in the production AWS account.
In this version, the deployment is managed via:
- A deployment server (an EC2 instance)
- Terraform
- GitHub Actions workflows
A fully automated proper CI/CD pipeline will be introduced in future versions.
-
General Environment Setup (gen):
- Run the deployment for the
gen
environment manually on AWS (using CloudShell or EC2). - This deploys shared resources (S3 buckets, IAM roles, Secrets, Parameter Store entries) and a private subnet in the default VPC.
- Run the deployment for the
-
Deployment Server Setup:
- Use Amazon Linux 2023 EC2 instance, placed in the private subnet of the default VPC.
- Attach the IAM role
dm-gen-ec2-profile-role
(soon to be renamed todm-gen-ec2-profile-deployment-role
). - Connect to the instance via SSM Session Manager.
- Install the following tools:
- AWS CLI: Install Guide
- Git: Install Guide
- Terraform v1.5.7: Install Guide
- kubectl: Install Guide
-
Additional Requirements:
- GitHub Actions IAM role defined in AWS.
- A domain or subdomain name for each environment (e.g.
dev.datamarketplace.gov.uk
). - TLS Certificate for the domain.
- SSO configuration on
security.gov.uk
.
Environment deployment is handled via GitHub Actions pipeline:
Input Parameters:
- Branch Name – Select the relevant Git branch
- Environment Name – Choose from:
dev
,tst
,stg
,pro
- MSSQL Snapshot Name
- PostgreSQL Snapshot Name
- Action Type:
init+plan
: Runsterraform plan
and shows proposed changes.init+plan+apply
: Runs plan, requests manual approval, then applies if approved.approval+destroy
: Runsterraform destroy
after manual approval.
- Terraform plan runs and shows changes.
- An issue is created for manual approval.
- Enter Approve or Deny in the issue.
- If Approved, the environment is created.
- If Denied, the pipeline cancels.
This will be automated in the future.
Steps:
- Ensure all required config entries exist in AWS Parameter Store at
/dm/gen/config-inputs
. - On the Deployment Server:
This script sets up app-specific parameters in Parameter Store.
git clone [this repository] cd data-marketplace-infrastructure/app-fast/ ./config/config.sh [env] # e.g., ./config/config.sh dev
This will also be automated later.
Steps:
- Complete Application Parameters Setup.
- On the Deployment Server:
cd data-marketplace-infrastructure/app-fast/ # Create and edit .env file with deployment settings sh dm-deploy.sh install # for installation sh dm-deploy.sh update # for updating sh dm-deploy.sh uninstall # for removal
- Please create a
.env
file with deployment settings in advance via using the template provided.env_template
- Please upload the newly created
.env
file to S3 Bucket
(the name of the bucket can be obtained from Pipeline filedata-marketplace-infrastructure/.github/workflows/application-configuration-update.yml
) - Then you can run GitHub Workflows pipeline of
application-configuration-update.yml
via UI or GitHub API
These will eventually be automated.
- Create or update DNS entry for the environment.
- Create or update WAF associated with the ALB created by the application deployment.
- Always update DNS CNAME when the ALB changes.
To completely delete an environment (e.g., dev
):
-
DNS Cleanup:
- Delete the CNAME record for the environment.
- Wait for DNS propagation (~15–30 mins).
-
WAF Removal:
- Remove the WAF linked to the ALB.
-
Application Uninstall:
sh dm-deploy.sh uninstall
-
Environment Destruction via Pipeline:
- Run
approval+destroy
option in the GitHub Actions workflow. - Approve the destruction in the created issue.
- Run
- On the Deployment Server:
cd app-fast/ cp dev.env .env # adjust as needed sh dm-deploy.sh update
- If the ALB is changed then update WAF and the CNAME accordingly.
⚠️ These may cause a temporary service outage. Application pods in the Kubernetes cluster might be restarted.