We do not recommend to manually run terraform for syntax verification. You should rather run the 2 following commands:

terraform fmt
terraform validate
1
2

If you still need to run the terraform manually for debugging purposes, you have 2 steps to follow.

Merge: The merge is linked to the pipeline configuration and merge-catalog-and-config tasks. See example

But you should usually be able to reproduce it with the following commands:

Example path of a private service catalog for the infrastructure stack

rsync -av --delete \
--exclude=".terraform" \
--exclude="provider.tmp.tf" \
--exclude="terraform.tfstate*" .../stack/stack-infrastructure/terraform/ ./
rsync -av .../config/infrastructure/terraform/infra/ ./
1
2
3
4
5

Configure: Stacks use Terraform with a remote state file on Amazon S3. To be able to determine the path and the bucket name used to configure Terraform, have a look in the pipeline configuration for the Terraform resource

Sample of pipeline yaml file:

terraform_storage_bucket_path: "($ project $)/($ environment $)"


resources:
- name: terraform-magento-((env))
  type: terraform
  icon: terraform
  source:
    env_name: ((env))
    backend_type: s3
    backend_config:
      bucket: ((terraform_storage_bucket_name))
      # When using a non-default workspace, the state path will be /workspace_key_prefix/env_name/key
      key: ((project))-((env)).tfstate
      workspace_key_prefix: ((project))
...
jobs:
        - put: terraform-magento-((env))
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18

The bucket name and path can be found in the declaration of the Terraform resource. And the tfstate file name could be find in jobs which use this resource as env_name.

If your stack follow our practices, the path of the final tfstate file should look like something close to: s3://<orgname>-terraform-remote-state/<project>/<env>/<project>-<env>.tfstate Then with those information you should be able to generate a temporary provider.tmp.tf file to configure your local terraform to use the remote tfstate file.

export BUCKET="example-terraform-remote-state"
export ENV="test"
export PROJECT="magento"

# Key you configured in Cycloid credentials  manager.
export AWS_ACCESS_KEY_ID="<Amazon accessKey>"
export AWS_SECRET_ACCESS_KEY="<Amazon secretKey>"
export AWS_REGION="eu-west-1"

echo "terraform {
  backend \"s3\" {
    bucket = \"$BUCKET\"
    key    = \"$PROJECT/$ENV/$PROJECT-$ENV.tfstate\"
    region = \"$AWS_REGION\"
  }
}" > provider.tmp.tf

# Run terraform
terraform init -backend=true
terraform plan -var access_key=$AWS_ACCESS_KEY_ID -var secret_key=$AWS_SECRET_ACCESS_KEY
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20