Skip to main content

Running Terraform Plan Locally

Whilst it is possible to see the results of a Terraform plan when you create a pull request, it is also possible to run a Terraform plan locally. Some engineers prefer this as it provides a quicker feedback loop to identify any issues with your infrastructure code.

Enter your AWS SSO credentials

Get your AWS SSO credentials as detailed here, choose option 1 and paste the credentials into the terminal window you are working from.

Please note that the credentials will expire after a period of 1 hour.

Install Terraform

Follow the instructions here to install the latest version of Terraform according to your platform.

Retrieve the Modernisation Platform account ID

You will need the Modernisation Platform account ID to assume the correct role when running terraform init. You can retrieve the Modernisation Platform account ID from the SSM Parameter store via the web console, or via CLI. This will allow you to assume the correct role_arn.

aws ssm get-parameters --region eu-west-2 \
--names "modernisation_platform_account_id" --with-decryption --query "Parameters[*].{Value:Value}" --output text

Run Terraform plan

  1. Navigate to your application infrastructure code - cd modernisation-platform-environments/terraform/environments/my-application
  2. Run a Terraform init that assumes the backend role in the Modernisation Platform account - terraform init -backend-config=assume_role={role_arn=\"arn:aws:iam::000000000000:role/modernisation-account-terraform-state-member-access\"}

Remember to replace the 000000000000 placeholder with the Modernisation Platform account ID.

  1. View the workspaces (you have different workspaces for your different environment accounts) - terraform workspace list
  2. Select the required workspace - terraform workspace select my-application-development
  3. Run a Terraform plan - terraform plan

Running a plan locally has read only permissions, you will not be able to run an apply, destroy or import. The example syntax for assuming a backend role is appropriate for Terraform 1.6.0 onwards.

This page was last reviewed on 11 December 2023. It needs to be reviewed again on 11 June 2024 by the page owner #modernisation-platform .
This page was set to be reviewed before 11 June 2024 by the page owner #modernisation-platform. This might mean the content is out of date.