{"id":13451718,"url":"https://github.com/benediktkr/aws-demo","last_synced_at":"2025-03-23T19:32:29.080Z","repository":{"id":68324871,"uuid":"110266940","full_name":"benediktkr/aws-demo","owner":"benediktkr","description":null,"archived":false,"fork":false,"pushed_at":"2017-11-17T13:10:28.000Z","size":42,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-07-02T14:46:45.602Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"HCL","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/benediktkr.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2017-11-10T16:15:08.000Z","updated_at":"2023-08-01T18:49:03.000Z","dependencies_parsed_at":null,"dependency_job_id":"433e78bf-2565-45b0-a07c-009ad4f85c3a","html_url":"https://github.com/benediktkr/aws-demo","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/benediktkr%2Faws-demo","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/benediktkr%2Faws-demo/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/benediktkr%2Faws-demo/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/benediktkr%2Faws-demo/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/benediktkr","download_url":"https://codeload.github.com/benediktkr/aws-demo/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":213325073,"owners_count":15570230,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-07-31T07:01:00.289Z","updated_at":"2024-07-31T07:04:02.098Z","avatar_url":"https://github.com/benediktkr.png","language":"HCL","funding_links":[],"categories":["HCL"],"sub_categories":[],"readme":"# aws-demo\n\nThis is a demo of how to set up a Docker Swarm in AWS.\n\n![the cloud](http://s2.quickmeme.com/img/a7/a736c13ea9c5ad4687ceaf214c95ba2b61c41805e1e5a73877f5fd6924abd6dc.jpg)\n\n## What it does\n\nThis repo uses Terraform to deploy a EC2 instances onto a VPC in AWS, with subnets in multiple AZs. Then it uses Ansible to provision a Docker Swarm on the nodes and then deploys the [joshuaconner/hello-world-docker-bottle](https://github.com/joshuaconner/hello-world-docker-bottle) container on the swarm. Terraform also creates an ELB to serve HTTP traffic to and from the container.\n\n## Configure\n\nThe AWS creditials are read from `~/.aws/credentials`, rather than being kept in a `.tf` file. Use `aws configure` (install `aws-cli` with pip) to configure this.\n\nFor settings, take a look at `tf/stack.tf`. The format is not ideal, but you'll find the following (relatively self-explanatory) settings there, as well as the public key used for the instances.\n\n```hcl\nresource \"aws_key_pair\" \"ben_key_pair\" {\n  key_name = \"ben_key_pair\"\n  public_key = \"ssh-rsa AAAAB3NzaC1y[...]ndqOEQ== benedikt@mathom\"\n}\n\nvariable \"domainname\" {\n  default = \"aws-demo.sudo.is\"\n}\n\nvariable \"node_count\" {\n  default = 5\n}\n\nvariable \"manager_count\" {\n  default = 3\n}\n\nvariable \"instance_type\" {\n  default = \"t2.nano\"\n}\n\nvariable \"hello-world-app\" {\n  default = {\n    name = \"joshuaconner/hello-world-docker-bottle\"\n    port = 8080\n  }\n}\n```\n\n## How to run\n\nJust run terraform!\n\n```shell\naws-demo$ terraform apply tf/\n[....]\nOutputs:\n\nelb-dns = [\n    aws-demo-helloworld-847708057.eu-central-1.elb.amazonaws.com,\n    helloworld.aws-demo.sudo.is\n]\nnodes-private-ips = [\n    10.200.0.10,\n    10.200.1.11,\n    10.200.0.12,\n    10.200.1.13,\n    10.200.0.14\n]\nnodes-public-ips = [\n    54.93.155.184,\n    54.93.50.56,\n    54.93.241.144,\n    18.195.88.249,\n    54.93.194.250\n]\nns-servers = [\n    ns-1319.awsdns-36.org,\n    ns-1542.awsdns-00.co.uk,\n    ns-62.awsdns-07.com,\n    ns-748.awsdns-29.net\n]\n```\n\nThe nameservers are outputted since because it's assumed that the domain used is a subdoamain, and need to be delegated to AWS. Here is what the zone file should look like to delegate it:\n\n```bind\naws-demo.sudo.is.\tNS\tns-1319.awsdns-36.org.\naws-demo.sudo.is.\tNS\tns-1512.awsdns-00.co.uk.\naws-demo.sudo.is.\tNS\tns-62.awsdns-07.com.\naws-demo.sudo.is.\tNS\tns-748.awsdns-29.net.\n```\n\nIf the domain is delegated with the `NS` records correct, you can use the DNS name to SSH to one of the instances to check that everything is working as supposed (otherwise you can use the IP outputed by terraform).\n\n```shell\naws-demo$ ssh swarm-node-1.aws-demo.sudo.is\nubuntu@swarm-node-0:~$ sudo docker node ls\nID                            HOSTNAME            STATUS              AVAILABILITY        MANAGER STATUS\n1nfhj6nuv3z9xnlug91my15h0     swarm-node-3        Ready               Active\n7t5swjgnqu9d3rzh7blven66m     swarm-node-4        Ready               Active\n9mpyjxznwf5tdawrlv8xxfwo8     swarm-node-2        Ready               Active              Reachable\ngumqc06pqtn6vnnoa1fxs5bt0 *   swarm-node-0        Ready               Active              Leader\nn2fflejq35acvil36xsh6ashy     swarm-node-1        Ready               Active              Reachable\nubuntu@swarm-node-0:~$ sudo docker service ls\nID                  NAME                MODE                REPLICAS            IMAGE                                           PORTS\nuacq5t6tbaut        unruffled_khorana   replicated          5/5                 joshuaconner/hello-world-docker-bottle:latest   *:8080-\u003e8080/tcp\n\n```\n\nThen we can verify that the app answers\n\n```shell\naws-demo$ curl http://helloworld.aws-demo.sudo.is/\nHello World!\n```\n\nIf you haven't delegated the subdomain, you should use the ELBs public dns name, in this case `aws-demo-helloworld-847708057.eu-central-1.elb.amazonaws.com`.\n\n# Improvements\n\nI tried to keep all of the logic in Terraform, but it feels like it belongs somewhere else --- even independently. Also, it would be better if you could just specify a total number of nodes, and an automatically correct ratio of managers/workers would be selected automatically.\n\nThe `local-exec` command that invokes Ansible is terribly messy and has handcrafted JSON. Also, due to limitations in Terraform, you can only configure one app in `stack.tf` to start on the swarm, but the Ansible code handles a list of apps. It might be better to have that part of the configuration in Ansible and not Terraform\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbenediktkr%2Faws-demo","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbenediktkr%2Faws-demo","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbenediktkr%2Faws-demo/lists"}