From 5ab16c1d00321eaad0b6a6c790e80e7bec313344 Mon Sep 17 00:00:00 2001 From: Yuliyan Tsvetkov Date: Wed, 5 Sep 2018 13:28:57 +0300 Subject: [PATCH 1/8] Adding .gitignore --- .gitignore | 10 + modules/aws-resources-used.txt | 39 + v1-legacy/terraform/app-cluster.tf | 2 +- v1-legacy/terraform/infra.svg | 2017 ++++++++++++++++++++++++++++ v1-legacy/terraform/terraform.tf | 7 - 5 files changed, 2067 insertions(+), 8 deletions(-) create mode 100644 modules/aws-resources-used.txt create mode 100644 v1-legacy/terraform/infra.svg diff --git a/.gitignore b/.gitignore index e69de29..0b1c871 100644 --- a/.gitignore +++ b/.gitignore @@ -0,0 +1,10 @@ +# Local .terraform directories +**/.terraform/* + +# .tfstate files +*.tfstate +*.tfstate.* + +**/.idea/* +.idea +.idea/workspace.xml \ No newline at end of file diff --git a/modules/aws-resources-used.txt b/modules/aws-resources-used.txt new file mode 100644 index 0000000..d7c3d54 --- /dev/null +++ b/modules/aws-resources-used.txt @@ -0,0 +1,39 @@ +aws_ecs_cluster +aws_ecs_service +aws_appautoscaling_target +aws_s3_bucket +aws_cloudwatch_log_group +aws_alb +aws_alb_listener +aws_alb_target_group +aws_autoscaling_group +aws_launch_configuration +aws_security_group +aws_iam_role +aws_iam_role_policy_attachment +aws_iam_instance_profile +aws_eip +aws_instance +aws_elasticache_cluster +aws_elasticache_subnet_group +aws_cloudwatch_event_rule +aws_cloudwatch_event_target +aws_iam_role_policy +aws_ecs_task_definition +aws_route53_zone +aws_route53_record +aws_iam_user +aws_iam_policy_attachment +aws_efs_file_system +aws_efs_mount_target +aws_key_pair +aws_nat_gateway +aws_subnet +aws_route_table +aws_internet_gateway +aws_egress_only_internet_gateway +aws_route_table_association +aws_rds_cluster +aws_rds_cluster_instance +aws_db_subnet_group +aws_vpc \ No newline at end of file diff --git a/v1-legacy/terraform/app-cluster.tf b/v1-legacy/terraform/app-cluster.tf index 225bded..401e4f9 100644 --- a/v1-legacy/terraform/app-cluster.tf +++ b/v1-legacy/terraform/app-cluster.tf @@ -131,7 +131,7 @@ resource "aws_ecs_service" "magento2" { desired_count = "${lookup(var.app_task_count, terraform.workspace)}" deployment_maximum_percent = 100 deployment_minimum_healthy_percent = 50 -0 + // Required so that the agent can talk to the load balancer iam_role = "${aws_iam_role.app_ecs_service_role.arn}" diff --git a/v1-legacy/terraform/infra.svg b/v1-legacy/terraform/infra.svg new file mode 100644 index 0000000..b549a13 --- /dev/null +++ b/v1-legacy/terraform/infra.svg @@ -0,0 +1,2017 @@ + + + + + + +%3 + + + +[root] aws_alb.app + +aws_alb.app + + + +[root] aws_s3_bucket.logs + +aws_s3_bucket.logs + + + +[root] aws_alb.app->[root] aws_s3_bucket.logs + + + + + +[root] aws_security_group.alb_web + +aws_security_group.alb_web + + + +[root] aws_alb.app->[root] aws_security_group.alb_web + + + + + +[root] aws_subnet.public_az1 + +aws_subnet.public_az1 + + + +[root] aws_alb.app->[root] aws_subnet.public_az1 + + + + + +[root] aws_subnet.public_az2 + +aws_subnet.public_az2 + + + +[root] aws_alb.app->[root] aws_subnet.public_az2 + + + + + +[root] aws_subnet.public_az3 + +aws_subnet.public_az3 + + + +[root] aws_alb.app->[root] aws_subnet.public_az3 + + + + + +[root] aws_alb_listener.app_http + +aws_alb_listener.app_http + + + +[root] aws_alb_listener.app_http->[root] aws_alb.app + + + + + +[root] aws_alb_target_group.app + +aws_alb_target_group.app + + + +[root] aws_alb_listener.app_http->[root] aws_alb_target_group.app + + + + + +[root] aws_vpc.default + +aws_vpc.default + + + +[root] aws_alb_target_group.app->[root] aws_vpc.default + + + + + +[root] aws_appautoscaling_target.service_appalb_asg_target + +aws_appautoscaling_target.service_appalb_asg_target + + + +[root] aws_ecs_service.magento2 + +aws_ecs_service.magento2 + + + +[root] aws_appautoscaling_target.service_appalb_asg_target->[root] aws_ecs_service.magento2 + + + + + +[root] aws_iam_role.ecs_autoscale_role + +aws_iam_role.ecs_autoscale_role + + + +[root] aws_appautoscaling_target.service_appalb_asg_target->[root] aws_iam_role.ecs_autoscale_role + + + + + +[root] aws_autoscaling_group.asg_app + +aws_autoscaling_group.asg_app + + + +[root] aws_autoscaling_group.asg_app->[root] aws_alb_target_group.app + + + + + +[root] aws_launch_configuration.lc_app + +aws_launch_configuration.lc_app + + + +[root] aws_autoscaling_group.asg_app->[root] aws_launch_configuration.lc_app + + + + + +[root] var.app_server_count + +[root] var.app_server_count + + + +[root] aws_autoscaling_group.asg_app->[root] var.app_server_count + + + + + +[root] var.availability_zones + +[root] var.availability_zones + + + +[root] aws_autoscaling_group.asg_app->[root] var.availability_zones + + + + + +[root] aws_cloudwatch_event_rule.cron_schedule + +aws_cloudwatch_event_rule.cron_schedule + + + +[root] provider.aws + +provider.aws + + + +[root] aws_cloudwatch_event_rule.cron_schedule->[root] provider.aws + + + + + +[root] aws_cloudwatch_event_target.magento_cron + +aws_cloudwatch_event_target.magento_cron + + + +[root] aws_cloudwatch_event_target.magento_cron->[root] aws_cloudwatch_event_rule.cron_schedule + + + + + +[root] aws_ecs_cluster.cluster_app + +aws_ecs_cluster.cluster_app + + + +[root] aws_cloudwatch_event_target.magento_cron->[root] aws_ecs_cluster.cluster_app + + + + + +[root] aws_ecs_task_definition.magento2_cron + +aws_ecs_task_definition.magento2_cron + + + +[root] aws_cloudwatch_event_target.magento_cron->[root] aws_ecs_task_definition.magento2_cron + + + + + +[root] aws_iam_role.task_role + +aws_iam_role.task_role + + + +[root] aws_cloudwatch_event_target.magento_cron->[root] aws_iam_role.task_role + + + + + +[root] aws_cloudwatch_log_group.app + +aws_cloudwatch_log_group.app + + + +[root] aws_cloudwatch_log_group.app->[root] provider.aws + + + + + +[root] aws_db_subnet_group.default + +aws_db_subnet_group.default + + + +[root] aws_subnet.private_az1 + +aws_subnet.private_az1 + + + +[root] aws_db_subnet_group.default->[root] aws_subnet.private_az1 + + + + + +[root] aws_subnet.private_az2 + +aws_subnet.private_az2 + + + +[root] aws_db_subnet_group.default->[root] aws_subnet.private_az2 + + + + + +[root] aws_subnet.private_az3 + +aws_subnet.private_az3 + + + +[root] aws_db_subnet_group.default->[root] aws_subnet.private_az3 + + + + + +[root] aws_ecs_cluster.cluster_app->[root] provider.aws + + + + + +[root] aws_ecs_service.magento2->[root] aws_alb_listener.app_http + + + + + +[root] aws_ecs_service.magento2->[root] aws_ecs_cluster.cluster_app + + + + + +[root] aws_iam_role.app_ecs_service_role + +aws_iam_role.app_ecs_service_role + + + +[root] aws_ecs_service.magento2->[root] aws_iam_role.app_ecs_service_role + + + + + +[root] data.aws_ecs_task_definition.magento2 + +data.aws_ecs_task_definition.magento2 + + + +[root] aws_ecs_service.magento2->[root] data.aws_ecs_task_definition.magento2 + + + + + +[root] var.app_task_count + +[root] var.app_task_count + + + +[root] aws_ecs_service.magento2->[root] var.app_task_count + + + + + +[root] aws_ecs_task_definition.magento2 + +aws_ecs_task_definition.magento2 + + + +[root] aws_route53_record.db + +aws_route53_record.db + + + +[root] aws_ecs_task_definition.magento2->[root] aws_route53_record.db + + + + + +[root] aws_route53_record.redis_cache + +aws_route53_record.redis_cache + + + +[root] aws_ecs_task_definition.magento2->[root] aws_route53_record.redis_cache + + + + + +[root] aws_route53_record.redis_session + +aws_route53_record.redis_session + + + +[root] aws_ecs_task_definition.magento2->[root] aws_route53_record.redis_session + + + + + +[root] data.aws_ecr_repository.magento2 + +data.aws_ecr_repository.magento2 + + + +[root] aws_ecs_task_definition.magento2->[root] data.aws_ecr_repository.magento2 + + + + + +[root] data.aws_ecr_repository.nginx + +data.aws_ecr_repository.nginx + + + +[root] aws_ecs_task_definition.magento2->[root] data.aws_ecr_repository.nginx + + + + + +[root] var.env_mysql_database + +[root] var.env_mysql_database + + + +[root] aws_ecs_task_definition.magento2->[root] var.env_mysql_database + + + + + +[root] var.env_mysql_user + +[root] var.env_mysql_user + + + +[root] aws_ecs_task_definition.magento2->[root] var.env_mysql_user + + + + + +[root] aws_ecs_task_definition.magento2_cron->[root] aws_route53_record.db + + + + + +[root] aws_ecs_task_definition.magento2_cron->[root] aws_route53_record.redis_cache + + + + + +[root] aws_ecs_task_definition.magento2_cron->[root] aws_route53_record.redis_session + + + + + +[root] aws_ecs_task_definition.magento2_cron->[root] data.aws_ecr_repository.magento2 + + + + + +[root] aws_ecs_task_definition.magento2_cron->[root] var.env_mysql_database + + + + + +[root] aws_ecs_task_definition.magento2_cron->[root] var.env_mysql_user + + + + + +[root] aws_ecs_task_definition.magento2_setup + +aws_ecs_task_definition.magento2_setup + + + +[root] aws_ecs_task_definition.magento2_setup->[root] aws_alb.app + + + + + +[root] aws_ecs_task_definition.magento2_setup->[root] aws_route53_record.db + + + + + +[root] aws_ecs_task_definition.magento2_setup->[root] aws_route53_record.redis_cache + + + + + +[root] aws_ecs_task_definition.magento2_setup->[root] aws_route53_record.redis_session + + + + + +[root] aws_ecs_task_definition.magento2_setup->[root] data.aws_ecr_repository.magento2 + + + + + +[root] aws_ecs_task_definition.magento2_setup->[root] var.env_mysql_database + + + + + +[root] aws_ecs_task_definition.magento2_setup->[root] var.env_mysql_user + + + + + +[root] aws_efs_file_system.media + +aws_efs_file_system.media + + + +[root] aws_efs_file_system.media->[root] provider.aws + + + + + +[root] var.project_name + +[root] var.project_name + + + +[root] aws_efs_file_system.media->[root] var.project_name + + + + + +[root] aws_efs_mount_target.az1 + +aws_efs_mount_target.az1 + + + +[root] aws_efs_mount_target.az1->[root] aws_efs_file_system.media + + + + + +[root] aws_security_group.efs + +aws_security_group.efs + + + +[root] aws_efs_mount_target.az1->[root] aws_security_group.efs + + + + + +[root] aws_efs_mount_target.az1->[root] aws_subnet.private_az1 + + + + + +[root] aws_efs_mount_target.az2 + +aws_efs_mount_target.az2 + + + +[root] aws_efs_mount_target.az2->[root] aws_efs_file_system.media + + + + + +[root] aws_efs_mount_target.az2->[root] aws_security_group.efs + + + + + +[root] aws_efs_mount_target.az2->[root] aws_subnet.private_az2 + + + + + +[root] aws_efs_mount_target.az3 + +aws_efs_mount_target.az3 + + + +[root] aws_efs_mount_target.az3->[root] aws_efs_file_system.media + + + + + +[root] aws_efs_mount_target.az3->[root] aws_security_group.efs + + + + + +[root] aws_efs_mount_target.az3->[root] aws_subnet.private_az3 + + + + + +[root] aws_egress_only_internet_gateway.ipv6egress + +aws_egress_only_internet_gateway.ipv6egress + + + +[root] aws_egress_only_internet_gateway.ipv6egress->[root] aws_vpc.default + + + + + +[root] aws_eip.bastion + +aws_eip.bastion + + + +[root] aws_instance.bastion + +aws_instance.bastion + + + +[root] aws_eip.bastion->[root] aws_instance.bastion + + + + + +[root] aws_eip.nat + +aws_eip.nat + + + +[root] aws_eip.nat->[root] provider.aws + + + + + +[root] aws_elasticache_cluster.redis_cache + +aws_elasticache_cluster.redis_cache + + + +[root] aws_elasticache_subnet_group.redis + +aws_elasticache_subnet_group.redis + + + +[root] aws_elasticache_cluster.redis_cache->[root] aws_elasticache_subnet_group.redis + + + + + +[root] aws_security_group.default + +aws_security_group.default + + + +[root] aws_elasticache_cluster.redis_cache->[root] aws_security_group.default + + + + + +[root] aws_security_group.redis + +aws_security_group.redis + + + +[root] aws_elasticache_cluster.redis_cache->[root] aws_security_group.redis + + + + + +[root] aws_elasticache_cluster.redis_session + +aws_elasticache_cluster.redis_session + + + +[root] aws_elasticache_cluster.redis_session->[root] aws_elasticache_subnet_group.redis + + + + + +[root] aws_elasticache_cluster.redis_session->[root] aws_security_group.default + + + + + +[root] aws_elasticache_cluster.redis_session->[root] aws_security_group.redis + + + + + +[root] aws_elasticache_subnet_group.redis->[root] aws_subnet.private_az1 + + + + + +[root] aws_elasticache_subnet_group.redis->[root] aws_subnet.private_az2 + + + + + +[root] aws_elasticache_subnet_group.redis->[root] aws_subnet.private_az3 + + + + + +[root] aws_iam_instance_profile.ecs_app_instance_profile + +aws_iam_instance_profile.ecs_app_instance_profile + + + +[root] aws_iam_role.ecs_role + +aws_iam_role.ecs_role + + + +[root] aws_iam_instance_profile.ecs_app_instance_profile->[root] aws_iam_role.ecs_role + + + + + +[root] aws_iam_role.app_ecs_service_role->[root] provider.aws + + + + + +[root] aws_iam_role.app_ecs_task_role + +aws_iam_role.app_ecs_task_role + + + +[root] aws_iam_role.app_ecs_task_role->[root] provider.aws + + + + + +[root] aws_iam_role.ecs_autoscale_role->[root] provider.aws + + + + + +[root] aws_iam_role.ecs_role->[root] provider.aws + + + + + +[root] aws_iam_role.task_role->[root] provider.aws + + + + + +[root] aws_iam_role_policy.run_task_policy + +aws_iam_role_policy.run_task_policy + + + +[root] aws_iam_role_policy.run_task_policy->[root] aws_iam_role.task_role + + + + + +[root] aws_iam_role_policy_attachment.ecs_autoscale_role_policy_attachment + +aws_iam_role_policy_attachment.ecs_autoscale_role_policy_attachment + + + +[root] aws_iam_role_policy_attachment.ecs_autoscale_role_policy_attachment->[root] aws_iam_role.ecs_autoscale_role + + + + + +[root] aws_iam_role_policy_attachment.ecs_instance_instance_role_policy_attachment + +aws_iam_role_policy_attachment.ecs_instance_instance_role_policy_attachment + + + +[root] aws_iam_role_policy_attachment.ecs_instance_instance_role_policy_attachment->[root] aws_iam_role.ecs_role + + + + + +[root] aws_iam_role_policy_attachment.ecs_service_instance_role_policy_attachment + +aws_iam_role_policy_attachment.ecs_service_instance_role_policy_attachment + + + +[root] aws_iam_role_policy_attachment.ecs_service_instance_role_policy_attachment->[root] aws_iam_role.ecs_role + + + + + +[root] aws_iam_role_policy_attachment.ecs_service_role_policy_attachment + +aws_iam_role_policy_attachment.ecs_service_role_policy_attachment + + + +[root] aws_iam_role_policy_attachment.ecs_service_role_policy_attachment->[root] aws_iam_role.app_ecs_service_role + + + + + +[root] aws_key_pair.deployer + +aws_key_pair.deployer + + + +[root] aws_instance.bastion->[root] aws_key_pair.deployer + + + + + +[root] aws_security_group.bastion + +aws_security_group.bastion + + + +[root] aws_instance.bastion->[root] aws_security_group.bastion + + + + + +[root] aws_instance.bastion->[root] aws_subnet.public_az1 + + + + + +[root] var.amazon_dns_server + +[root] var.amazon_dns_server + + + +[root] aws_instance.bastion->[root] var.amazon_dns_server + + + + + +[root] var.amis + +[root] var.amis + + + +[root] aws_instance.bastion->[root] var.amis + + + + + +[root] aws_internet_gateway.default + +aws_internet_gateway.default + + + +[root] aws_internet_gateway.default->[root] aws_vpc.default + + + + + +[root] aws_key_pair.deployer->[root] provider.aws + + + + + +[root] aws_launch_configuration.lc_app->[root] aws_iam_instance_profile.ecs_app_instance_profile + + + + + +[root] data.template_file.template_app_ecs_user_data + +data.template_file.template_app_ecs_user_data + + + +[root] aws_launch_configuration.lc_app->[root] data.template_file.template_app_ecs_user_data + + + + + +[root] var.ecs_ami + +[root] var.ecs_ami + + + +[root] aws_launch_configuration.lc_app->[root] var.ecs_ami + + + + + +[root] aws_nat_gateway.nat + +aws_nat_gateway.nat + + + +[root] aws_nat_gateway.nat->[root] aws_eip.nat + + + + + +[root] aws_nat_gateway.nat->[root] aws_subnet.public_az1 + + + + + +[root] aws_nat_gateway.nat->[root] aws_subnet.public_az2 + + + + + +[root] aws_nat_gateway.nat->[root] aws_subnet.public_az3 + + + + + +[root] aws_rds_cluster.default + +aws_rds_cluster.default + + + +[root] aws_rds_cluster.default->[root] aws_db_subnet_group.default + + + + + +[root] aws_rds_cluster.default->[root] aws_security_group.default + + + + + +[root] aws_security_group.rds + +aws_security_group.rds + + + +[root] aws_rds_cluster.default->[root] aws_security_group.rds + + + + + +[root] var.rds_password + +[root] var.rds_password + + + +[root] aws_rds_cluster.default->[root] var.rds_password + + + + + +[root] aws_rds_cluster_instance.cluster_instances + +aws_rds_cluster_instance.cluster_instances + + + +[root] aws_rds_cluster_instance.cluster_instances->[root] aws_rds_cluster.default + + + + + +[root] aws_route53_record.db->[root] aws_rds_cluster.default + + + + + +[root] aws_route53_zone.internal + +aws_route53_zone.internal + + + +[root] aws_route53_record.db->[root] aws_route53_zone.internal + + + + + +[root] aws_route53_record.efs_az1 + +aws_route53_record.efs_az1 + + + +[root] aws_route53_record.efs_az1->[root] aws_efs_file_system.media + + + + + +[root] aws_route53_record.efs_az1->[root] aws_route53_zone.internal + + + + + +[root] aws_route53_record.efs_az2 + +aws_route53_record.efs_az2 + + + +[root] aws_route53_record.efs_az2->[root] aws_efs_file_system.media + + + + + +[root] aws_route53_record.efs_az2->[root] aws_route53_zone.internal + + + + + +[root] aws_route53_record.efs_az3 + +aws_route53_record.efs_az3 + + + +[root] aws_route53_record.efs_az3->[root] aws_efs_file_system.media + + + + + +[root] aws_route53_record.efs_az3->[root] aws_route53_zone.internal + + + + + +[root] aws_route53_record.efs_dns + +aws_route53_record.efs_dns + + + +[root] aws_route53_record.efs_dns->[root] aws_efs_file_system.media + + + + + +[root] aws_route53_record.efs_dns->[root] aws_route53_zone.internal + + + + + +[root] aws_route53_record.internal_ns + +aws_route53_record.internal_ns + + + +[root] aws_route53_record.internal_ns->[root] aws_route53_zone.internal + + + + + +[root] aws_route53_record.redis_cache->[root] aws_elasticache_cluster.redis_cache + + + + + +[root] aws_route53_record.redis_cache->[root] aws_route53_zone.internal + + + + + +[root] aws_route53_record.redis_session->[root] aws_elasticache_cluster.redis_session + + + + + +[root] aws_route53_record.redis_session->[root] aws_route53_zone.internal + + + + + +[root] aws_route53_zone.internal->[root] aws_vpc.default + + + + + +[root] var.internal_domain + +[root] var.internal_domain + + + +[root] aws_route53_zone.internal->[root] var.internal_domain + + + + + +[root] aws_route_table.private + +aws_route_table.private + + + +[root] aws_route_table.private->[root] aws_egress_only_internet_gateway.ipv6egress + + + + + +[root] aws_route_table.private->[root] aws_nat_gateway.nat + + + + + +[root] aws_route_table.public + +aws_route_table.public + + + +[root] aws_route_table.public->[root] aws_internet_gateway.default + + + + + +[root] aws_route_table_association.private + +aws_route_table_association.private + + + +[root] aws_route_table_association.private->[root] aws_route_table.private + + + + + +[root] aws_route_table_association.private->[root] aws_subnet.private_az1 + + + + + +[root] aws_route_table_association.private->[root] aws_subnet.private_az2 + + + + + +[root] aws_route_table_association.private->[root] aws_subnet.private_az3 + + + + + +[root] aws_route_table_association.public_az1 + +aws_route_table_association.public_az1 + + + +[root] aws_route_table_association.public_az1->[root] aws_route_table.public + + + + + +[root] aws_route_table_association.public_az1->[root] aws_subnet.public_az1 + + + + + +[root] aws_route_table_association.public_az2 + +aws_route_table_association.public_az2 + + + +[root] aws_route_table_association.public_az2->[root] aws_route_table.public + + + + + +[root] aws_route_table_association.public_az2->[root] aws_subnet.public_az2 + + + + + +[root] aws_route_table_association.public_az3 + +aws_route_table_association.public_az3 + + + +[root] aws_route_table_association.public_az3->[root] aws_route_table.public + + + + + +[root] aws_route_table_association.public_az3->[root] aws_subnet.public_az3 + + + + + +[root] aws_s3_bucket.logs->[root] provider.aws + + + + + +[root] aws_s3_bucket.logs->[root] var.project_name + + + + + +[root] var.default_log_account_ids + +[root] var.default_log_account_ids + + + +[root] aws_s3_bucket.logs->[root] var.default_log_account_ids + + + + + +[root] aws_security_group.alb_web->[root] aws_vpc.default + + + + + +[root] aws_security_group.app + +aws_security_group.app + + + +[root] aws_security_group.app->[root] aws_security_group.bastion + + + + + +[root] aws_security_group.bastion->[root] aws_vpc.default + + + + + +[root] aws_security_group.default->[root] aws_vpc.default + + + + + +[root] aws_security_group.efs->[root] aws_security_group.app + + + + + +[root] aws_security_group.rds->[root] aws_security_group.app + + + + + +[root] aws_security_group.redis->[root] aws_security_group.app + + + + + +[root] aws_subnet.private_az1->[root] aws_internet_gateway.default + + + + + +[root] var.private_subnet_az1_cidr + +[root] var.private_subnet_az1_cidr + + + +[root] aws_subnet.private_az1->[root] var.private_subnet_az1_cidr + + + + + +[root] aws_subnet.private_az2->[root] aws_internet_gateway.default + + + + + +[root] var.private_subnet_az2_cidr + +[root] var.private_subnet_az2_cidr + + + +[root] aws_subnet.private_az2->[root] var.private_subnet_az2_cidr + + + + + +[root] aws_subnet.private_az3->[root] aws_internet_gateway.default + + + + + +[root] var.private_subnet_az3_cidr + +[root] var.private_subnet_az3_cidr + + + +[root] aws_subnet.private_az3->[root] var.private_subnet_az3_cidr + + + + + +[root] aws_subnet.public_az1->[root] aws_internet_gateway.default + + + + + +[root] var.public_subnet_az1_cidr + +[root] var.public_subnet_az1_cidr + + + +[root] aws_subnet.public_az1->[root] var.public_subnet_az1_cidr + + + + + +[root] aws_subnet.public_az2->[root] aws_internet_gateway.default + + + + + +[root] var.public_subnet_az2_cidr + +[root] var.public_subnet_az2_cidr + + + +[root] aws_subnet.public_az2->[root] var.public_subnet_az2_cidr + + + + + +[root] aws_subnet.public_az3->[root] aws_internet_gateway.default + + + + + +[root] var.public_subnet_az3_cidr + +[root] var.public_subnet_az3_cidr + + + +[root] aws_subnet.public_az3->[root] var.public_subnet_az3_cidr + + + + + +[root] aws_vpc.default->[root] provider.aws + + + + + +[root] aws_vpc.default->[root] var.project_name + + + + + +[root] var.vpc_cidr + +[root] var.vpc_cidr + + + +[root] aws_vpc.default->[root] var.vpc_cidr + + + + + +[root] data.aws_ecr_repository.magento2->[root] provider.aws + + + + + +[root] data.aws_ecr_repository.nginx->[root] provider.aws + + + + + +[root] data.aws_ecs_task_definition.magento2->[root] aws_ecs_task_definition.magento2 + + + + + +[root] data.template_file.template_app_ecs_user_data->[root] aws_route53_record.db + + + + + +[root] provider.template + +provider.template + + + +[root] data.template_file.template_app_ecs_user_data->[root] provider.template + + + + + +[root] data.template_file.template_app_ecs_user_data->[root] var.env_mysql_database + + + + + +[root] data.template_file.template_app_ecs_user_data->[root] var.env_mysql_user + + + + + +[root] var.aws_region + +[root] var.aws_region + + + +[root] provider.aws->[root] var.aws_region + + + + + +[root] meta.count-boundary (count boundary fixup) + +[root] meta.count-boundary (count boundary fixup) + + + +[root] meta.count-boundary (count boundary fixup)->[root] aws_appautoscaling_target.service_appalb_asg_target + + + + + +[root] meta.count-boundary (count boundary fixup)->[root] aws_autoscaling_group.asg_app + + + + + +[root] meta.count-boundary (count boundary fixup)->[root] aws_cloudwatch_event_target.magento_cron + + + + + +[root] meta.count-boundary (count boundary fixup)->[root] aws_cloudwatch_log_group.app + + + + + +[root] meta.count-boundary (count boundary fixup)->[root] aws_ecs_task_definition.magento2_setup + + + + + +[root] meta.count-boundary (count boundary fixup)->[root] aws_efs_mount_target.az1 + + + + + +[root] meta.count-boundary (count boundary fixup)->[root] aws_efs_mount_target.az2 + + + + + +[root] meta.count-boundary (count boundary fixup)->[root] aws_efs_mount_target.az3 + + + + + +[root] meta.count-boundary (count boundary fixup)->[root] aws_iam_role.app_ecs_task_role + + + + + +[root] meta.count-boundary (count boundary fixup)->[root] aws_iam_role_policy.run_task_policy + + + + + +[root] meta.count-boundary (count boundary fixup)->[root] aws_iam_role_policy_attachment.ecs_autoscale_role_policy_attachment + + + + + +[root] meta.count-boundary (count boundary fixup)->[root] aws_iam_role_policy_attachment.ecs_instance_instance_role_policy_attachment + + + + + +[root] meta.count-boundary (count boundary fixup)->[root] aws_iam_role_policy_attachment.ecs_service_instance_role_policy_attachment + + + + + +[root] meta.count-boundary (count boundary fixup)->[root] aws_iam_role_policy_attachment.ecs_service_role_policy_attachment + + + + + +[root] meta.count-boundary (count boundary fixup)->[root] aws_rds_cluster_instance.cluster_instances + + + + + +[root] meta.count-boundary (count boundary fixup)->[root] aws_route53_record.efs_az1 + + + + + +[root] meta.count-boundary (count boundary fixup)->[root] aws_route53_record.efs_az2 + + + + + +[root] meta.count-boundary (count boundary fixup)->[root] aws_route53_record.efs_az3 + + + + + +[root] meta.count-boundary (count boundary fixup)->[root] aws_route53_record.efs_dns + + + + + +[root] meta.count-boundary (count boundary fixup)->[root] aws_route53_record.internal_ns + + + + + +[root] meta.count-boundary (count boundary fixup)->[root] aws_route_table_association.private + + + + + +[root] meta.count-boundary (count boundary fixup)->[root] aws_route_table_association.public_az1 + + + + + +[root] meta.count-boundary (count boundary fixup)->[root] aws_route_table_association.public_az2 + + + + + +[root] meta.count-boundary (count boundary fixup)->[root] aws_route_table_association.public_az3 + + + + + +[root] output.alb_name + +[root] output.alb_name + + + +[root] meta.count-boundary (count boundary fixup)->[root] output.alb_name + + + + + +[root] output.bastion.ip + +[root] output.bastion.ip + + + +[root] meta.count-boundary (count boundary fixup)->[root] output.bastion.ip + + + + + +[root] var.ssh_user + +[root] var.ssh_user + + + +[root] meta.count-boundary (count boundary fixup)->[root] var.ssh_user + + + + + +[root] output.alb_name->[root] aws_alb.app + + + + + +[root] output.bastion.ip->[root] aws_eip.bastion + + + + + +[root] provider.aws (close) + +[root] provider.aws (close) + + + +[root] provider.aws (close)->[root] aws_appautoscaling_target.service_appalb_asg_target + + + + + +[root] provider.aws (close)->[root] aws_autoscaling_group.asg_app + + + + + +[root] provider.aws (close)->[root] aws_cloudwatch_event_target.magento_cron + + + + + +[root] provider.aws (close)->[root] aws_cloudwatch_log_group.app + + + + + +[root] provider.aws (close)->[root] aws_ecs_task_definition.magento2_setup + + + + + +[root] provider.aws (close)->[root] aws_efs_mount_target.az1 + + + + + +[root] provider.aws (close)->[root] aws_efs_mount_target.az2 + + + + + +[root] provider.aws (close)->[root] aws_efs_mount_target.az3 + + + + + +[root] provider.aws (close)->[root] aws_eip.bastion + + + + + +[root] provider.aws (close)->[root] aws_iam_role.app_ecs_task_role + + + + + +[root] provider.aws (close)->[root] aws_iam_role_policy.run_task_policy + + + + + +[root] provider.aws (close)->[root] aws_iam_role_policy_attachment.ecs_autoscale_role_policy_attachment + + + + + +[root] provider.aws (close)->[root] aws_iam_role_policy_attachment.ecs_instance_instance_role_policy_attachment + + + + + +[root] provider.aws (close)->[root] aws_iam_role_policy_attachment.ecs_service_instance_role_policy_attachment + + + + + +[root] provider.aws (close)->[root] aws_iam_role_policy_attachment.ecs_service_role_policy_attachment + + + + + +[root] provider.aws (close)->[root] aws_rds_cluster_instance.cluster_instances + + + + + +[root] provider.aws (close)->[root] aws_route53_record.efs_az1 + + + + + +[root] provider.aws (close)->[root] aws_route53_record.efs_az2 + + + + + +[root] provider.aws (close)->[root] aws_route53_record.efs_az3 + + + + + +[root] provider.aws (close)->[root] aws_route53_record.efs_dns + + + + + +[root] provider.aws (close)->[root] aws_route53_record.internal_ns + + + + + +[root] provider.aws (close)->[root] aws_route_table_association.private + + + + + +[root] provider.aws (close)->[root] aws_route_table_association.public_az1 + + + + + +[root] provider.aws (close)->[root] aws_route_table_association.public_az2 + + + + + +[root] provider.aws (close)->[root] aws_route_table_association.public_az3 + + + + + +[root] provider.template (close) + +[root] provider.template (close) + + + +[root] provider.template (close)->[root] data.template_file.template_app_ecs_user_data + + + + + +[root] provisioner.file (close) + +[root] provisioner.file (close) + + + +[root] provisioner.file (close)->[root] aws_instance.bastion + + + + + +[root] provisioner.remote-exec (close) + +[root] provisioner.remote-exec (close) + + + +[root] provisioner.remote-exec (close)->[root] aws_instance.bastion + + + + + +[root] root + +[root] root + + + +[root] root->[root] meta.count-boundary (count boundary fixup) + + + + + +[root] root->[root] provider.aws (close) + + + + + +[root] root->[root] provider.template (close) + + + + + +[root] root->[root] provisioner.file (close) + + + + + +[root] root->[root] provisioner.remote-exec (close) + + + + + diff --git a/v1-legacy/terraform/terraform.tf b/v1-legacy/terraform/terraform.tf index 469d44c..e69de29 100644 --- a/v1-legacy/terraform/terraform.tf +++ b/v1-legacy/terraform/terraform.tf @@ -1,7 +0,0 @@ -terraform { - backend "s3" { - bucket = "magecloudkit-state" - key = "terraform" - region = "us-east-1" - } -} From 7ffaa3c49cf3255e51f219f04b09c22f1e6986ee Mon Sep 17 00:00:00 2001 From: Yuliyan Tsvetkov Date: Wed, 5 Sep 2018 13:30:30 +0300 Subject: [PATCH 2/8] Fixing app-cluster module structure in order to start creating configuration data templates --- modules/app-cluster/aws/{ecs-cluster => }/README.md | 0 modules/app-cluster/aws/ecs-service/README.md | 0 modules/app-cluster/aws/ecs-service/main.tf | 0 modules/app-cluster/aws/ecs-service/outputs.tf | 0 modules/app-cluster/aws/ecs-service/variables.tf | 0 modules/app-cluster/aws/{ecs-cluster => }/main.tf | 0 modules/app-cluster/aws/{ecs-cluster => }/outputs.tf | 0 modules/app-cluster/aws/{ecs-cluster => }/variables.tf | 0 8 files changed, 0 insertions(+), 0 deletions(-) rename modules/app-cluster/aws/{ecs-cluster => }/README.md (100%) delete mode 100644 modules/app-cluster/aws/ecs-service/README.md delete mode 100644 modules/app-cluster/aws/ecs-service/main.tf delete mode 100644 modules/app-cluster/aws/ecs-service/outputs.tf delete mode 100644 modules/app-cluster/aws/ecs-service/variables.tf rename modules/app-cluster/aws/{ecs-cluster => }/main.tf (100%) rename modules/app-cluster/aws/{ecs-cluster => }/outputs.tf (100%) rename modules/app-cluster/aws/{ecs-cluster => }/variables.tf (100%) diff --git a/modules/app-cluster/aws/ecs-cluster/README.md b/modules/app-cluster/aws/README.md similarity index 100% rename from modules/app-cluster/aws/ecs-cluster/README.md rename to modules/app-cluster/aws/README.md diff --git a/modules/app-cluster/aws/ecs-service/README.md b/modules/app-cluster/aws/ecs-service/README.md deleted file mode 100644 index e69de29..0000000 diff --git a/modules/app-cluster/aws/ecs-service/main.tf b/modules/app-cluster/aws/ecs-service/main.tf deleted file mode 100644 index e69de29..0000000 diff --git a/modules/app-cluster/aws/ecs-service/outputs.tf b/modules/app-cluster/aws/ecs-service/outputs.tf deleted file mode 100644 index e69de29..0000000 diff --git a/modules/app-cluster/aws/ecs-service/variables.tf b/modules/app-cluster/aws/ecs-service/variables.tf deleted file mode 100644 index e69de29..0000000 diff --git a/modules/app-cluster/aws/ecs-cluster/main.tf b/modules/app-cluster/aws/main.tf similarity index 100% rename from modules/app-cluster/aws/ecs-cluster/main.tf rename to modules/app-cluster/aws/main.tf diff --git a/modules/app-cluster/aws/ecs-cluster/outputs.tf b/modules/app-cluster/aws/outputs.tf similarity index 100% rename from modules/app-cluster/aws/ecs-cluster/outputs.tf rename to modules/app-cluster/aws/outputs.tf diff --git a/modules/app-cluster/aws/ecs-cluster/variables.tf b/modules/app-cluster/aws/variables.tf similarity index 100% rename from modules/app-cluster/aws/ecs-cluster/variables.tf rename to modules/app-cluster/aws/variables.tf From abf1197a1aa345f1808d4e28feea567bd093ccf0 Mon Sep 17 00:00:00 2001 From: Yuliyan Tsvetkov Date: Wed, 5 Sep 2018 13:34:44 +0300 Subject: [PATCH 3/8] Creating .tpl files for content migration to template_file --- modules/app-cluster/aws/app_ecs_service_role.tpl | 0 modules/app-cluster/aws/app_ecs_task_definition_magento2.tpl | 0 modules/app-cluster/aws/app_ecs_task_role.tpl | 0 modules/app-cluster/aws/ecs_autoscale_role.tpl | 0 modules/app-cluster/aws/ecs_role.tpl | 0 modules/app-cluster/aws/logs-policy.tpl | 0 modules/app-cluster/aws/template_app_ecs_user_data.tpl | 0 7 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 modules/app-cluster/aws/app_ecs_service_role.tpl create mode 100644 modules/app-cluster/aws/app_ecs_task_definition_magento2.tpl create mode 100644 modules/app-cluster/aws/app_ecs_task_role.tpl create mode 100644 modules/app-cluster/aws/ecs_autoscale_role.tpl create mode 100644 modules/app-cluster/aws/ecs_role.tpl create mode 100644 modules/app-cluster/aws/logs-policy.tpl create mode 100644 modules/app-cluster/aws/template_app_ecs_user_data.tpl diff --git a/modules/app-cluster/aws/app_ecs_service_role.tpl b/modules/app-cluster/aws/app_ecs_service_role.tpl new file mode 100644 index 0000000..e69de29 diff --git a/modules/app-cluster/aws/app_ecs_task_definition_magento2.tpl b/modules/app-cluster/aws/app_ecs_task_definition_magento2.tpl new file mode 100644 index 0000000..e69de29 diff --git a/modules/app-cluster/aws/app_ecs_task_role.tpl b/modules/app-cluster/aws/app_ecs_task_role.tpl new file mode 100644 index 0000000..e69de29 diff --git a/modules/app-cluster/aws/ecs_autoscale_role.tpl b/modules/app-cluster/aws/ecs_autoscale_role.tpl new file mode 100644 index 0000000..e69de29 diff --git a/modules/app-cluster/aws/ecs_role.tpl b/modules/app-cluster/aws/ecs_role.tpl new file mode 100644 index 0000000..e69de29 diff --git a/modules/app-cluster/aws/logs-policy.tpl b/modules/app-cluster/aws/logs-policy.tpl new file mode 100644 index 0000000..e69de29 diff --git a/modules/app-cluster/aws/template_app_ecs_user_data.tpl b/modules/app-cluster/aws/template_app_ecs_user_data.tpl new file mode 100644 index 0000000..e69de29 From 334c796e43454c5024d9f81f03f9b4512f0e6e4a Mon Sep 17 00:00:00 2001 From: Yuliyan Tsvetkov Date: Wed, 5 Sep 2018 13:44:39 +0300 Subject: [PATCH 4/8] Moving tpl definitions to external .tpl files - no config migration made --- .../app-cluster/aws/app_ecs_service_role.tpl | 14 + .../aws/app_ecs_task_definition_magento2.tpl | 95 +++++ modules/app-cluster/aws/app_ecs_task_role.tpl | 13 + .../app-cluster/aws/ecs_autoscale_role.tpl | 14 + modules/app-cluster/aws/ecs_role.tpl | 15 + modules/app-cluster/aws/logs-policy.tpl | 15 + modules/app-cluster/aws/main.tf | 342 ++++++++++++++++++ 7 files changed, 508 insertions(+) diff --git a/modules/app-cluster/aws/app_ecs_service_role.tpl b/modules/app-cluster/aws/app_ecs_service_role.tpl index e69de29..99856ce 100644 --- a/modules/app-cluster/aws/app_ecs_service_role.tpl +++ b/modules/app-cluster/aws/app_ecs_service_role.tpl @@ -0,0 +1,14 @@ +{ + "Version": "2008-10-17", + "Statement": [ + { + "Action": "sts:AssumeRole", + "Principal": { + "Service": [ + "ecs.amazonaws.com" + ] + }, + "Effect": "Allow" + } + ] +} \ No newline at end of file diff --git a/modules/app-cluster/aws/app_ecs_task_definition_magento2.tpl b/modules/app-cluster/aws/app_ecs_task_definition_magento2.tpl index e69de29..9af3fe3 100644 --- a/modules/app-cluster/aws/app_ecs_task_definition_magento2.tpl +++ b/modules/app-cluster/aws/app_ecs_task_definition_magento2.tpl @@ -0,0 +1,95 @@ + [ + { + "name": "magento2", + "image": "${data.aws_ecr_repository.magento2.repository_url}", + "mountPoints": [ + { + "containerPath": "/var/www/html/pub/media", + "sourceVolume": "media", + "readOnly": null + } + ], + "essential": true, + "environment": [ + { + "name": "ENVIRONMENT", + "value": "${terraform.workspace}" + }, + { + "name": "MAGE_MODE", + "value": "production" + }, + { + "name": "CACHE_PREFIX", + "value": "1_" + }, + { + "name": "MYSQL_HOST", + "value": "${aws_route53_record.db.fqdn}" + }, + { + "name": "MYSQL_DATABASE", + "value": "${var.env_mysql_database}" + }, + { + "name": "MYSQL_USER", + "value": "${var.env_mysql_user}" + }, + { + "name": "MYSQL_PASSWORD", + "value": "${lookup(var.rds_password, terraform.workspace)}" + }, + { + "name": "REDIS_CACHE_HOST", + "value": "${aws_route53_record.redis_cache.fqdn}" + }, + { + "name": "REDIS_SESSION_HOST", + "value": "${aws_route53_record.redis_session.fqdn}" + } + ], + "logConfiguration": { + "logDriver": "awslogs", + "options": { + "awslogs-group": "${terraform.workspace}-app", + "awslogs-region": "us-east-1", + "awslogs-stream-prefix": "magento2" + } + }, + "cpu": 0, + "memoryReservation": 768 + }, + { + "name": "nginx", + "volumesFrom": [ + { + "readOnly": true, + "sourceContainer": "magento2" + } + ], + "portMappings": [ + { + "hostPort": 80, + "containerPort": 80, + "protocol": "tcp" + } + ], + "essential": true, + "environment": [], + "links": [ + "magento2:phpfpm" + ], + "image": "${data.aws_ecr_repository.nginx.repository_url}", + "command": [], + "logConfiguration": { + "logDriver": "awslogs", + "options": { + "awslogs-group": "${terraform.workspace}-app", + "awslogs-region": "us-east-1", + "awslogs-stream-prefix": "nginx" + } + }, + "cpu": 0, + "memoryReservation": 512 + } + ] \ No newline at end of file diff --git a/modules/app-cluster/aws/app_ecs_task_role.tpl b/modules/app-cluster/aws/app_ecs_task_role.tpl index e69de29..014611f 100644 --- a/modules/app-cluster/aws/app_ecs_task_role.tpl +++ b/modules/app-cluster/aws/app_ecs_task_role.tpl @@ -0,0 +1,13 @@ +{ + "Version": "2012-10-17", + "Statement": [ + { + "Sid": "", + "Effect": "Allow", + "Principal": { + "Service": "ecs-tasks.amazonaws.com" + }, + "Action": "sts:AssumeRole" + } + ] +} \ No newline at end of file diff --git a/modules/app-cluster/aws/ecs_autoscale_role.tpl b/modules/app-cluster/aws/ecs_autoscale_role.tpl index e69de29..3acddba 100644 --- a/modules/app-cluster/aws/ecs_autoscale_role.tpl +++ b/modules/app-cluster/aws/ecs_autoscale_role.tpl @@ -0,0 +1,14 @@ +{ + "Version": "2012-10-17", + "Statement": [ + { + "Action": "sts:AssumeRole", + "Principal": { + "Service": [ + "application-autoscaling.amazonaws.com" + ] + }, + "Effect": "Allow" + } + ] +} \ No newline at end of file diff --git a/modules/app-cluster/aws/ecs_role.tpl b/modules/app-cluster/aws/ecs_role.tpl index e69de29..a662b99 100644 --- a/modules/app-cluster/aws/ecs_role.tpl +++ b/modules/app-cluster/aws/ecs_role.tpl @@ -0,0 +1,15 @@ +{ + "Version": "2008-10-17", + "Statement": [ + { + "Action": "sts:AssumeRole", + "Principal": { + "Service": [ + "ecs.amazonaws.com", + "ec2.amazonaws.com" + ] + }, + "Effect": "Allow" + } + ] +} \ No newline at end of file diff --git a/modules/app-cluster/aws/logs-policy.tpl b/modules/app-cluster/aws/logs-policy.tpl index e69de29..99776bc 100644 --- a/modules/app-cluster/aws/logs-policy.tpl +++ b/modules/app-cluster/aws/logs-policy.tpl @@ -0,0 +1,15 @@ +{ + "Id": "${var.project_name}-${terraform.workspace}-logs-policy", + "Version": "2012-10-17", + "Statement": [ + { + "Sid": "Stmt1484671540333", + "Action": "s3:PutObject", + "Effect": "Allow", + "Resource": "arn:aws:s3:::${var.project_name}-${terraform.workspace}-logs/*", + "Principal": { + "AWS": "arn:aws:iam::${lookup(var.default_log_account_ids, var.aws_region)}:root" + } + } + ] +} \ No newline at end of file diff --git a/modules/app-cluster/aws/main.tf b/modules/app-cluster/aws/main.tf index e69de29..8242166 100644 --- a/modules/app-cluster/aws/main.tf +++ b/modules/app-cluster/aws/main.tf @@ -0,0 +1,342 @@ +resource "aws_ecs_cluster" "cluster_app" { + name = "${terraform.workspace}-app" + + lifecycle { + create_before_destroy = true + } +} + +data "aws_ecs_task_definition" "magento2" { + task_definition = "${aws_ecs_task_definition.magento2.family}" + + depends_on = [ + "aws_ecs_task_definition.magento2", + ] +} + +/* Initial task definition - will be updated later by the deploy script */ +resource "aws_ecs_task_definition" "magento2" { + family = "${terraform.workspace}-magento2" + + container_definitions = < Date: Wed, 5 Sep 2018 13:56:11 +0300 Subject: [PATCH 5/8] Sorting out resources for the app-cluster --- modules/app-cluster/aws/main.tf | 627 +++++++++++++++------------ modules/app-cluster/aws/variables.tf | 10 + 2 files changed, 350 insertions(+), 287 deletions(-) diff --git a/modules/app-cluster/aws/main.tf b/modules/app-cluster/aws/main.tf index 8242166..1c604fe 100644 --- a/modules/app-cluster/aws/main.tf +++ b/modules/app-cluster/aws/main.tf @@ -1,342 +1,395 @@ -resource "aws_ecs_cluster" "cluster_app" { - name = "${terraform.workspace}-app" +#---------------------------------------- +# BrightFame APP-CLUSTER Terraform module +# +# version: x.x.x +# +# License: +# +#---------------------------------------- - lifecycle { - create_before_destroy = true - } +# AWS provider definition +provider "aws" { + region = "${var.aws_region}" + version = "${var.aws_provider_version" } -data "aws_ecs_task_definition" "magento2" { - task_definition = "${aws_ecs_task_definition.magento2.family}" +# //resource - aws_ecs_cluster - depends_on = [ - "aws_ecs_task_definition.magento2", - ] -} +# //resource - aws_ecs_task_definition -/* Initial task definition - will be updated later by the deploy script */ -resource "aws_ecs_task_definition" "magento2" { - family = "${terraform.workspace}-magento2" +# //resource - aws_ecs_service - container_definitions = < Date: Wed, 12 Sep 2018 08:21:20 +0300 Subject: [PATCH 6/8] fixing conflict --- modules/app-cluster/aws/README.md | 3 +++ modules/app-cluster/aws/main.tf | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/modules/app-cluster/aws/README.md b/modules/app-cluster/aws/README.md index e69de29..4cc90d4 100644 --- a/modules/app-cluster/aws/README.md +++ b/modules/app-cluster/aws/README.md @@ -0,0 +1,3 @@ +# ECS Service + +Deploy one or more Docker containers as a long-running ECS service. This module includes support for automated, zero-downtime deployment, auto-restart of crashed containers and integration with an Application Load Balancer (ALB). \ No newline at end of file diff --git a/modules/app-cluster/aws/main.tf b/modules/app-cluster/aws/main.tf index 1c604fe..ed9f28b 100644 --- a/modules/app-cluster/aws/main.tf +++ b/modules/app-cluster/aws/main.tf @@ -10,7 +10,7 @@ # AWS provider definition provider "aws" { region = "${var.aws_region}" - version = "${var.aws_provider_version" + version = "${var.aws_provider_version}" } # //resource - aws_ecs_cluster From 443db046d509f1a4e8bd45f4d4d2e578fdb550e8 Mon Sep 17 00:00:00 2001 From: Yuliyan Tsvetkov Date: Wed, 12 Sep 2018 08:33:01 +0300 Subject: [PATCH 7/8] Moving files into the new module folder --- modules/app-cluster/aws/README.md | 3 --- .../app-cluster/aws/{ => ecs-service}/app_ecs_service_role.tpl | 0 .../aws/{ => ecs-service}/app_ecs_task_definition_magento2.tpl | 0 .../app-cluster/aws/{ => ecs-service}/app_ecs_task_role.tpl | 0 .../app-cluster/aws/{ => ecs-service}/ecs_autoscale_role.tpl | 0 modules/app-cluster/aws/{ => ecs-service}/ecs_role.tpl | 0 modules/app-cluster/aws/{ => ecs-service}/logs-policy.tpl | 0 modules/app-cluster/aws/{ => ecs-service}/main.tf | 0 modules/app-cluster/aws/{ => ecs-service}/outputs.tf | 0 .../aws/{ => ecs-service}/template_app_ecs_user_data.tpl | 0 modules/app-cluster/aws/{ => ecs-service}/variables.tf | 0 11 files changed, 3 deletions(-) delete mode 100644 modules/app-cluster/aws/README.md rename modules/app-cluster/aws/{ => ecs-service}/app_ecs_service_role.tpl (100%) rename modules/app-cluster/aws/{ => ecs-service}/app_ecs_task_definition_magento2.tpl (100%) rename modules/app-cluster/aws/{ => ecs-service}/app_ecs_task_role.tpl (100%) rename modules/app-cluster/aws/{ => ecs-service}/ecs_autoscale_role.tpl (100%) rename modules/app-cluster/aws/{ => ecs-service}/ecs_role.tpl (100%) rename modules/app-cluster/aws/{ => ecs-service}/logs-policy.tpl (100%) rename modules/app-cluster/aws/{ => ecs-service}/main.tf (100%) rename modules/app-cluster/aws/{ => ecs-service}/outputs.tf (100%) rename modules/app-cluster/aws/{ => ecs-service}/template_app_ecs_user_data.tpl (100%) rename modules/app-cluster/aws/{ => ecs-service}/variables.tf (100%) diff --git a/modules/app-cluster/aws/README.md b/modules/app-cluster/aws/README.md deleted file mode 100644 index 4cc90d4..0000000 --- a/modules/app-cluster/aws/README.md +++ /dev/null @@ -1,3 +0,0 @@ -# ECS Service - -Deploy one or more Docker containers as a long-running ECS service. This module includes support for automated, zero-downtime deployment, auto-restart of crashed containers and integration with an Application Load Balancer (ALB). \ No newline at end of file diff --git a/modules/app-cluster/aws/app_ecs_service_role.tpl b/modules/app-cluster/aws/ecs-service/app_ecs_service_role.tpl similarity index 100% rename from modules/app-cluster/aws/app_ecs_service_role.tpl rename to modules/app-cluster/aws/ecs-service/app_ecs_service_role.tpl diff --git a/modules/app-cluster/aws/app_ecs_task_definition_magento2.tpl b/modules/app-cluster/aws/ecs-service/app_ecs_task_definition_magento2.tpl similarity index 100% rename from modules/app-cluster/aws/app_ecs_task_definition_magento2.tpl rename to modules/app-cluster/aws/ecs-service/app_ecs_task_definition_magento2.tpl diff --git a/modules/app-cluster/aws/app_ecs_task_role.tpl b/modules/app-cluster/aws/ecs-service/app_ecs_task_role.tpl similarity index 100% rename from modules/app-cluster/aws/app_ecs_task_role.tpl rename to modules/app-cluster/aws/ecs-service/app_ecs_task_role.tpl diff --git a/modules/app-cluster/aws/ecs_autoscale_role.tpl b/modules/app-cluster/aws/ecs-service/ecs_autoscale_role.tpl similarity index 100% rename from modules/app-cluster/aws/ecs_autoscale_role.tpl rename to modules/app-cluster/aws/ecs-service/ecs_autoscale_role.tpl diff --git a/modules/app-cluster/aws/ecs_role.tpl b/modules/app-cluster/aws/ecs-service/ecs_role.tpl similarity index 100% rename from modules/app-cluster/aws/ecs_role.tpl rename to modules/app-cluster/aws/ecs-service/ecs_role.tpl diff --git a/modules/app-cluster/aws/logs-policy.tpl b/modules/app-cluster/aws/ecs-service/logs-policy.tpl similarity index 100% rename from modules/app-cluster/aws/logs-policy.tpl rename to modules/app-cluster/aws/ecs-service/logs-policy.tpl diff --git a/modules/app-cluster/aws/main.tf b/modules/app-cluster/aws/ecs-service/main.tf similarity index 100% rename from modules/app-cluster/aws/main.tf rename to modules/app-cluster/aws/ecs-service/main.tf diff --git a/modules/app-cluster/aws/outputs.tf b/modules/app-cluster/aws/ecs-service/outputs.tf similarity index 100% rename from modules/app-cluster/aws/outputs.tf rename to modules/app-cluster/aws/ecs-service/outputs.tf diff --git a/modules/app-cluster/aws/template_app_ecs_user_data.tpl b/modules/app-cluster/aws/ecs-service/template_app_ecs_user_data.tpl similarity index 100% rename from modules/app-cluster/aws/template_app_ecs_user_data.tpl rename to modules/app-cluster/aws/ecs-service/template_app_ecs_user_data.tpl diff --git a/modules/app-cluster/aws/variables.tf b/modules/app-cluster/aws/ecs-service/variables.tf similarity index 100% rename from modules/app-cluster/aws/variables.tf rename to modules/app-cluster/aws/ecs-service/variables.tf From 20b4b3be70d32a5991d50eb0b39b093753bb0f21 Mon Sep 17 00:00:00 2001 From: Yuliyan Tsvetkov Date: Wed, 12 Sep 2018 08:35:59 +0300 Subject: [PATCH 8/8] Fixing structure --- configuration/app_ecs_service_role.tpl | 14 +++ .../app_ecs_task_definition_magento2.tpl | 95 +++++++++++++++++++ configuration/app_ecs_task_role.tpl | 13 +++ configuration/ecs_autoscale_role.tpl | 14 +++ configuration/ecs_role.tpl | 15 +++ configuration/logs-policy.tpl | 15 +++ configuration/template_app_ecs_user_data.tpl | 0 7 files changed, 166 insertions(+) create mode 100644 configuration/app_ecs_service_role.tpl create mode 100644 configuration/app_ecs_task_definition_magento2.tpl create mode 100644 configuration/app_ecs_task_role.tpl create mode 100644 configuration/ecs_autoscale_role.tpl create mode 100644 configuration/ecs_role.tpl create mode 100644 configuration/logs-policy.tpl create mode 100644 configuration/template_app_ecs_user_data.tpl diff --git a/configuration/app_ecs_service_role.tpl b/configuration/app_ecs_service_role.tpl new file mode 100644 index 0000000..99856ce --- /dev/null +++ b/configuration/app_ecs_service_role.tpl @@ -0,0 +1,14 @@ +{ + "Version": "2008-10-17", + "Statement": [ + { + "Action": "sts:AssumeRole", + "Principal": { + "Service": [ + "ecs.amazonaws.com" + ] + }, + "Effect": "Allow" + } + ] +} \ No newline at end of file diff --git a/configuration/app_ecs_task_definition_magento2.tpl b/configuration/app_ecs_task_definition_magento2.tpl new file mode 100644 index 0000000..9af3fe3 --- /dev/null +++ b/configuration/app_ecs_task_definition_magento2.tpl @@ -0,0 +1,95 @@ + [ + { + "name": "magento2", + "image": "${data.aws_ecr_repository.magento2.repository_url}", + "mountPoints": [ + { + "containerPath": "/var/www/html/pub/media", + "sourceVolume": "media", + "readOnly": null + } + ], + "essential": true, + "environment": [ + { + "name": "ENVIRONMENT", + "value": "${terraform.workspace}" + }, + { + "name": "MAGE_MODE", + "value": "production" + }, + { + "name": "CACHE_PREFIX", + "value": "1_" + }, + { + "name": "MYSQL_HOST", + "value": "${aws_route53_record.db.fqdn}" + }, + { + "name": "MYSQL_DATABASE", + "value": "${var.env_mysql_database}" + }, + { + "name": "MYSQL_USER", + "value": "${var.env_mysql_user}" + }, + { + "name": "MYSQL_PASSWORD", + "value": "${lookup(var.rds_password, terraform.workspace)}" + }, + { + "name": "REDIS_CACHE_HOST", + "value": "${aws_route53_record.redis_cache.fqdn}" + }, + { + "name": "REDIS_SESSION_HOST", + "value": "${aws_route53_record.redis_session.fqdn}" + } + ], + "logConfiguration": { + "logDriver": "awslogs", + "options": { + "awslogs-group": "${terraform.workspace}-app", + "awslogs-region": "us-east-1", + "awslogs-stream-prefix": "magento2" + } + }, + "cpu": 0, + "memoryReservation": 768 + }, + { + "name": "nginx", + "volumesFrom": [ + { + "readOnly": true, + "sourceContainer": "magento2" + } + ], + "portMappings": [ + { + "hostPort": 80, + "containerPort": 80, + "protocol": "tcp" + } + ], + "essential": true, + "environment": [], + "links": [ + "magento2:phpfpm" + ], + "image": "${data.aws_ecr_repository.nginx.repository_url}", + "command": [], + "logConfiguration": { + "logDriver": "awslogs", + "options": { + "awslogs-group": "${terraform.workspace}-app", + "awslogs-region": "us-east-1", + "awslogs-stream-prefix": "nginx" + } + }, + "cpu": 0, + "memoryReservation": 512 + } + ] \ No newline at end of file diff --git a/configuration/app_ecs_task_role.tpl b/configuration/app_ecs_task_role.tpl new file mode 100644 index 0000000..014611f --- /dev/null +++ b/configuration/app_ecs_task_role.tpl @@ -0,0 +1,13 @@ +{ + "Version": "2012-10-17", + "Statement": [ + { + "Sid": "", + "Effect": "Allow", + "Principal": { + "Service": "ecs-tasks.amazonaws.com" + }, + "Action": "sts:AssumeRole" + } + ] +} \ No newline at end of file diff --git a/configuration/ecs_autoscale_role.tpl b/configuration/ecs_autoscale_role.tpl new file mode 100644 index 0000000..3acddba --- /dev/null +++ b/configuration/ecs_autoscale_role.tpl @@ -0,0 +1,14 @@ +{ + "Version": "2012-10-17", + "Statement": [ + { + "Action": "sts:AssumeRole", + "Principal": { + "Service": [ + "application-autoscaling.amazonaws.com" + ] + }, + "Effect": "Allow" + } + ] +} \ No newline at end of file diff --git a/configuration/ecs_role.tpl b/configuration/ecs_role.tpl new file mode 100644 index 0000000..a662b99 --- /dev/null +++ b/configuration/ecs_role.tpl @@ -0,0 +1,15 @@ +{ + "Version": "2008-10-17", + "Statement": [ + { + "Action": "sts:AssumeRole", + "Principal": { + "Service": [ + "ecs.amazonaws.com", + "ec2.amazonaws.com" + ] + }, + "Effect": "Allow" + } + ] +} \ No newline at end of file diff --git a/configuration/logs-policy.tpl b/configuration/logs-policy.tpl new file mode 100644 index 0000000..99776bc --- /dev/null +++ b/configuration/logs-policy.tpl @@ -0,0 +1,15 @@ +{ + "Id": "${var.project_name}-${terraform.workspace}-logs-policy", + "Version": "2012-10-17", + "Statement": [ + { + "Sid": "Stmt1484671540333", + "Action": "s3:PutObject", + "Effect": "Allow", + "Resource": "arn:aws:s3:::${var.project_name}-${terraform.workspace}-logs/*", + "Principal": { + "AWS": "arn:aws:iam::${lookup(var.default_log_account_ids, var.aws_region)}:root" + } + } + ] +} \ No newline at end of file diff --git a/configuration/template_app_ecs_user_data.tpl b/configuration/template_app_ecs_user_data.tpl new file mode 100644 index 0000000..e69de29