-
-
Notifications
You must be signed in to change notification settings - Fork 362
feat: Added support for persisting Atlantis state using EFS #247
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
298b7a2
684098b
5e6c8b2
947ff30
47f6dfd
0c2b5b2
154a95c
83db2ad
b6d233e
8f31f4c
7e6ebbc
5a7e48f
f6572b8
a748aae
4331aef
99774f1
7ecc9ce
12be167
07ebf5d
36bc94d
aa65e66
bd303ff
05f99b2
3d6b675
b9827af
a230370
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -110,6 +110,17 @@ locals { | |
| sort(compact(concat(var.allow_github_webhooks ? var.github_webhooks_cidr_blocks : [], var.whitelist_unauthenticated_cidr_blocks))), | ||
| 5 | ||
| ) | ||
|
|
||
| # break up user to uid and gid -- set both to 0 if null | ||
| uid = var.user == null ? 0 : split(":", var.user)[0] | ||
| gid = var.user == null ? 0 : split(":", var.user)[1] | ||
|
|
||
| # default mount points for efs if ephemeral storage is not enabled and mount points aren't specified | ||
| mount_points = var.enable_ephemeral_storage || length(var.mount_points) > 0 ? var.mount_points : [{ | ||
| containerPath = "/home/atlantis" | ||
| sourceVolume = "efs-storage" | ||
| readOnly = "false" | ||
| }] | ||
| } | ||
|
|
||
| data "aws_partition" "current" {} | ||
|
|
@@ -189,8 +200,9 @@ module "vpc" { | |
| private_subnets = var.private_subnets | ||
| public_subnets = var.public_subnets | ||
|
|
||
| enable_nat_gateway = true | ||
| single_nat_gateway = true | ||
| enable_nat_gateway = true | ||
| single_nat_gateway = true | ||
| enable_dns_hostnames = !var.enable_ephemeral_storage | ||
|
|
||
| manage_default_security_group = var.manage_default_security_group | ||
| default_security_group_ingress = var.default_security_group_ingress | ||
|
|
@@ -355,6 +367,24 @@ module "atlantis_sg" { | |
| tags = merge(local.tags, var.atlantis_security_group_tags) | ||
| } | ||
|
|
||
| module "efs_sg" { | ||
| source = "terraform-aws-modules/security-group/aws//modules/nfs" | ||
| version = "v4.8.0" | ||
| count = var.enable_ephemeral_storage ? 0 : 1 | ||
|
|
||
| name = "${var.name}-efs" | ||
| vpc_id = local.vpc_id | ||
| description = "Security group allowing access to the EFS storage" | ||
|
|
||
| ingress_cidr_blocks = [var.cidr] | ||
| ingress_with_source_security_group_id = [{ | ||
| rule = "nfs-tcp", | ||
| source_security_group_id = module.atlantis_sg.security_group_id | ||
| }] | ||
|
|
||
| tags = local.tags | ||
| } | ||
|
|
||
| ################################################################################ | ||
| # ACM (SSL certificate) | ||
| ################################################################################ | ||
|
|
@@ -388,6 +418,35 @@ resource "aws_route53_record" "atlantis" { | |
| } | ||
| } | ||
|
|
||
| ################################################################################ | ||
| # EFS | ||
| ################################################################################ | ||
|
|
||
| resource "aws_efs_file_system" "this" { | ||
| count = var.enable_ephemeral_storage ? 0 : 1 | ||
MarkIannucci marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| creation_token = var.name | ||
| } | ||
|
|
||
| resource "aws_efs_mount_target" "this" { | ||
| # we coalescelist in order to specify the resource keys when we create the subnets using the VPC or they're specified for us. This works around the for_each value depends on attributes which can't be determined until apply error | ||
| for_each = zipmap(coalescelist(var.private_subnets, var.private_subnet_ids), local.private_subnet_ids) | ||
|
|
||
| file_system_id = aws_efs_file_system.this[0].id | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @MarkIannucci Unfortunately this is not working if I want to have there is no condition for
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @borissavelev , thank you for the bug report. I'm sorry about the problem. I created #254 to track the resolution. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. no problem! thank you) |
||
| subnet_id = each.value | ||
| security_groups = [module.efs_sg[0].security_group_id, module.atlantis_sg.security_group_id] | ||
| } | ||
|
|
||
| resource "aws_efs_access_point" "this" { | ||
| count = var.enable_ephemeral_storage ? 0 : 1 | ||
|
|
||
| file_system_id = aws_efs_file_system.this[0].id | ||
| posix_user { | ||
| gid = local.gid | ||
| uid = local.uid | ||
| } | ||
| } | ||
|
|
||
| ################################################################################ | ||
| # ECS | ||
| ################################################################################ | ||
|
|
@@ -521,7 +580,7 @@ module "container_definition_github_gitlab" { | |
| container_depends_on = var.container_depends_on | ||
| essential = var.essential | ||
| readonly_root_filesystem = var.readonly_root_filesystem | ||
| mount_points = var.mount_points | ||
| mount_points = local.mount_points | ||
| volumes_from = var.volumes_from | ||
|
|
||
| port_mappings = [ | ||
|
|
@@ -624,11 +683,29 @@ resource "aws_ecs_task_definition" "atlantis" { | |
|
|
||
| dynamic "ephemeral_storage" { | ||
| for_each = var.enable_ephemeral_storage ? [1] : [] | ||
|
|
||
| content { | ||
| size_in_gib = var.ephemeral_storage_size | ||
| } | ||
| } | ||
|
|
||
| dynamic "volume" { | ||
| for_each = var.enable_ephemeral_storage ? [] : [1] | ||
|
|
||
| content { | ||
| name = "efs-storage" | ||
| efs_volume_configuration { | ||
| file_system_id = aws_efs_file_system.this[0].id | ||
| transit_encryption = "ENABLED" | ||
| transit_encryption_port = 2999 | ||
| authorization_config { | ||
| access_point_id = aws_efs_access_point.this[0].id | ||
| iam = "ENABLED" | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| tags = local.tags | ||
| } | ||
|
|
||
|
|
@@ -676,6 +753,7 @@ resource "aws_ecs_service" "atlantis" { | |
|
|
||
| dynamic "capacity_provider_strategy" { | ||
| for_each = var.ecs_fargate_spot ? [true] : [] | ||
|
|
||
| content { | ||
| capacity_provider = "FARGATE_SPOT" | ||
| weight = 100 | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
var.cidrcan be empty when is reusing existing VPCThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
probably
ingress_cidr_blocksis unnecessary here because later we haveingress_with_source_security_group_id