boltops-tools / terraspace

Terraspace: The Terraform Framework
https://terraspace.cloud
Apache License 2.0
674 stars 46 forks source link

2 Features away to be the best Terraform Framework Ever #257

Open fenos opened 2 years ago

fenos commented 2 years ago

I'm opening this thread with the hope that the terraspace team understands how close they are to providing a perfect, simple, powerful framework for terraform.

If you could implement these 2 features there will be no look back for any infra engineer out there.

Here they are:

Global Resources

The first feature is to provide the ability to define global resources easily and intuitively.

Current:

At the moment when we need to define global resources such as route53 or networks (in gcp) the only weapon we have in our arsenal is to create "global" stacks and map them to a specific env ( TS_ENV=global) then, allow the stacks only when we run terraspace with that variable set.

The problem:

With the above approach, we have a few limitations that would make the feature not feasible to use. For instance:

Proposal

To make this essential feature work properly I would suggest the following:

Use Cases

Issue Ref: https://community.boltops.com/t/how-to-create-global-stacks/939/2

Nested Stacks

This is also a very high demanded feature from the community.

The Problem

Currently, the nested structure is not supported which forces us to bloat the top-level stacks folder making it very hard to reason about when the project grows

Proposal

We would like to be able to define nested stacks within a stack, and follow these rules:

Use Cases

Ref: https://community.boltops.com/t/nested-stack-folders/666

Final Considerations

I believe that the global resources management is one of the most important features that is missing. Nowadays cloud providers are abstracting lots of infrastructures to be globally available.

In one way or another, we'll always encounter these kinds of resources.

Thanks a lot for making terraspace, it is a super awesome framework.

Cross-posting for visibility: [Forum Post]

fenos commented 2 years ago

@tongueroo could you give me some direction for implementing the global resources feature

I will give it a try

tongueroo commented 2 years ago

Copy and pasing from the community post https://community.boltops.com/t/2-features-away-to-be-the-best-terraform-framework-ever/940/2

RE: I’m opening this thread with the hope that the terraspace team understands how close they are to providing a perfect, simple, powerful framework for terraform.

Thanks for the kind words.

RE: 1. Global Resources

Yup. Would like to support global resources. Sounds like the idea to have folders like:

app/stacks/demo/global

Unsure about that. Think global resources are typically shared by multiple stacks. So it would result in something like this

app/stacks/demo1/global
app/stacks/demo2/global

Which doesn't seem like the right fit. Glad to hear another idea though and maybe it'll help lead to an approach.

RE: 2. Nested Stacks

Yes. Would like to support this. Believe this might simply require a brute force approach to finding all areas in terraspace that makes the 1-depth level folder assumptions and tackle them. Will consider PRs.

RE: RE: 2. Nested Stacks Same State File

Unsure here. Gut says separate nested folders should have different state files. Believe the subfolders are mainly for organizational purposes. So for larger terraspace project app/stacks don't end up with too many folders. Making up a possible example:

app/stacks/network/vpc
app/stacks/network/security_groups
app/stacks/shared/rds
app/stacks/shared/ecs
app/stacks/shared/eks

Believe app/stacks/shared/ecs and app/stacks/shared/eks should would be able to deploy independently and still have different terraform state files. Maybe:

terraspace up shared/ecs
terraspace up shared/eks

Dunno. Figuring it out. 🧐


Wish had some more direction but unsure on the approach currently. Maybe it's one of those things were will need to let it simmer on the brain. 🤔 Think will continue discussion in the original community post until there's something more concrete. Thanks for sharing and opening issue though.

alisson276 commented 1 year ago

I fell into the same limitation. In our case, we have global images built by EC2 image builder and would like to share the same image in staging and production, but output helper is useless for this kind of thing. We ended up using the terraform_remote_state, but it would become much simpler if we could use something like output('infrastructure-ami-ecs_base.image', env: 'global')

Nested stacks are the most requested feature, I guess, because it helps when we have, I would say, more than 50 stacks/folders. There is another issue related to that: https://github.com/boltops-tools/terraspace/issues/214.