diff --git a/tests/ci/Makefile b/tests/ci/Makefile index 08a9eb87..4b10e51a 100644 --- a/tests/ci/Makefile +++ b/tests/ci/Makefile @@ -1,14 +1,15 @@ .PHONY: test deploy rollback refresh deploy-no-update-service scale down delete help run-task status export CLUSTER := ecspresso-test -export SERVICE := nginx-$(CIRCLE_BRANCH) +export SERVICE := nginx +# export TFSTATE_BUCKET := ecspresso-test export NOW := $(shell date +%Y%m%d%H%M%S) export CLIENT_TOKEN := $(shell uuidgen) ECSPRESSO := ecspresso --envfile envfile help: -test: verify deploy tasks diff revisions run-task deploy rollback refresh deploy-no-update-service scale down up delete +test: diff verify deploy tasks diff revisions run-task deploy rollback refresh deploy-no-update-service scale down up delete status: $(ECSPRESSO) status --events 10 --debug @@ -89,3 +90,8 @@ revisions: $(ECSPRESSO) revisions $(ECSPRESSO) revisions --revision=current $(ECSPRESSO) revisions --revision=latest + +render: + $(ECSPRESSO) render config + $(ECSPRESSO) render servicedef + $(ECSPRESSO) render taskdef diff --git a/tests/ci/ecspresso.yml b/tests/ci/ecspresso.yml index 57b85324..c94598bd 100644 --- a/tests/ci/ecspresso.yml +++ b/tests/ci/ecspresso.yml @@ -4,3 +4,9 @@ service: "{{ must_env `SERVICE` }}" service_definition: ecs-service-def.json task_definition: ecs-task-def.json timeout: 10m0s +plugins: +{{ if (env `TFSTATE_BUCKET` ``) }} + - name: tfstate + config: + url: "s3://{{ must_env `TFSTATE_BUCKET` }}/terraform.tfstate" +{{ end }} diff --git a/tests/ci/terraform.tfstate b/tests/ci/terraform.tfstate new file mode 100644 index 00000000..cda4b824 --- /dev/null +++ b/tests/ci/terraform.tfstate @@ -0,0 +1,559 @@ +{ + "version": 4, + "terraform_version": "0.12.16", + "serial": 173, + "lineage": "054d7292-3d84-0584-4590-24d6f3b17399", + "outputs": { + "foo": { + "value": "FOO", + "type": "string" + }, + "bar": { + "value": [ + "A", + "B", + "C" + ], + "type": [ + "tuple", + [ + "string", + "string", + "string" + ] + ] + } + }, + "resources": [ + { + "mode": "data", + "type": "terraform_remote_state", + "name": "remote", + "provider": "provider[\"terraform.io/builtin/terraform\"]", + "instances": [ + { + "schema_version": 0, + "attributes": { + "backend": "local", + "defaults": null, + "outputs": { + "value": { + "kms_key": { + "arn": "arn:aws:kms:ap-northeast-1:123456789012:key/500193e3-ddd9-4581-ab0c-fd7aeaedf3e1", + "customer_master_key_spec": "SYMMETRIC_DEFAULT", + "deletion_window_in_days": null, + "description": "my kms key", + "enable_key_rotation": false, + "id": "500193e3-ddd9-4581-ab0c-fd7aeaedf3e1", + "is_enabled": true, + "key_id": "500193e3-ddd9-4581-ab0c-fd7aeaedf3e1", + "key_usage": "ENCRYPT_DECRYPT", + "policy": "{}", + "tags": { + "env": "remote" + } + }, + "kms_key_arn": "arn:aws:kms:ap-northeast-1:123456789012:key/500193e3-ddd9-4581-ab0c-fd7aeaedf3e1", + "mylist": [ + 1, + 2, + 3 + ] + }, + "type": [ + "object", + { + "kms_key": [ + "object", + { + "arn": "string", + "customer_master_key_spec": "string", + "deletion_window_in_days": "number", + "description": "string", + "enable_key_rotation": "bool", + "id": "string", + "is_enabled": "bool", + "key_id": "string", + "key_usage": "string", + "policy": "string", + "tags": [ + "map", + "string" + ] + } + ], + "kms_key_arn": "string", + "mylist": [ + "tuple", + [ + "number", + "number", + "number" + ] + ] + } + ] + }, + "workspace": null + }, + "sensitive_attributes": [] + } + ] + }, + { + "mode": "data", + "type": "aws_caller_identity", + "name": "current", + "provider": "provider.aws", + "instances": [ + { + "schema_version": 0, + "attributes": { + "account_id": "123456789012", + "arn": "arn:aws:sts::123456789012:assumed-role/foo/1583745336520988000", + "id": "2020-03-09 09:16:00.754235 +0000 UTC", + "user_id": "xxxxxxx:1583745336520988000" + } + } + ] + }, + { + "mode": "managed", + "type": "aws_acm_certificate", + "name": "main", + "provider": "provider.aws", + "instances": [ + { + "attributes": { + "arn": "arn:aws:acm:ap-northeast-1:123456789012:certificate/4986a36e-7027-4265-864b-1fe32f96d774", + "certificate_authority_arn": "", + "certificate_body": null, + "certificate_chain": null, + "domain_name": "example.com", + "domain_validation_options": [ + { + "domain_name": "example.com", + "resource_record_name": "_6a89c060c6b487799746d5764bfaf659.example.com.", + "resource_record_type": "CNAME", + "resource_record_value": "_2c68f3a12a12fd1c8504175708b95a72.abcdefg.acm-validations.aws." + }, + { + "domain_name": "*.example.com", + "resource_record_name": "_6a89c060c6b487799746d5764bfaf659.example.com.", + "resource_record_type": "CNAME", + "resource_record_value": "_2c68f3a12a12fd1c8504175708b95a72.abcdefg.acm-validations.aws." + } + ], + "id": "arn:aws:acm:ap-northeast-1:123456789012:certificate/8f10da5e-d173-4891-a9d3-1309fa6ff4f4", + "options": [ + { + "certificate_transparency_logging_preference": "ENABLED" + } + ], + "private_key": null, + "subject_alternative_names": [ + "*.example.com" + ], + "tags": { + "env": "world" + }, + "validation_emails": [], + "validation_method": "DNS" + }, + "private": "bnVsbA==" + } + ] + }, + { + "module": "module.logs", + "mode": "managed", + "type": "aws_cloudwatch_log_group", + "name": "main", + "each": "map", + "provider": "provider.aws", + "instances": [ + { + "schema_version": 0, + "attributes": { + "arn": "arn:aws:logs:ap-northeast-1:123456789012:log-group:/main/vanish:*", + "id": "/main/vanish", + "kms_key_id": "", + "name": "/main/vanish", + "name_prefix": null, + "retention_in_days": 30, + "tags": { + "env": "world" + } + }, + "private": "bnVsbA==" + }, + { + "index_key": "app", + "schema_version": 0, + "attributes": { + "arn": "arn:aws:logs:ap-northeast-1:123456789012:log-group:/main/app:*", + "id": "/main/app", + "kms_key_id": "", + "name": "/main/app", + "name_prefix": null, + "retention_in_days": 30, + "tags": { + "env": "world" + } + }, + "private": "bnVsbA==" + }, + { + "index_key": "web", + "schema_version": 0, + "attributes": { + "arn": "arn:aws:logs:ap-northeast-1:123456789012:log-group:/main/web:*", + "id": "/main/web", + "kms_key_id": "", + "name": "/main/web", + "name_prefix": null, + "retention_in_days": 30, + "tags": { + "env": "world" + } + }, + "private": "bnVsbA==" + } + ] + }, + { + "mode": "managed", + "type": "aws_iam_role_policy_attachment", + "name": "ec2", + "each": "list", + "provider": "provider.aws", + "instances": [ + { + "index_key": 0, + "schema_version": 0, + "attributes": { + "id": "ec2-20190801065413533200000002", + "policy_arn": "arn:aws:iam::aws:policy/AmazonS3ReadOnlyAccess", + "role": "ec2" + }, + "private": "bnVsbA==" + }, + { + "index_key": 1, + "schema_version": 0, + "attributes": { + "id": "ec2-20190801065413531100000001", + "policy_arn": "arn:aws:iam::aws:policy/AmazonEC2ContainerRegistryPowerUser", + "role": "ec2" + }, + "private": "bnVsbA==" + } + ] + }, + { + "module": "module.webapp.module.ecs_task_roles", + "mode": "managed", + "type": "aws_iam_role", + "name": "task_execution_role", + "provider": "provider.aws", + "instances": [ + { + "schema_version": 0, + "attributes": { + "arn": "arn:aws:iam::123456789012:role/task-execution-role", + "assume_role_policy": "{\"Version\":\"2012-10-17\",\"Statement\":[{\"Sid\":\"\",\"Effect\":\"Allow\",\"Principal\":{\"Service\":\"ecs-tasks.amazonaws.com\"},\"Action\":\"sts:AssumeRole\"}]}", + "create_date": "2019-11-18T07:57:06Z", + "description": "", + "force_detach_policies": false, + "id": "task-execution-role", + "max_session_duration": 3600, + "name": "task-execution-role", + "name_prefix": null, + "path": "/", + "permissions_boundary": null, + "tags": {}, + "unique_id": "AAAAAAAAAAAA" + }, + "private": "bnVsbA==" + } + ] + }, + { + "module": "module.subnets", + "mode": "managed", + "type": "aws_subnet", + "name": "main", + "provider": "provider[\"registry.terraform.io/hashicorp/aws\"]", + "instances": [ + { + "index_key": 0, + "schema_version": 1, + "attributes": { + "arn": "arn:aws:ec2:ap-northeast-1:123456789012:subnet/subnet-01234567890123456", + "assign_ipv6_address_on_creation": false, + "availability_zone": "ap-northeast-1a", + "availability_zone_id": "apne1-az4", + "cidr_block": "10.11.12.0/22", + "id": "subnet-01234567890123456", + "ipv6_cidr_block": "", + "ipv6_cidr_block_association_id": "", + "map_public_ip_on_launch": false, + "outpost_arn": "", + "owner_id": "012345678901", + "tags": {}, + "timeouts": null, + "vpc_id": "vpc-01234567" + }, + "private": "bnVsbA==" + }, + { + "index_key": 1, + "schema_version": 1, + "attributes": { + "arn": "arn:aws:ec2:ap-northeast-1:123456789012:subnet/subnet-90123456789012345", + "assign_ipv6_address_on_creation": false, + "availability_zone": "ap-northeast-1a", + "availability_zone_id": "apne1-az4", + "cidr_block": "10.11.15.0/22", + "id": "subnet-90123456789012345", + "ipv6_cidr_block": "", + "ipv6_cidr_block_association_id": "", + "map_public_ip_on_launch": false, + "outpost_arn": "", + "owner_id": "012345678901", + "tags": {}, + "timeouts": null, + "vpc_id": "vpc-01234567" + }, + "private": "bnVsbA==" + } + ] + }, + { + "mode": "managed", + "type": "aws_iam_user", + "name": "users", + "provider": "provider[\"registry.terraform.io/hashicorp/aws\"]", + "instances": [ + { + "index_key": "foo.bar", + "schema_version": 0, + "attributes": { + "arn": "arn:aws:iam::xxxxxxxxxxxx:user/foo.bar", + "force_destroy": false, + "id": "foo.bar", + "name": "foo.bar", + "path": "/", + "permissions_boundary": null, + "tags": {}, + "unique_id": "XXXXXXXXXXXXXXXXXXXXX" + }, + "private": "bnVsbA==" + }, + { + "index_key": "hoge.fuga", + "schema_version": 0, + "attributes": { + "arn": "arn:aws:iam::xxxxxxxxxxxx:user/hoge.fuga", + "force_destroy": false, + "id": "hoge.fuga", + "name": "hoge.fuga", + "path": "/", + "permissions_boundary": null, + "tags": {}, + "unique_id": "XXXXXXXXXXXXXXXXXXXXX" + }, + "private": "bnVsbA==" + } + ] + }, + { + "mode": "managed", + "type": "aws_iam_user", + "name": "user", + "provider": "provider[\"registry.terraform.io/hashicorp/aws\"]", + "instances": [ + { + "index_key": "me", + "schema_version": 0, + "attributes": { + "arn": "arn:aws:iam::xxxxxxxxxxxx:user/me", + "force_destroy": false, + "id": "me", + "name": "me", + "path": "/", + "permissions_boundary": null, + "tags": {}, + "unique_id": "XXXXXXXXXXXXXXXXXXXXX" + }, + "private": "bnVsbA==" + } + ] + }, + { + "mode": "data", + "type": "aws_lb_target_group", + "name": "app", + "each": "map", + "provider": "provider.aws", + "instances": [ + { + "index_key": "dev1", + "schema_version": 0, + "attributes": { + "arn": "arn:aws:elasticloadbalancing:ap-northeast-1:123456789012:targetgroup/dev-dev1-app/d122c303215d2e0c", + "arn_suffix": "targetgroup/dev-dev1-app/d122c303215d2e0c", + "deregistration_delay": 300, + "health_check": [ + { + "enabled": true, + "healthy_threshold": 2, + "interval": 5, + "matcher": "", + "path": "/AWS.ALB/healthcheck", + "port": "traffic-port", + "protocol": "HTTP", + "timeout": 3, + "unhealthy_threshold": 10 + } + ], + "id": "arn:aws:elasticloadbalancing:ap-northeast-1:123456789012:targetgroup/dev-dev1-app/d122c303215d2e0c", + "lambda_multi_value_headers_enabled": null, + "load_balancing_algorithm_type": "round_robin", + "name": "dev-dev1-app", + "port": 8080, + "protocol": "HTTP", + "proxy_protocol_v2": null, + "slow_start": 0, + "stickiness": [ + { + "cookie_duration": 86400, + "enabled": false, + "type": "lb_cookie" + } + ], + "tags": {}, + "target_type": "ip", + "vpc_id": "vpc-00435ca4ee84a4fb9" + } + }, + { + "index_key": "dev2", + "schema_version": 0, + "attributes": { + "arn": "arn:aws:elasticloadbalancing:ap-northeast-1:123456789012:targetgroup/dev-dev2-app/3c09e9a755f72d26", + "arn_suffix": "targetgroup/dev-dev2-app/3c09e9a755f72d26", + "deregistration_delay": 300, + "health_check": [ + { + "enabled": true, + "healthy_threshold": 2, + "interval": 5, + "matcher": "", + "path": "/AWS.ALB/healthcheck", + "port": "traffic-port", + "protocol": "HTTP", + "timeout": 3, + "unhealthy_threshold": 10 + } + ], + "id": "arn:aws:elasticloadbalancing:ap-northeast-1:123456789012:targetgroup/dev-dev2-app/3c09e9a755f72d26", + "lambda_multi_value_headers_enabled": null, + "load_balancing_algorithm_type": "round_robin", + "name": "dev-dev2-app", + "port": 8080, + "protocol": "HTTP", + "proxy_protocol_v2": null, + "slow_start": 0, + "stickiness": [ + { + "cookie_duration": 86400, + "enabled": false, + "type": "lb_cookie" + } + ], + "tags": {}, + "target_type": "ip", + "vpc_id": "vpc-00435ca4ee84a4fb9" + } + }, + { + "index_key": "dev3", + "schema_version": 0, + "attributes": { + "arn": "arn:aws:elasticloadbalancing:ap-northeast-1:123456789012:targetgroup/dev-dev3-app/aa3a78fa94b2b463", + "arn_suffix": "targetgroup/dev-dev3-app/aa3a78fa94b2b463", + "deregistration_delay": 300, + "health_check": [ + { + "enabled": true, + "healthy_threshold": 2, + "interval": 5, + "matcher": "", + "path": "/AWS.ALB/healthcheck", + "port": "traffic-port", + "protocol": "HTTP", + "timeout": 3, + "unhealthy_threshold": 10 + } + ], + "id": "arn:aws:elasticloadbalancing:ap-northeast-1:123456789012:targetgroup/dev-dev3-app/aa3a78fa94b2b463", + "lambda_multi_value_headers_enabled": null, + "load_balancing_algorithm_type": "round_robin", + "name": "dev-dev3-app", + "port": 8080, + "protocol": "HTTP", + "proxy_protocol_v2": null, + "slow_start": 0, + "stickiness": [ + { + "cookie_duration": 86400, + "enabled": false, + "type": "lb_cookie" + } + ], + "tags": {}, + "target_type": "ip", + "vpc_id": "vpc-00435ca4ee84a4fb9" + } + } + ] + }, + { + "module": "module.example", + "mode": "managed", + "type": "aws_vpc", + "name": "example", + "provider": "provider.aws", + "instances": [] + }, + { + "mode": "data", + "type": "terraform_remote_state", + "name": "hyphenated-id", + "provider": "provider[\"terraform.io/builtin/terraform\"]", + "instances": [ + { + "schema_version": 0, + "attributes": { + "backend": "local", + "defaults": null, + "outputs": { + "value": { + "repository-uri": "123456789012.dkr.ecr.ap-northeast-1.amazonaws.com/app" + }, + "type": [ + "object", + { + "repository-uri": "string" + } + ] + }, + "workspace": null + }, + "sensitive_attributes": [] + } + ] + } + ] +}