How to structure Terraform directory for multiple accounts

Follows on from the Terraform provider thread with @sblue’s support.

Background
Our setup has about 40 sub-accounts under the main Enterprise-level account. As such, scalability is a major concern when looking to implement any changes. As a result, we’re looking to shift orchestration into Terraform in order to afford a level automation and self-documentation that goes beyond NerdGraph/API.

Request
So what is the best way to structure our code and directory to enable reusability of modules as well as per-account-level tweaks?

Suggestion
I’ve been considering a structure as follows.

.
|—modules
| |—alert_policies.tf
| |—alert_conditions.tf
| |—versions.tf
|—environments
| |—account_alpha.tf
| |—account_bravo.tf
| |—versions.tf

This would allow us to:

  • Reference the same set of resources present in “modules” to be shared across our clients, much like a template.
    E.g., base set of alerting that should be present across all sub-accounts.

  • Each sub-account can individually override certain resources if required, using the template as a base.
    E.g., tweak the thresholds, depending on the sub-account’s requirements.

How can we shape our code structure to target this use-case? It’d be a big win for scalability to allow this sort flexibility within the configuration.

Thank you.

Hi @rishav.dhar, at this moment in time, New Relic does not offer support for Terraform but hopefully someone else on the community might have some working experience here.

1 Like

Hi @rishav.dhar I’ve commented on the Github Issue, we’ll take a look at this problem you’ve reported.

1 Like

Thanks, @jvajda. Did you mean to comment on this other thread?

Since this post, I’ve managed to prototype and open-source a project which delivers on this.

Any feedback is welcome and appreciated on the dedicated thread, thanks.