Code Monkey home page Code Monkey logo

terraform-adobe-magento's Introduction

Note: This module is in beta testing and likely contains bugs. It is not recommended for production use at this time.

Terraform Magento Commerce

This module uses Terraform Cloud to deploy Magento Commerce on the Amazon Web Services (AWS) Cloud.

Authors

James Cowie, Pat McManaman, and Mikko Sivula, Shero Commerce

Kenny Rajan, Dan Taoka, and Vikram Mehto, Amazon Web Services

Install Terraform

See Install Terraform.

Sign up for Terraform Cloud

Log in to Terraform Cloud. If you don't have an account, you can sign up for a free tier.

Configure Terraform Cloud API access

Generate a Terraform Cloud token:

terraform login

Export the TERRAFORM_CONFIG variable:

export TERRAFORM_CONFIG="$HOME/.terraform.d/credentials.tfrc.json"

Configure the tfvars file

Example path:

$HOME/.aws/terraform.tfvars

An example of the tfvars file contents:

AWS_SECRET_ACCESS_KEY = "{insert secret access key}"
AWS_ACCESS_KEY_ID = "{insert access key ID}"
AWS_SESSION_TOKEN = "{insert session token}"

Note: We recommend using Security Token Service (AWS STS)–based credentials.

Warning: Follow best practices for managing secrets, and ensure that your credentials are not stored in a public repository.

Note: Before deployment, you must create both an AWS key pair and a Magento deployment key.

Create an AWS key pair

To create a key pair, see Prepare an AWS Account.

Note the key-pair name because you will use it during the deployment.

Store the private key in AWS Secrets Manager as plaintext

  1. Navigate to AWS Secrets Manager in the AWS Management Console.
  2. Store a new secret.
  3. Choose Other type of secrets.
  4. Choose Plaintext".
  5. Clear the \{:} JSON format from the Plaintext section.
  6. Copy and paste the private-key contents that you previously created.
  7. Select the encryption key, and choose Next.
  8. Set secret name to ssh-key-admin, and choose Next.
  9. Set Automatic rotation to Disabled, and choose Next.
  10. Review and store the key.

Create Magento deployment keys

To create Magento deployment keys, see Get your authentication keys. This deployment uses Composer to manage Magento components and their dependencies. For more information, see Magento Composer.

  • Create a Magento public-authentication key for your Composer user name.
  • Create a Magento public-authentication key for your Composer password.

Note these values because you will use them during the deployment.

Deploy the module (Linux and iOS)

  1. Clone the repository.
  2. Navigate to the repository's root directory.
  3. Navigate to the setup_workspace directory:
cd setup_workspace

Run the following commands in order:

terraform init

Alternatively, for the previous command, specify the file:

terraform apply -var-file="$HOME/.aws/terraform.tfvars"

You are asked for the following:

  • The AWS Region where you want to deploy this module. This must match the Region where you generated the key pair.
  • The organization under which Terraform Cloud runs. This can be found in the Terraform Cloud console.
  • Setup confirmation.

Terraform Cloud creates the workspace, which contains the Terraform Cloud organization name.

Navigate to the directory, and deploy Magento (the previous terraform init command generates backend.hcl):

cd ../deploy
  1. Open, edit, and review all of the variables in the variables.tf file.
  2. Update the default= value for your deployment.
  3. The description= provides additional context for each variable.

The following items must be edited before deployment:

  • Project-specific: domain_name
  • Magento information: mage_composer_username
  • Magento information: mage_composer_password
  • Magento information: magento_admin_password
  • Magento information: magento_admin_email
  • Database: magento_database_password

Important: Don't store secret information in a public repository.

After you review and update the ./deploy/variables.tf file, run one of the following Terraform commands:

terraform apply
terraform apply -var-file="$HOME/.aws/terraform.tfvars"

Terraform apply runs remotely in Terraform Cloud and takes about 30–60 minutes to deploy.

During the deployment, you should receive an AWS email to allow Amazon SES to send you emails. Verify this before you log in to Magento.

After the Terraform deployment completes, an output shows the relevant information for accessing Magento.

Important: After Terraform completes, Magento bootstraps the environment, which takes about 15–20 minutes. Various Magento install and configuration commands run during this time, and the site enters maintenance mode. After it exits maintenance mode, images sync with your Amazon Simple Storage Service (Amazon S3) bucket.

Test the deployment

After Terraform completes, it outputs the frontend and backend URLs. Use the credentials specified in the variables.tf file to log in as an administrator. Run the following command to connect to the web node:

ssh -i PATH_TO_GENERATED_KEY -J admin@BASTION_PUBLIC_IP magento@WEB_NODE_PRIVATE_IP

Note: Ensure that you have SSH key forwarding enabled.

Clean up the infrastructure

Note: If you want to retain the Magento files stored in your Amazon S3 bucket, copy and save the bucket's objects before completing this step.

When you no longer need the infrastructure, run one of the following commands to remove it:

terraform destroy
terraform destroy -var-file="$HOME/.aws/terraform.tfvars

After you remove the infrastructure, the database is stored as an artifact.

terraform-adobe-magento's People

Contributors

andrew-glenn avatar delfingala avatar drewmullen avatar pmcmanaman avatar tbulding avatar tlindsay42 avatar tonynv avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

terraform-adobe-magento's Issues

Error creating S3 bucket: BucketAlreadyExists

module.magento.module.magento.aws_alb.alb_internal: Still creating... [2m50s elapsed]
module.magento.module.magento.aws_alb.alb_internal: Creation complete after 2m58s [id=arn:aws:elasticloadbalancing:eu-west-1:464148620691:loadbalancer/app/alb-internal/b3792917185db033]
module.magento.module.magento.data.template_file.varnish_userdata: Reading...
module.magento.module.magento.data.template_file.varnish_userdata: Read complete after 0s [id=1a7047b636f724a9d6db32991271c688c325b6b19b185beee292c14c10009de8]
module.magento.module.magento.aws_alb_listener.alb_internal_listener_http: Creating...
module.magento.module.magento.aws_alb_listener.alb_internal_listener_http: Creation complete after 1s [id=arn:aws:elasticloadbalancing:eu-west-1:464148620691:listener/app/alb-internal/b3792917185db033/6cfabc4525bcc717]

│ Error: Error creating S3 bucket: BucketAlreadyExists: The requested bucket name is not available. The bucket namespace is shared by all users of the system. Please select a different name and try again.
│ status code: 409, request id: DPHQ1H930F1JQ2FW, host id: dg8wQy9BQcY6/RWY+NC9sbMjrT2niz9VsOaViELxK73ss//69GcohNqDVFN6I4UOuNA/vvLo8HX+tVcP/dJJVw==

│ with module.magento.module.magento.aws_s3_bucket.lb_logs,
│ on ../modules/magento/alb_and_asg.tf line 5, in resource "aws_s3_bucket" "lb_logs":
│ 5: resource "aws_s3_bucket" "lb_logs" {


Operation failed: failed running terraform apply (exit 1)

Breaking changes Magento 2.4.6

Issue: The script uses the latest Magento distribution. Recently Magento releases v2.4.6 that doesnt support php7.4. Due to the latest update, the installation will fail.

Ref: https://experienceleague.adobe.com/docs/commerce-operations/release/notes/magento-open-source/2-4-6.html?lang=en

Workaround:

  1. Open modules/magento-ami/scripts/ec2_install/scripts/install_magento.sh
  2. Replace the content with following to use Magento 2.4.5 instead.
    #!/bin/bash
    BASEDIR=$1
    MAGVERSION="2.4.5"
    
    sudo mkdir -p /var/www/html/magento
    sudo chown -R magento. /var/www/html
    mkdir -p /home/magento/.config/composer/
    sudo mv $BASEDIR/configs/auth.json /home/magento/.config/composer/
    sudo chown -R magento. /home/magento/.config/
    cd /home/magento
    sudo -u magento composer create-project --repository-url=https://repo.magento.com/ magento/project-community-edition=$MAGVERSION /var/www/html/magento -n
    ```
    
    

infrastructure limits and security implications

security:
please do not use any:

  1. ssh connections
  2. ssh keys
  3. sudo ALL
  4. single system and php user
  5. undefined acl
  6. writeable folders
  7. executable awscli
  8. IMDSv1

infrastructure:
please do not limit to nor use:

  1. only single region
  2. only 2 AZ in region
  3. bastion hosts
  4. parameters/ip sync

add more randomness to parameters and variables.
many devs will use it for production and deployment own shops, adopting and replicating these issues.

also you create dual ALB with IGW to internal private network and with CloudFront, doesn't looks like quick start reference infrastructure.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.