title: Terraform - Multiple accounts with multiple environments (regions)
body: <p>I am developing the infrastructure (IaC) I want to have in <strong>AWS</strong> with <strong>Terraform</strong>. To test, I am using an EC2 instance.</p>
  <p>This code has to be able to be deployed <strong>across multiple accounts</strong> and **multiple regions (environments) per developer **. This is an example:</p>
  <p><strong>account-999</strong></p>
  <pre><code>developer1: us-east-2
  developer2: us-west-1
  developerN: us-east-1
  </code></pre>
  <p><strong>account-666</strong>:</p>
  <pre><code>Staging: us-east-1
  Production: eu-west-2
  </code></pre>
  <p>I've created two <code>.tfvars</code> variables, <code>account-999.env.tfvars</code> and <code>account-666.env.tfvars</code> with the following content:</p>
  <ul>
  <li><code>profile=&quot;account-999&quot;</code> and  <code>profile=&quot;account-666&quot;</code> respectively</li>
  </ul>
  <p>This is my <code>main.tf</code> which contains the aws provider with the EC2 instance:</p>
  <pre><code>provider &quot;aws&quot; {
    version = &quot;~&gt; 2.0&quot;
    region  = &quot;us-east-1&quot;
    profile = var.profile
  }
  
  data &quot;aws_ami&quot; &quot;ubuntu&quot; {
    most_recent = true
  
    filter {
      name   = &quot;name&quot;
      values = [&quot;ubuntu/images/hvm-ssd/ubuntu-focal-20.04-amd64-server-*&quot;]
    }
  
    filter {
      name   = &quot;virtualization-type&quot;
      values = [&quot;hvm&quot;]
    }
  
    owners = [&quot;099720109477&quot;]
  }
  
  resource &quot;aws_instance&quot; &quot;web&quot; {
    ami           = data.aws_ami.ubuntu.id
    instance_type = &quot;t3.micro&quot;
  
    tags = {
      Name = &quot;HelloWorld&quot;
    }
  }
  </code></pre>
  <p>And the <code>variable.tf</code> file:</p>
  <pre><code>variable &quot;profile&quot; {
    type=string
  }
  
  variable &quot;region&quot; {
    description = &quot;Region by developer&quot;
    type = map
    default = {
      developer1 = &quot;us-west-2&quot;
      developer2 = &quot;us-east-2&quot;
      developerN = &quot;ap-southeast-1&quot;
    }
  }
  </code></pre>
  <p>But I'm not sure if I'm managing it well. For example, the <code>region</code> variable only contains the values of the <code>account-999</code> account. How can I solve that?
  On the other hand, with this structure, would it be possible to implement modules?</p>