2

Please tell me if there is any way to make some Terraspace stack common for a few environments? For example, I have one AWS account for all non-production environments and I'd like to use the same VPC for all environments, all other resources (e.g. EC2, RDS, SQS, etc.) will be different and specific for each environment. So is there any way to share a state (first of all output) of a common VPC stack to other environments (dev, stage, test, etc.) and how to prevent applying of VPC stack separately to each environment on terraspace build <environment> stage?

Kushan Gunasekera
  • 7,268
  • 6
  • 44
  • 58
John
  • 41
  • 2
  • Did you ever find a solution to this? I am trying to accomplish a similar issue using one VPC (terraspace stack) for multiple environments (all other necessary AWS resources, ECS, SG, Elasticache, etc...) – Ode Aug 23 '23 at 17:59

1 Answers1

-2

Hello you can create modules each module will represent a stack and use the across you environments . A module is a container for multiple resources that are used together. Modules can be used to create lightweight abstractions, so that you can describe your infrastructure in terms of its architecture, rather than directly in terms of physical objects.

Here's a ref

for exemple image your stack is like that :

stage
  └ vpc
  └ services
      └ frontend-app
      └ backend-app
  └ data-storage
      └ mysql
      └ redis
prod
  └ vpc
  └ services
      └ frontend-app
      └ backend-app
  └ data-storage
      └ mysql
      └ redis
mgmt
  └ vpc
  └ services
      └ bastion-host
      └ jenkins
global
  └ iam
  └ s3

So you create modules if you want in a seperate git project and use the modules in each env :

live.git
  └ stage
      └ vpc
      └ services
          └ frontend-app
          └ backend-app
      └ data-storage
          └ mysql
          └ redis
  └ prod
      └ vpc
      └ services
          └ frontend-app
          └ backend-app
      └ data-storage
          └ mysql
          └ redis
  └ mgmt
      └ vpc
      └ services
          └ bastion-host
          └ jenkins
  └ global
      └ iam
      └ s3
modules.git
  └ data-stores
       └ mysql
       └ redis           
  └ mgmt
       └ vpc           
       └ jenkins           
  └ security
       └ iam
       └ s3
       └ bastion-host
  └ services
       └ webserver-cluster

here's a Link on how to create modules

Montassar Bouajina
  • 1,482
  • 1
  • 8
  • 20
  • 1
    Thanks for your answer. In this topic, I rather try to understand how to share output from one of the stacks (here the stack in Terraspace terminology) to a few Terraspace environments. This question not about modules or sharing output in general, but about Terraspace-specific cases. – John Nov 18 '20 at 10:44
  • I was hopeful for a minute that this would solve my issues as I am trying to do a similar thing. One VPC for multiple environments. I find that the Terraspace code is lacking to be able to allow this and would take a bit of work. So unfortunately you will be left doing data lookups on everything that uses that VPC instead of relying on remote state for any VPC related values. – Ode Aug 23 '23 at 17:58