{"id":13516339,"url":"https://github.com/Genaker/TerraformMagentoCloud","last_synced_at":"2025-03-31T06:30:34.978Z","repository":{"id":35463292,"uuid":"209696735","full_name":"Genaker/TerraformMagentoCloud","owner":"Genaker","description":"AWS Magento 2 cloud Terraform infrastructure as code. For any systems WordPress / WooCommerce/ Drupal / Shopware 6 / Shopify APP / VueStorefront / Oddo / ORO / Magento 2 with horizontal Auto scaling (platform agnostic)","archived":false,"fork":false,"pushed_at":"2024-01-29T20:20:27.000Z","size":2162,"stargazers_count":229,"open_issues_count":11,"forks_count":85,"subscribers_count":27,"default_branch":"master","last_synced_at":"2025-03-22T08:53:11.953Z","etag":null,"topics":["amazon-web-services","aws","cloud","magento","magento2","terraform","terraform-module"],"latest_commit_sha":null,"homepage":"","language":"HCL","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Genaker.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-09-20T03:23:48.000Z","updated_at":"2025-02-27T16:43:13.000Z","dependencies_parsed_at":"2024-09-26T19:00:25.567Z","dependency_job_id":"118397bc-9e61-4897-a976-c47eeb7d26d2","html_url":"https://github.com/Genaker/TerraformMagentoCloud","commit_stats":{"total_commits":146,"total_committers":9,"mean_commits":16.22222222222222,"dds":"0.12328767123287676","last_synced_commit":"d692635b7d2de059cb85e697416ddd795527beb4"},"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Genaker%2FTerraformMagentoCloud","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Genaker%2FTerraformMagentoCloud/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Genaker%2FTerraformMagentoCloud/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Genaker%2FTerraformMagentoCloud/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Genaker","download_url":"https://codeload.github.com/Genaker/TerraformMagentoCloud/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246308051,"owners_count":20756482,"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":["amazon-web-services","aws","cloud","magento","magento2","terraform","terraform-module"],"created_at":"2024-08-01T05:01:21.465Z","updated_at":"2025-03-31T06:30:34.933Z","avatar_url":"https://github.com/Genaker.png","language":"HCL","funding_links":[],"categories":["HCL"],"sub_categories":[],"readme":"# Infrastructure as code for eCommerce Cloud Architecture on AWS (Multi Cloud AWS,GCP,Azure)\n\nThis repository contains Magento 2 Cloud Terraform infrastructure as code for AWS Public Cloud.\n\nThis infrastructure is the result of years of experience scaling Magento 1 and 2 in the cloud. It comes with the best cloud development practices baked in to save your time and money.\n\nLeveraging your own AWS Account dramatically reduces your monthly spend vs. paying an expensive managed hosting provider (PaaS, SaaS).\n\nThis script is not limited to Magento deployments and can be used with any eCommerce/Web platform, eg. WordPress, WooCommerce, Drupal, Shopware 6, Shopify APP (Custum Private APP cloud), VueStorefront, Silyus, Oddo, ORO etc. It includes Magento in the name because it was designed for Magento at first. There are however projects using it to run Enterprise Java applications with auto scaling.\n\nIf you have any questions feel free to send me an email – yegorshytikov@gmail.com\n\n# Important!!!\n\nMagento Software installation is out of the scope of this Project. This Repository is just an example of the AWS infrastructure provisioning for Magento using Terraform. Please refer to our another project to Install Magento 2 on Centos 8 or Amazon Linux 2 x86/ARM Linux: \n\n**Magento 2 Installation Automation (Centos 8.2, Amazon Linux 2 with ARM support) GitHub repository:**\n[Magento installation Script] (https://github.com/Genaker/Magento-AWS-Linux-2-Instalation).\n\nGraviton 2 ARM instances are also supported. \n\n\n# Why Auto Scaling \n\nIncreasing the number of PHP-FPM processes beyond the number of physical processor cores does not improve performance, rather is likely to degrade it, and can consume resources needlessly. Basic rule for the web is:\n\nCPU(physical) = (Concurrent HTTP REquest * http_req_duration)\n\nBe careful Intel CPUs are virtual and actual number of CPUs factor = 2; AWS Graviton2 ARM64 CPUs have factor 1 and are better for concurrent request processing. \nIntel CPUs have some advantages of 20-30% in some cases, however for magento (long heavy queries) physical cores are better. With higher traffic you need more CPUs.\nIt is rule for uncached pages.  \n\nWith Varnish/FPC it is the same. However Varnish has ~1ms response time and a single instance CPU can return 1000 caches pages per sec. To avoid unpredictable results with the cache invalidation, misses, uncached checkouts, cart, AJAXs, API the BEST practice is to measure performance without FPC. FPC is a bonus.\n\n\n## AWS Magento 2 Cloud Features:\n* True Horizontal Auto Scaling \n* Affordable (starting from ~300$ for us-west-2 region)\n* MySQL RDS scalable Managed by Amazon, multi-az failover, vertical scaling with no downtime\n* Compatible with RDS Aurora Cluster and Aurora Serverless\n* EFS - Fully managed elastic NFS for media and configuration storage\n* CloudFront CDN for static and media served from different origins S3 or Magento(EFS) as second origin \n* Automatically back up your code and databases (point-in-time snapshot) for easy restoration\n* 99.9% Uptime, availability across multiple zones\n* High security (Security groups, private infrastructure)\n* Elastic(Static) IP and used for internet access for all EC2 instances through NAT (Network Address Translation).\n* Bastion host to provide Secure Shell (SSH) access to the Magento web servers. \n* Appropriate security groups for each instance or function to restrict access to only necessary protocols and ports.\n* Private Public Subnets - NAT gateway, Bastion server\n* All servers and Database are securely hosted in private Network\n* System and Software Update Patches\n* DDoS Protection with AWS Shield\n* PCI compliant infrastructure\n* Redis cluster\n* Amazon Elasticsearch Service - Elasticsearch at scale with zero down time with built-in Kibana\n* Different Application Scaling Groups (ASG)\n* Application Load Balancer(ALB) with SSL/TSL termination, SSL certificates management\n* ALB Path-Based Routing, Host-Based Routing, Lambda functions as targets, HTTP header/method-based routing, Query string parameter-based routing \t\t\n* Scaled Varnish ASG\n* Dedicated Admin/Cron ASG\n* You can easily add new autoscaling groups for your needs (Per WebSite/for Checkout requests/for API), just copy paste code \n* Possibility to run the same infrastructure on Production/Staging/Dev environment, different projects\n* Automatic CI/CD (CodePipeline/CodeDeploy) deployments possible\n* AWS CodeDeploy In-place deployment, Blue/green deployment from Git or S3, Redeploy or Roll Back\n* Deploying from a Development Account to a Production Account\n* Amazon Simple Email Service (Amazon SES) - cloud-based email sending service. Price $0.10 for 1K emails \n* Amazon CloudWatch - load all the metrics (CPU, RAM, Network) in your account for search, graphing, and alarms. Metric data is kept for 15 months.\n* CloudWatch alarms that watche a single CloudWatch metric or the result of a math expression based on CloudWatch metrics and send SMS(Text) Notifications or Emails\n* Simple and Step Scaling Policies - choose scaling metrics that trigger horizontal scaling\n* Manual Scaling for Magento Auto Scaling Group (ASG)\n* AWS Command Line Interface (CLI) - tool to manage your AWS services. You can control multiple AWS services from the command line and automate them through scripts.\n* DynamoDB for logs, indexes, analytics\n* Lambda functions as targets for a load balancer\n* Elastic Container Registry (ECR) - fully-managed Docker container registry that makes it easy to store, manage, and deploy Docker container images!\n* You can use Amazon Elastic Container Service (ECS) instead of ASG with Service Auto Scaling to adjust running containers desired count automatically.\n* Awesome AWS documentation is Open Source and on GitHub\n\n![Magento 2 AWS Infrastructure Cloud ](https://github.com/Genaker/TerraformMagentoCloud/blob/master/Magento2Cloud.png)\n\n[Cloud Flat View](https://github.com/Genaker/TerraformMagentoCloud/blob/master/Magento2Cloud-Flat.png)\n\n# Our Infrastructure\n\nInfrastructure consists of multiple layers (autoscaling, alb, rds, security-group, vpc) where each layer is configured using one of the [Terraform AWS modules](https://github.com/terraform-aws-modules/) with arguments specified in `terraform.tfvars` in layers directory.\n\nTerraform uses this during the module installation step of `terraform init` to download the source code to a directory on local disk so that it can be used by other Terraform commands.\n\nThe [https://registry.terraform.io/](public Terraform registry) provides infrastructure modules for many infrastructure resources.\n\n[Terragrunt](https://github.com/gruntwork-io/terragrunt) is used to work with Terraform configurations which allows you to orchestrate dependent layers, update arguments dynamically and keep configurations. Define Terraform code once, no matter how many environments you have ([DRY](https://en.wikipedia.org/wiki/Don%27t_repeat_yourself)).\n\n# Minimal Magento Cloud Terraform Infrastructure \n\n![Magento Cloud Minimal Terraform Infrastructure](https://user-images.githubusercontent.com/9213670/134946402-8a4ff61d-5def-448a-83dd-89eadecaa550.png)\n\nThe Minimal Magento Cloud infrastructure designed for small and extra large merchants. It can handle any load of up to 10,000 not cached requests per second(according to the internal test). Magento Commerce Cloud can’t handle even 100 simultaneous requests. Also, it dramatically reduces management overhead and cost.\nAfter fixes in the Magento Fork Varnish is the redundant solution for 98% of the merchants and is not the best practice anymore.  \n\nSources of the small infrastructure located in the separate branch-\u003e https://github.com/Genaker/TerraformMagentoCloud/tree/minimal\n\n# Magento 2 Multi Regional Infastructure Support \n\nWe have a global scale-out model. All data updates (POST, DELETE request) are directed to the main data center region. All GET and CACHED requests (black lines) are routed to regional data centers. \n\nGeographically remote web servers add latency and degrade the shopping experience. Such mistakes can prove costly, resulting in lost customers, missed revenue, and reputational damage.\n\nRoute your traffic to your regional Magento Servers based on the user's location.\nWhen you use geolocation routing, you can localize your web store and present some or all of your websites in the language of your users. You can also use geolocation routing to restrict access to the websites to only the locations you have distribution rights. Another use case is balancing load across endpoints.\n\nCan you imagine your USA-based customers' frustration when your servers are located in Norway 🇳🇴 or Australia 🇦🇺?\n\n## Pre-requirements\n\n- [Terraform 0.12 or newer](https://www.terraform.io/)\n- [Terragrunt 0.19 or newer](https://github.com/gruntwork-io/terragrunt)\n- [tfvars-annotations](https://github.com/antonbabenko/tfvars-annotations) - Update values in terraform.tfvars using annotations\n- Optional: [pre-commit hooks](http://pre-commit.com) to keep Terraform formatting and documentation up-to-date\n\n# Install HomeBrew on Linux\n\nPaste at a terminal prompt:\n```\n/bin/bash -c \"$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)\"\n```\nThe installation script installs Homebrew to /home/linuxbrew/.linuxbrew using sudo if possible and, if not, in your home directory at ~/.linuxbrew. Homebrew does not use sudo after installation. Using /home/linuxbrew/.linuxbrew allows the use of more binary packages (bottles) than installing in your personal home directory.\n\nThe followig instructions will add Homebrew to your PATH and to your bash shell profile script (either ~/.profile on Debian/Ubuntu or ~/.bash_profile on CentOS/Fedora/RedHat).\n```\ntest -d ~/.linuxbrew \u0026\u0026 eval $(~/.linuxbrew/bin/brew shellenv)\ntest -d /home/linuxbrew/.linuxbrew \u0026\u0026 eval $(/home/linuxbrew/.linuxbrew/bin/brew shellenv)\ntest -r ~/.bash_profile \u0026\u0026 echo \"eval \\$($(brew --prefix)/bin/brew shellenv)\" \u003e\u003e~/.bash_profile\necho \"eval \\$($(brew --prefix)/bin/brew shellenv)\" \u003e\u003e~/.profile\n```\nYou’re done! Try installing a package:\n```\nbrew install hello\n```\nIf you’re using an older distribution of Linux, installing your first package will also install a recent version of glibc and gcc. Use `brew doctor` to troubleshoot common issues.\n\nIf you are using Mac you can install all dependencies using Homebrew:\n\n    $ brew install terraform terragrunt pre-commit\n    \n## Manual install:\n\nYou can install Terragrunt manually by going to the [Releases page](https://github.com/gruntwork-io/terragrunt/releases), downloading the binary for your OS, renaming it to terragrunt and adding it to your PATH.\n\n# Install Terragrunt and Terraform Ubuntu Manually\n```\nsudo -s; ## run as a super user\n    export TERRAFORM_VERSION=0.12.24 \\\n    \u0026\u0026 export TERRAGRUNT_VERSION=0.23.2 \\\n    \u0026\u0026 mkdir -p /ci/terraform_${TERRAFORM_VERSION} \\\n    \u0026\u0026 wget -nv -O /ci/terraform_${TERRAFORM_VERSION}/terraform_${TERRAFORM_VERSION}_linux_amd64.zip https://releases.hashicorp.com/terraform/${TERRAFORM_VERSION}/terraform_${TERRAFORM_VERSION}_linux_amd64.zip \\\n    \u0026\u0026 unzip -o /ci/terraform_${TERRAFORM_VERSION}/terraform_${TERRAFORM_VERSION}_linux_amd64.zip -d /usr/local/bin/ \\\n    \u0026\u0026 mkdir -p /ci/terragrunt-${TERRAGRUNT_VERSION}/ \\\n    \u0026\u0026 wget -nv -O /ci/terragrunt-${TERRAGRUNT_VERSION}/terragrunt https://github.com/gruntwork-io/terragrunt/releases/download/v${TERRAGRUNT_VERSION}/terragrunt_linux_amd64 \\\n    \u0026\u0026 sudo chmod a+x /ci/terragrunt-${TERRAGRUNT_VERSION}/terragrunt \\\n    \u0026\u0026 cp /ci/terragrunt-${TERRAGRUNT_VERSION}/terragrunt /bin \\\n    \u0026\u0026 chmod a+x /bin/terragrunt \\\n    \u0026\u0026 rm -rf /ci \\\n    \u0026\u0026 exit\n```\nTest The Terragrunt/Terraform installation(Optional):\n```\nterragrunt -v;\nterraform -v\n```\n\n## Instructions for use\n\nStep 0. Terraform uses the SSH protocol to clone the modules. Configured SSH keys will be used automatically. Add your SSH key to github account. (https://help.github.com/en/enterprise/2.15/user/articles/adding-a-new-ssh-key-to-your-github-account)\n\nGit+SSH is used because it works for both public and private repositories.\n\nStep 1. Set credentials. By default, access credentials to AWS account should be set using environment variables:\n```\n     export AWS_DEFAULT_REGION=us-west-1 ## change it to your preferable AWS region\n     export AWS_ACCESS_KEY_ID=\"...\"\n     export AWS_SECRET_ACCESS_KEY=\"...\"\n```\nAlternatively, you can edit `common/main_providers.tf` and use another authentication mechanism as described in the [AWS provider documentation](https://www.terraform.io/docs/providers/aws/index.html#authentication).\n\nThe AWS provider offers a flexible means of providing credentials for authentication. The following methods are supported, in this order, and explained below:\n\nStatic credentials\nEnvironment variables\nShared credentials/configuration file\nCodeBuild, ECS, and EKS Roles\nEC2 Instance Metadata Service (IMDS and IMDSv2)\n\nStep 2. Once all arguments are set, run this command to create infrastructure in all layers in a single region:\n\n    $ cd production\n    $ terragrunt apply-all\n\nAlternatively, you can create infrastructure in a single layer (eg, `autoscaling_3`):\n\n    $ cd production/autoscaling_3\n    $ terragrunt apply\n\nSee [official Terragrunt documentation](https://github.com/gruntwork-io/terragrunt/blob/master/README.md) for all available commands and features.\n\nIf you are using newer version of the terragrunt you should use :\n\n- **Region as a whole (slower\u0026complete).** Run this command to create infrastructure in all layers in a single region:\n\n```\n$ cd ap-southeast-1\n$ terragrunt run-all apply\n```\n\n- **As a single layer (faster\u0026granular).** Run this command to create infrastructure in a single layer (eg, `magento_auto_scaling`):\n\n```\n$ cd ap-southeast-1/magento_auto_scaling\n$ terragrunt apply\n```\n\nAfter the confirmation your infrastructure should be created.\n\n## Destroy infrastructure\n\n**destroy-all** (DEPRECATED: use run-all)\nDEPRECATED: Use **run-all destroy** instead.\n\n```\n terragrunt run-all destroy\n```\n\nDestroy a ‘stack’ by running ‘terragrunt destroy’ in each subfolder.\n\n\n# Demo video showing how it works (click on image)\n\n\u003ca href=\"https://www.youtube.com/watch?v=kmnlrXSTQlM\"\u003e\n\u003cimg alt=\"Magento AWS Cloud\" src=\"https://github.com/Genaker/TerraformMagentoCloud/blob/master/Magento2Cloud-Flat.png\" width=\"50%\" height=\"50%\"\u003e\n\u003c/a\u003e\n\nor click the url to see the video: (https://www.youtube.com/watch?v=kmnlrXSTQlM)\n\nArchitecting your Magento platform to grow with your business can sometimes be a challenge. This video walks through the steps needed to take an out-of-the-box, single-node Magento implementation and turn it into a highly available, elastic, and robust deployment. This includes an end-to-end caching strategy that provides an efficient front-end cache (including populated shopping carts) using Varnish on Amazon EC2 as well as offloading the Magento caches to separate infrastructure such as [https://aws.amazon.com/elasticache/](Amazon ElastiCache). We also look at strategies to manage the Magento Media library outside of the application instances, including [https://aws.amazon.com/efs/](EFS shared storage solutions).\n\n\n# Debug logging\n\nIf you set the TERRAGRUNT_DEBUG environment variable to “true”, the stack trace for any error will be printed to stdout when you run the app.\n\nAdditionally, newer features introduced in v0.19.0 (such as locals and dependency blocks) can output more verbose logging if you set the TG_LOG environment variable to debug.\n\nTurn on debug when you need do troubleshooting.\n```\n# or if you run with terragrunt\nTF_LOG=DEBUG terragrunt \u003ccommand\u003e\n```\n\nIn the new versions of the terragrunt use:\n```\nterragrunt run-all apply --terragrunt-log-level debug --terragrunt-debug\n```\n\nTerragrunt and Terraform usually play well together in helping you write DRY, re-usable infrastructure. But how do we figure out what went wrong in the rare case that they don’t play well?\n\nTerragrunt provides a way to configure logging level through the --terragrunt-log-level command flag. Additionally, Terragrunt provides --terragrunt-debug, that can be used to generate terragrunt-debug.tfvars.json.\n\nFor example you could use it like this to debug an apply that’s producing unexpected output:\n\n```\n$ terragrunt apply --terragrunt-log-level debug --terragrunt-debug\n```\n\nRunning this command will do two things for you:\n\nOutput a file named terragrunt-debug.tfvars.json to your terragrunt working directory (the same one containing your terragrunt.hcl).\nPrint instructions on how to invoke terraform against the generated file to reproduce exactly the same terraform output as you saw when invoking terragrunt. This will help you to determine where the problem’s root cause lies.\nUsing those features is helpful when you want determine which of these three major areas is the root cause of your problem:\n\nMisconfiguration of your infrastructure code.\n - An error in terragrunt.\n - An error in terraform.\n\n# Clearing the Terragrunt cache\n\nTerragrunt creates a .terragrunt-cache folder in the current working directory as its scratch directory. It downloads your remote Terraform configurations into this folder, runs your Terraform commands in this folder, and any modules and providers those commands download also get stored in this folder. You can safely delete this folder any time and Terragrunt will recreate it as necessary.\n\nIf you need to clean up a lot of these folders (e.g., after terragrunt apply-all), you can use the following commands on Mac and Linux:\n\nRecursively find all the .terragrunt-cache folders that are children of the current folder:\n```\nfind . -type d -name \".terragrunt-cache\"\n```\nIf you are ABSOLUTELY SURE you want to delete all the folders that come up in the previous command, you can recursively delete all of them as follows:\n```\nfind . -type d -name \".terragrunt-cache\" -prune -exec rm -rf {} \\;\n```\nAlso consider setting the TERRAGRUNT_DOWNLOAD environment variable if you wish to place the cache directories somewhere else.\n\n# Destroy Terragrunt Magento Infrastructure \n```\nterragrunt destroy-all \n```\nInfrastructure managed by Terraform will be destroyed. This will ask for confirmation before destroying.\n\nThis command accepts all the arguments and flags that the apply command accepts, with the exception of a plan file argument.\n\nIf -auto-approve is set, then the destroy confirmation will not be shown.\n\nThe -target flag, instead of affecting \"dependencies\" will instead also destroy any resources that depend on the target(s) specified. For more information, see the [Targeting section of the terraform plan documentation](https://www.terraform.io/docs/commands/plan.html#resource-targeting).\n\nThe behavior of any terraform destroy command can be previewed at any time with an equivalent `terraform plan -destroy` command.\n\n\n# Production \u0026 staging environments \n\nYou can copy/paste folders to create new environments. Consider the following files structure, which defines three magento environments (prod, project-3 and stage) with the same infrastructure in each one (an app, a MySQL database, and a VPC):\n```\n└── magento\n    ├── prod\n    │   ├── app\n    │   │   └── main.tf\n    │   ├── mysql\n    │   │   └── main.tf\n    │   └── vpc\n    │       └── main.tf\n    ├── project-3\n    │   ├── app\n    │   │   └── main.tf\n    │   ├── mysql\n    │   │   └── main.tf\n    │   └── vpc\n    │       └── main.tf\n    └── stage\n        ├── app\n        │   └── main.tf\n        ├── mysql\n        │   └── main.tf\n        └── vpc\n            └── main.tf\n```    \nThe contents of each environment will be more or less identical, except perhaps for a few settings (eg. the prod environment may use bigger or more servers). As the size of the infrastructure grows, having to maintain all of this duplicated code between environments becomes more error prone. You can reduce the amount of copying and pasting using Terraform modules, but even the code to instantiate a module and set up input variables, output variables, providers and remote state can still create a lot of maintenance overhead.\n\nTerragrunt allows you to keep your Magento backend configuration DRY (“Don’t Repeat Yourself”) by defining it once in a root location and inheriting that configuration in all child modules. Let’s say your Terraform code has the following folder layout:\n```\nstage\n├── frontend-app\n│   └── main.tf\n└── mysql\n    └── main.tf\n``` \nTo use Terragrunt, add a single terragrunt.hcl file to the root of your repo, in the stage folder, and one terragrunt.hcl file in each module folder:\n```\nstage\n├── terragrunt.hcl\n├── frontend-app\n│   ├── main.tf\n│   └── terragrunt.hcl\n└── mysql\n    ├── main.tf\n    └── terragrunt.hcl\n```\nNow you can define your backend configuration just once in the root terragrunt.hcl file!\n\n\n# Multi cloud deployments \n\nTerraform provides Magento 2 Open Source Cloud infrastructure as a code approach to provision and manage any cloud (AWS, GoogleCloud, Azure, Alibaba, or other types of services such as Kubernetes).\n\nTerraform can manage popular service providers, such as AWS, GCP, Micosoft Azure, Alibaba Cloud, and VMware, as well as custom in-house and on-premises solutions.\n\n## Enterprise Support/Installation/Development Package available.\nSeveral Magento development Agencies select this custom cloud solution for their clients and they are willing to provide services/support for businesses based on this Open Source project.\nThis project currently has 10+ partners. \nIf you are willing to be listed as cloud service provider feel free message me.\n\n\nMore information: yegorshytikov@gmail.com\n\nI also have Ansible Magento Cloud provisioning implementation:\nhttps://github.com/Genaker/AWS_Magento2_Ansible\n\nAnd also Magento Cloud provisioning Using AWS CDK. Coming soon ...\n\n\n# Approximate Magento 2 AWS Cloud infrastructure Cost\n\n```\n+-------------+---------------------+-----------+------------+-------+------------+---------------+---------------+\n| Category    | Type                | Region    | Total cost | Count | Unit price | Instance type | Instance size |\n+-------------+---------------------+-----------+------------+-------+------------+---------------+---------------+\n| appservices | Email Service - 10K | us-west-2 | $1.00      | 1     | $1.00      |               |               |\n+-------------+---------------------+-----------+------------+-------+------------+---------------+---------------+\n| storage     | EFS storage – 20GB  | us-west-2 | $6.00      | 1     | $6.00      |               |               |\n+-------------+---------------------+-----------+------------+-------+------------+---------------+---------------+\n| storage     | S3 – 50Gb           | us-west-2 | $2.00      | 1     | $2.00      |               |               |\n+-------------+---------------------+-----------+------------+-------+------------+---------------+---------------+\n| compute     | ec2-Web Node        | us-west-2 | $61.20     | 1     | $61.20     | c5            | large         |\n+-------------+---------------------+-----------+------------+-------+------------+---------------+---------------+\n| networking  | elb - Load Balancer | us-west-2 | $43.92     | 2     | $21.96     |               |               |\n+-------------+---------------------+-----------+------------+-------+------------+---------------+---------------+\n| compute     | ec2-Admin-Cron Node | us-west-2 | $29.95     | 1     | $29.95     | t3            | medium        |\n+-------------+---------------------+-----------+------------+-------+------------+---------------+---------------+\n| database    | ElastiCache-Redis   | us-west-2 | $24.48     | 1     | $24.48     | t3            | small         |\n+-------------+---------------------+-----------+------------+-------+------------+---------------+---------------+\n| compute     | ec2-Varnish         | us-west-2 | $29.95     | 1     | $29.95     | t3            | large         |\n+-------------+---------------------+-----------+------------+-------+------------+---------------+---------------+\n| analytics   | ElasticSearch       | us-west-2 | $12.96     | 1     | $12.96     | t2            | micro         |\n+-------------+---------------------+-----------+------------+-------+------------+---------------+---------------+\n| database    | RDS MySQL           | us-west-2 | $48.96     | 1     | $48.96     | t3            | medium        |\n+-------------+---------------------+-----------+------------+-------+------------+---------------+---------------+\n| storage     | EBS Storage 30Gb    | us-west-2 | $9.13      | 1     | $9.13      |               |               |\n+-------------+---------------------+-----------+------------+-------+------------+---------------+---------------+\n|             |                     | Total     | $269.55    |       |            |               |               |\n+-------------+---------------------+-----------+------------+-------+------------+---------------+---------------+\n```\n# eCommerce Cloud Price Visualisation \n\n![Magento 2 AWS Cloud Cost](https://github.com/Genaker/TerraformMagentoCloud/blob/master/small-big.png)\n\n# Why not Magento Cloud?\n```\n+-----------------------------------------+-------------------------------------------+\n|              Magento Cloud              |               This Solution               |\n+-----------------------------------------+-------------------------------------------+\n| Manual scaling, requires prior notice,  | Unlimited Resource, scaling by rule,      |\n| vertical scaling,                       | no performance degradation                |\n| performance degradation during scaling  |                                           |\n+-----------------------------------------+-------------------------------------------+\n| Fastly CDN only                         | Completely CDN agnostic,                  |\n|                                         |  works with Cloudflare, CloudFront        |\n+-----------------------------------------+-------------------------------------------+\n| Works only with Enterprise version M2   | Works with any version of Magento 1/2     |\n+-----------------------------------------+-------------------------------------------+\n| Expensive $2000-$10000 month * +        | Paying only for AWS resources you used,   |\n| Enterprise license                      | starting from 300$ months                 |\n+-----------------------------------------+-------------------------------------------+\n| Not Customizable                        | Fully Customizeble                        |\n+-----------------------------------------+-------------------------------------------+\n| Host only single Magento 2 CE           | Can host multiple project, web sites,     |\n| installation                            | tech stacks, PHP, Node.JS, Python, Java;  |\n|                                         | Magento 1/2, WordPres, Drupal, Joomla,    |\n|                                         | Presta Shop, Open Cart, Laravel, Django   |\n+-----------------------------------------+-------------------------------------------+\n```\n*Magento Cloud introduces: \nOVERAGE FEES for the Compute Overage usage (per vCPU day): ~$X(price of the Commerce Cloud is Adore Secret)/vCPU-day when a raw AWS vCPU cost is less than 1$ per day. \n\nFrom the Magento Cloud Agremment: \n\nMagento Cloud Customer hereby authorizes Magento, if applicable, to charge its credit card or other payment instrument or Subscription Fees, Overage Fees and/or any upgrades to the Services ordered, and any applicable taxes in arrears or at time of order, as the case may be.\n\nBecause of the bad Magento Cloud Architecture and performace you cloud HIDDEN OVERAGE FEES can be more then a Contract price. \n\n\n# Basic Deployment With CodeDeploy Example \n\n## Code and application deployment is beyond the scope of this repo. This repo for infrastructure provisioning only!!!\n\nAWS CodeDeploy is a managed deployment technology. It provides great features like rolling deployments, automatic rollback, and load balancer integration. It is technology agnostic and Amazon uses it to deploy everything. \n\nASSUMING YOU ALREADY HAVE an AWS account and CodeDeploy setup\n\nHere are the basic that we take on a deployment for M2 \n\nHere is the appspec.yml file (https://docs.aws.amazon.com/codedeploy/latest/userguide/reference-appspec-file.html#appspec-reference-ecs)\n```\nversion: 0.0\nos: linux\nhooks:\n    BeforeInstall:\n        - location: config_files/scripts/beforeInstall.bash\n          runas: root\n    AfterInstall:\n        - location: config_files/scripts/afterInstall.bash\n          runas: mage_user\n        - location: config_files/scripts/moveToProduction.bash\n          runas: root\n        - location: config_files/scripts/cacheclean.bash\n          runas: mage_user\n```\n\n# Magento 2 AWS Code Deploy script example\nScript to 'compile' magento on Deploy server - You pull and compile code to deploy server or build Docker container end after just push code to production using Code Deploy - fastest way \n\n```\ncd production/build/public_html\ngit checkout .\ngit pull origin master\nrm -rf var/cache/* var/page_cache/* var/composer_home/* var/tmp/*\nphp composer.phar update --no-interaction --no-progress --optimize-autoloader\nbin/magento setup:upgrade\nbin/magento setup:static-content:deploy -t Magento/backend\nbin/magento setup:static-content:deploy en_US es_ES -a frontend\nbin/magento setup:di:compile\n# Make code files and directories read-only\necho \"Setting directory base permissions to 0750\"\nfind . -type d -exec chmod 0750 {} \\;\necho \"Setting file base permissions to 0640\"\nfind . -type f -exec chmod 0640 {} \\;\nchmod o-rwx app/etc/env.php \u0026\u0026 chmod u+x bin/magento\n\n# Compress source at shared directory\nif [ ! -d /build ]; then\n    mkdir -p /build\nfi\ntar -czvf /build/build.tar.gz . --exclude='./pub/media' --exclude='./.htaccess' --exclude='./.git' --exclude='./var/cache' --exclude='./var/composer_home' --exclude='./var/log' --exclude='./var/page_cache' --exclude='./var/import' --exclude='./var/export' --exclude='./var/report' --exclude='./var/backups' --exclude='./var/tmp' --exclude='./var/resource_config.json' --exclude='./var/.sample-data-state.flag' --exclude='./app/etc/config.php' --exclude='./app/etc/env.php'\n```\nNow you can deploy to your pre-configured group\n\n```\nsh ./compile.sh\naws deploy create-deployment \\\n--application-name AppMagento2 \\\n--deployment-config-name CodeDeployDefault.OneAtATime \\\n--deployment-group-name MyMagentoApp \\\n--description \"Live Deployment\" \\\n--s3-location bucket=mage-codedeploy,bundleType=zip,eTag=\u003ctagname\u003e,key=live-build2.zip\n```\n\nCreate this script to show where you are in the deployment\n\nshow-deployment.sh\n\n```\naws deploy get-deployment --deployment-id $1 --query \"deploymentInfo.[status, creator]\" --output text\n```\n\nFile 'config_files/scripts/afterInstall.bash' should run setup:upgrade --keep-generated, nginx, php-fpm restart and similar stuff\n\n##How to Deploy With Docker \n\nJust run command in your codeDeploy script \n\n```\ndocker pull [OPTIONS] MAGENTO_IMAGE_NAME[:TAG|@DIGEST]\n\n```\nExample of the deploy file: https://github.com/Genaker/TerraformMagentoCloud/blob/master/deploy.sh\n\n# Automate the installation of software using Golden AMI\n\nA “golden AMI” or “gold image” is an Magento AMI you standardize through configuration, consistent security patching, and hardening. It also contains agents you approve for logging, security, performance monitoring, etc. Many enterprise customers have a mature AMI pipeline setup to create a golden AMI of base operating systems for the organization. For a sample golden AMI pipeline, see [The Golden AMI Pipeline] (https://aws.amazon.com/blogs/awsmarketplace/announcing-the-golden-ami-pipeline/).\n\nYou can launch an instance from an existing AMI, customize the instance, setup Software (Magento, ODDO, Wordpress, Shopware etc.) and then save this updated configuration as a custom AMI. Instances launched from this new custom AMI include the customizations that you made when you created the AMI.\n\n# Magento 2 Installation Automation (Centos 8.2, AWS linux with ARM support) GitHub reposetory:\n\n[Magento installation Script] (https://github.com/Genaker/Magento-AWS-Linux-2-Instalation).\n\n# Building an Golden AMI with Packer\n\nPacker is an open-source tool by Hashicorp that automates the creation of machine images for different platforms. Developers specify the machine configuration using a JSON file called template, and then run Packer to build the image.\n\n\nOne key feature of Packer is its capability to create images targeted to different platforms, all from the same specification. This is a nice feature that allows you to create machine images of different types without repetitive coding.\n\nYou can get Packer and its documentation at the [Packer official site](https://www.packer.io/).  \n\n\n# Use DynamoDb with Magento 2\n\nMagento out of the box has a PHP Library to work with Dynamo DB. \n\n```\nuse Aws\\DynamoDb\\Exception\\DynamoDbException;\nuse Aws\\DynamoDb\\Marshaler;\n\n$sdk = new Aws\\Sdk([\n    'endpoint'   =\u003e 'http://localhost:8000',\n    'region'   =\u003e 'us-west-2',\n    'version'  =\u003e 'latest'\n]);\n\n$dynamodb = $sdk-\u003ecreateDynamoDb();\n$marshaler = new Marshaler();\n\n$tableName = 'Movies';\n\n$year = 2015;\n$title = 'The Big New Movie';\n\n$item = $marshaler-\u003emarshalJson('\n    {\n        \"year\": ' . $year . ',\n        \"title\": \"' . $title . '\",\n        \"info\": {\n            \"plot\": \"Nothing happens at all.\",\n            \"rating\": 0\n        }\n    }\n');\n\n$params = [\n    'TableName' =\u003e 'Movies',\n    'Item' =\u003e $item\n];\n\ntry {\n    $result = $dynamodb-\u003eputItem($params);\n    echo \"Added item: $year - $title\\n\";\n\n} catch (DynamoDbException $e) {\n    echo \"Unable to add item:\\n\";\n    echo $e-\u003egetMessage() . \"\\n\";\n}\n\n?\u003e\n```\n\nYou can record logs to a DynamoDB table with the AWS SDK and Monolog using /Monolog/Handler/DynamoDbHandler.php\n\nWhen Time to Live (TTL) is enabled on a table in Amazon DynamoDB, a background job checks the TTL attribute of items to determine whether they are expired.\n\nAlso you can use the Amazon Web Services CloudWatch Logs Handler for Monolog library to integrate Magento 2 Monolog with CloudWatch Logs (https://github.com/maxbanton/cwh).\n\n```\nphp composer.phar require maxbanton/cwh:^1.0\n```\n\n\nIf you have any questions feel free to send me an email – yegorshytikov@gmail.com\n\nTerraform AWS moules maintained by [Anton Babenko](https://github.com/antonbabenko)\n\nAll content, including [Terraform AWS modules](https://github.com/terraform-aws-modules/) used in these configurations, is released under the MIT License. \n\n# Good news for the Magento Terraform Community \n\nTerragrunt issue with use modules from Terraform Registry is resolved now we can use many other modules! \nhttps://github.com/gruntwork-io/terragrunt/issues/311\n\nTerragrunt 31.5 release: Added support for fetching modules from any Terraform Registry using the new tfr:// protocol syntax for the source attribute. See the updated docs on source for more details.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FGenaker%2FTerraformMagentoCloud","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FGenaker%2FTerraformMagentoCloud","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FGenaker%2FTerraformMagentoCloud/lists"}