{"id":13753860,"url":"https://github.com/express42/terraform-ansible-example","last_synced_at":"2026-03-10T11:06:53.635Z","repository":{"id":44344555,"uuid":"88597832","full_name":"express42/terraform-ansible-example","owner":"express42","description":"Quick start on how to provision with ansible inside terraform","archived":false,"fork":false,"pushed_at":"2022-07-09T10:53:39.000Z","size":52,"stargazers_count":80,"open_issues_count":6,"forks_count":50,"subscribers_count":24,"default_branch":"master","last_synced_at":"2025-05-17T00:33:36.875Z","etag":null,"topics":["ansible","terraform"],"latest_commit_sha":null,"homepage":null,"language":"Python","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/express42.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}},"created_at":"2017-04-18T07:54:10.000Z","updated_at":"2025-04-06T14:22:20.000Z","dependencies_parsed_at":"2022-09-16T08:52:00.778Z","dependency_job_id":null,"html_url":"https://github.com/express42/terraform-ansible-example","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/express42/terraform-ansible-example","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/express42%2Fterraform-ansible-example","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/express42%2Fterraform-ansible-example/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/express42%2Fterraform-ansible-example/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/express42%2Fterraform-ansible-example/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/express42","download_url":"https://codeload.github.com/express42/terraform-ansible-example/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/express42%2Fterraform-ansible-example/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30331658,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-10T05:25:20.737Z","status":"ssl_error","status_checked_at":"2026-03-10T05:25:17.430Z","response_time":106,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["ansible","terraform"],"created_at":"2024-08-03T09:01:31.742Z","updated_at":"2026-03-10T11:06:53.615Z","avatar_url":"https://github.com/express42.png","language":"Python","funding_links":[],"categories":["terraform"],"sub_categories":[],"readme":"# terraform-ansible-example\nQuick start on how to provision with ansible inside terraform\n\n## Project structure\n* ansible - folder with ansible playbooks, inventories and configuration\n* terraform - folder with terraform infrastructure files\n\n## Getting stated\nPrepend environment for using ansible dynamic inventory with Amazon ec2:\n```\n$ pip install boto\n$ chmod +x ansible/ec2.py\n```\nOf course, you'll need to have AWS credentials. By default you can find it in  ~/.aws/credentials\n```\n$ cat ~/.aws/credentials\n[default]\naws_access_key_id = \u003cAWS_ACCESS_TOKEN\u003e\naws_secret_access_key = \u003cAWS_SECRET_ACCESS_KEY\u003e\n...\n```\n\nIn file ansible/ec2.ini define your regions:\n```\n...\nregions = eu-central-1\nregions_exclude = us-gov-west-1, cn-north-1\n...\n```\n\n## Usage\nif you want just up example infrastructure you need set your variables in .tfvars files\n```\npub_key_path = \"~/.ssh/express42.pub\"\nprivate_key_path = \"~/.ssh/express42\"\nkey_name = \"astarostenko\"\nenv = \"astarostenko\"\n```\n\nGo to terraform folder and download all modules to .terraform folder (for local modules it just creates symlinks)\n```\n$ cd terraform\n$ terraform get\n```\n\nIf your want to see plan of your own infrastructure\n\n```\n$ terraform plan\nRefreshing Terraform state in-memory prior to plan...\nThe refreshed state will be used to calculate this plan, but will not be\npersisted to local or remote state storage.\n\ndata.aws_ami.image: Refreshing state...\nThe Terraform execution plan has been generated and is shown below.\nResources are shown in alphabetical order for quick scanning. Green resources\nwill be created (or destroyed and then created if an existing resource\nexists), yellow resources are being changed in-place, and red resources\nwill be destroyed. Cyan entries are data sources to be read.\n\nNote: You didn't specify an \"-out\" parameter to save this plan, so when\n\"apply\" is called, Terraform can't guarantee this is what will execute.\n\n+ null_resource.ansible_db\n\n+ null_resource.ansible_web\n\n+ module.db.aws_instance.db\n...\n...\n...\nPlan: 9 to add, 0 to change, 0 to destroy.\n\n```\nTo create all resources and provision all services\n```\n$ terraform apply\n```\nTo delete all created resources\n```\n$ terraform destroy\n```\n# Terraform structure\n\n#### main.tf - contain general infrastructure description\nWe describe used provider, can create resources, call some modules, and can also define provision  \naction\n```\nprovider \"aws\" {\n  region = \"${var.region}\"\n}\n...\nmodule \"base_linux\" {\n  source = \"./modules/base\"\n}\n...\nresource null_resource \"ansible_web\" {\n  depends_on = [\"module.web\"]\n\n  provisioner \"local-exec\" {\n    command = \"cd ../ansible \u0026\u0026 ansible-playbook playbooks/apache.yml -e env=${var.env} -e group_name=${var.web_server_params[\"name\"]}\"\n  }\n}\n...\n```\n\n\n#### variables.tf - define all required variables, its description(optional) default values(optional)\n\nThere are three types of variables in terraform:\n\n* string\n```\nvariable \"string_var_name\" {\n    default = \"string_value\"\n}\n```\n* map\n```\nvariable \"map_var_name\" {\n    default = {\n      key-1 = \"image-1234\"\n      key-2 = \"image-4567\"\n}\n```\n* list\n```\nvariable \"list_var_name\" {\n    default = [\"us-east-1a\", \"us-east-1b\"]\n}\n```\n\nVariables can be defined in\n* variables.tf or any other .tf file\n```\n  variable env {\n    description = \"current environment (dev, prod, stage)\"\n    default = \"dev\"\n  }\n```\nYou can just create it but not define in .tf file, but then you'll need to define it anywhere\n  ```\n    variable \"name\" {}\n  ```\n\n* terraform.tfvars (default) or any other .tfvars file with flag -var-file\n```\n$ terraform plan \\\n  -var-file=\"secret.tfvars\" \\\n  -var-file=\"production.tfvars\"\n```\n* input argument to terraform with flag -var\n```\n$ terraform plan -var 'access_key=foo'\n```\n\n[More information about variables](https://www.terraform.io/docs/configuration/variables.html)\n\n#### outputs.tf - define all important output data like variables\n\n```\noutput \"web_address\" {\n  value = \"${module.web.public_ip}\"\n}\n```\n\n#### modules/\nModules are used in Terraform to modularize and encapsulate groups of resources in your infrastructure.\nEvery module is a little terraform project - it can contain its own variables and outputs\n\nModule structure:\n* base - module used in every infrastructure\n* key_pair - upload public keys to cloud provider\n* db - build database resources\n* web - build web-service resources\n\nWe can use module just like:\n```\n  module \"exemplar_name\" {\n    source ./modules/web\n    name = server_name\n    env = \"${var.env_name}\"\n  }\n```\n[More information about modules](https://www.terraform.io/docs/modules/index.html)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fexpress42%2Fterraform-ansible-example","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fexpress42%2Fterraform-ansible-example","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fexpress42%2Fterraform-ansible-example/lists"}