generated from ministryofjustice/cloud-platform-terraform-template
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #309 from ministryofjustice/308-add-database-basti…
…on-for-service Add database bastion for service
- Loading branch information
Showing
9 changed files
with
113 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
module "rds_servers_bastion_label" { | ||
source = "./modules/label" | ||
service_name = "rds-servers-bastion" | ||
owner_email = var.owner_email | ||
} | ||
|
||
module "rds_servers_bastion" { | ||
source = "./modules/bastion" | ||
prefix = module.rds_servers_bastion_label.id | ||
vpc_id = module.servers_vpc.vpc.vpc_id | ||
vpc_cidr_block = module.servers_vpc.vpc.vpc_cidr_block | ||
private_subnets = module.servers_vpc.public_subnets | ||
security_group_ids = [module.dhcp.security_group_ids.dhcp_server] | ||
ami_name = "diso-devops/bastion/rds-admin/ubuntu-jammy-22.04-amd64-server-1.0.1" | ||
number_of_bastions = 1 | ||
assume_role = local.s3-mojo_file_transfer_assume_role_arn | ||
associate_public_ip_address = true | ||
tags = module.rds_servers_bastion_label.tags | ||
|
||
providers = { | ||
aws = aws.env | ||
} | ||
|
||
depends_on = [module.servers_vpc] | ||
// Set in SSM parameter store, true or false to enable or disable this module. | ||
count = var.enable_rds_servers_bastion == true ? 1 : 0 | ||
} |
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 |
---|---|---|
@@ -0,0 +1,26 @@ | ||
#!/usr/bin/env bash | ||
|
||
## Script to describe ec2 instances in target environment | ||
|
||
aws_describe_instances() { | ||
aws \ | ||
ec2 describe-instances \ | ||
--query 'Reservations[].Instances[].[InstanceId,InstanceType,PublicIpAddress,Tags[?Key==`Name`]| [0].Value]' \ | ||
--output table | ||
} | ||
|
||
assume_role_in_environment() { | ||
export $(printf "AWS_ACCESS_KEY_ID=%s AWS_SECRET_ACCESS_KEY=%s AWS_SESSION_TOKEN=%s" \ | ||
$(aws sts assume-role \ | ||
--role-arn "${TF_VAR_assume_role}" \ | ||
--role-session-name MySessionName \ | ||
--query "Credentials.[AccessKeyId,SecretAccessKey,SessionToken]" \ | ||
--output text)) | ||
} | ||
|
||
main() { | ||
assume_role_in_environment | ||
aws_describe_instances | ||
} | ||
|
||
main |
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,26 @@ | ||
#!/usr/bin/env bash | ||
|
||
## Script to describe ec2 instances in target environment | ||
|
||
aws_ssm_start_session() { | ||
instance_id=${1} | ||
|
||
echo "the instance_id is ${instance_id}" | ||
aws ssm start-session --target "${instance_id}" | ||
} | ||
|
||
assume_role_in_environment() { | ||
export $(printf "AWS_ACCESS_KEY_ID=%s AWS_SECRET_ACCESS_KEY=%s AWS_SESSION_TOKEN=%s" \ | ||
$(aws sts assume-role \ | ||
--role-arn "${TF_VAR_assume_role}" \ | ||
--role-session-name MySessionName \ | ||
--query "Credentials.[AccessKeyId,SecretAccessKey,SessionToken]" \ | ||
--output text)) | ||
} | ||
|
||
main() { | ||
assume_role_in_environment | ||
aws_ssm_start_session "${1}" | ||
} | ||
|
||
main "${1}" |
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