Skip to main content
Version: 2.1.0

Using Terraform

Nimara Storefront can be deployed to Vercel using Terraform. This allows you to manage your infrastructure as code which is particularly useful for automating deployments and managing configurations across different environments.

Prerequisites​

Before proceeding, ensure you have:

Clone the forked Repository​

First, clone your forked repository to your local machine:

git clone https://github.com/<YOUR_GITHUB_USERNAME>/nimara-ecommerce.git

Configure Terraform​

Navigate to the directory where the Terraform configuration files are located:

cd nimara-ecommerce/terraform/storefront

Initialize Terraform (this downloads the necessary provider plugins):

terraform init

Set Up Environment Variables​

Now it's time to set up the environment variables (both private and public) required for the storefront deployment.

Copy the private variable file template to a new file named private.auto.tfvars:

cp example.private.auto.tfvars private.auto.tfvars
warning

This file will contain sensitive information and should not be committed to version control. Make sure to add it to your .gitignore file.

Edit the new private.auto.tfvars file and add your environment variables, replacing the CHANGE_ME placeholders with your actual values. These variables are essential for the storefront to function correctly, including Saleor app token, authentication secret, and Stripe secret key and must be kept private. What they are and how to get them is described in the Environment Variables section. Vercel variables can be obtained from your Vercel account settings.

terraform/storefront/private.auto.tfvars
# Rename this file to `private.auto.tfvars` and fill in the values.
# This file cannot be committed to version control as it contains sensitive information.

# Can be found in your Vercel team settings - https://vercel.com/YOUR_TEAM_NAME/~/settings.
# Look for the `Team ID` section and copy the ID. Example: `team_1234567890abcdef`.
# Keep it secure and do not share it publicly.
vercel_team_id = "CHANGE_ME"

# Can be generated in your Vercel account settings - https://vercel.com/account/settings/tokens
# Give it a descriptive name, assign a proper scope and expiration date.
# Keep it secure and do not share it publicly.
vercel_api_token = "CHANGE_ME"

# Map of private environment variables to be set in the Vercel project. Put sensitive information here.
private_environment_variables = {
"SALEOR_APP_TOKEN": {
comment = "Required. Saleor app token for the storefront."
sensitive = true
envs_values = [
{
value = "CHANGE_ME"
target = ["production", "preview"]
}
]
},
"AUTH_SECRET": {
comment = "Required. Secret key for authentication."
sensitive = true
envs_values = [
{
value = "CHANGE_ME"
target = ["production", "preview"]
}
]
},
"STRIPE_SECRET_KEY": {
comment = "Required. Secret key for Stripe payments."
sensitive = true
envs_values = [
{
value = "CHANGE_ME"
target = ["production", "preview"]
}
]
}
}

Next, configure public environment variables in the same way. Copy the public variable file template to a new file named public.auto.tfvars:

cp example.public.auto.tfvars public.auto.tfvars

Edit the new public.auto.tfvars file and fill in the values for the public environment variables:

terraform/storefront/public.auto.tfvars
# Rename this file to `public.auto.tfvars` and fill in the values.
# This file can be committed to version control as it should contain only public information.

# GitHub repository for the Vercel project.
# Format: "owner/repo". Example: "mirumee/nimara-ecommerce".
github_repository = ""

# Repository branch to deploy to production. If not set, it will default to "main".
github_production_branch = "main"

# Vercel project name. If not set, it will default to "nimara-ecommerce".
vercel_project_name = "nimara-ecommerce"

# Optional. List of additional environments with their configurations.
additional_environments = []

# Map of public environment variables to be set in the Vercel project.
public_environment_variables = {
"NEXT_PUBLIC_SALEOR_API_URL" = {
comment = "Public Saleor API URL for the storefront"
envs_values = [
{
value = "https://{YOUR_SALEOR_DOMAIN}/graphql/"
target = ["production", "preview", "development"]
}
]
},
"NEXT_PUBLIC_DEFAULT_CHANNEL" = {
comment = "Default channel slug for the storefront"
envs_values = [
{
value = "CHANGE_ME"
target = ["production", "preview", "development"]
}]
},
"NEXT_PUBLIC_STOREFRONT_URL" = {
comment = "Public URL of the storefront. If not set, it will default to the Vercel project domain."
envs_values = [
{
value = "https://{YOUR_STOREFRONT_DOMAIN}"
target = ["production", "preview", "development"]
}
]
},
"NEXT_PUBLIC_STRIPE_PUBLIC_KEY" = {
comment = "Public Stripe key for the storefront"
envs_values = [
{
value = "CHANGE_ME"
target = ["production", "preview", "development"]
}
]
},
"NEXT_PUBLIC_PAYMENT_APP_ID": {
comment = "Public ID of the payment app for the storefront"
envs_values = [
{
value = "CHANGE_ME"
target = ["production", "preview", "development"]
}
]
}
}

Deploy the Storefront​

After configuring the environment variables, you can deploy the storefront to Vercel using Terraform.

First, run the following command to see what changes will be made:

terraform plan

If everything looks good, apply the changes to deploy the storefront. This command will prompt you to confirm the changes. Type yes to proceed.

terraform apply

If you have configured everything correctly, Terraform will create the necessary resources in Vercel and deploy your storefront.

Now you can push your changes to the GitHub repository to trigger the deployment on Vercel:

git add .
git commit -m "Configure Terraform for storefront deployment"
git push origin main