Bootstrap FreeKB - Terraform - Getting Started with Modules
Terraform - Getting Started with Modules

Updated:   |  Terraform articles

Let's say you have the following files on your Terraform server. In this example, there are 3 modules.

  • root module (the base directory that contains the provider.tf file)
  • foo module (the foo directory that contains it's own .tf files)
  • bar module (the bar directory that contains it's own .tf files)
├── locals.tf
├── modules.tf
├── outputs.tf
├── provider.tf
├── terraform.tfstate
├── variables.tf
├── foo (directory, child module)
│   ├── data.tf
│   ├── outputs.tf
│   ├── resources.tf
├── bar (directory, child module)
│   ├── data.tf
│   ├── outputs.tf
│   ├── resources.tf

 

For example, let's say you are using Terraform with the Amazon Web Services (AWS) provider. In this scenario, provider.tf might have something like this.

terraform {
  required_providers {
    aws = {
      source  = "hashicorp/aws"
    }
  }
}

provider "aws" {
  access_key = var.access_key
  secret_key = var.secret_key
  region     = var.region
}

 

And modules.tf could have something like this, to use the .tf files in the foo directory.

module "foo" {
  source = "./foo"
}

 

 




Did you find this article helpful?

If so, consider buying me a coffee over at Buy Me A Coffee



Comments


Add a Comment


Please enter 40a564 in the box below so that we can be sure you are a human.