I have two AWS accounts, one for dev and other for prod. I am trying to create the same resources in both accounts as VPC, subnet, etc. From reading on google I came up with the following structure:
|---- README.md
|---- dev_account
|---- main.tf
|---- terraform.tfvars
|---- variables.tf
|---- prod_account
|---- main.tf
|---- terraform.tfvars
|---- variables.tf
|---- modules
|---- provider.tf
|---- vpc.tf
|---- variables.tf
Here is some code I am using:
modules/provider.tf
provider "aws" {
region = "${var.aws_region}"
}
module/vpc.tf
resource "aws_vpc" "vpc" {
cidr_block = "${var.vpc_cidr_block}"
instance_tenancy = "default"
}
dev_account/main.tf:
module "create_infra" {
source = "../modules"
aws_region = "${var.aws_region}"
vpc_cidr_block = "${var.vpc_cidr_block}"
}
Same as above I will create more modules like subnet and call from main.tf file.
dev_account/variables.tf
variable "aws_region" {}
variable "vpc_cidr_block" {}
dev_account/terraform.tfvars
aws_region = "us-west-1"
vpc_cidr_block = "10.10.10.0/8"
Is this the right approach? Is there a better way of doing this? main.tf file under dev_account does not seem correct, as it will get difficult to manage if I will have let's say 10 or more resources.