4. Terraform Modules & Workspaces Flashcards
1
Q
Terraform Registry
- The Terraform Registry is a repository of modules written by the Terraform community.
- The registry can help you get started with Terraform more quickly
- If we intend to use a module, we need to define the path where the module files are present.
- The module files can be stored in multiple locations, some of these include:
- Local Path
- GitHub
- Terraform Registry
- S3 Bucket
- HTTP URLs
A
2
Q
Verified Modules in Terraform Registry
- Within Terraform Registry, you can find verified modules that are maintained by various third-party vendors.
- These modules are available for various resources like AWS VPC, RDS, ELB, and others
- Verified modules are reviewed by HashiCorp and actively maintained by contributors to stay up-to-date and compatible with both Terraform and their respective providers.
- The blue verification badge appears next to modules that are verified.
- Module verification is currently a manual process restricted to a small group of trusted HashiCorp partners.
A
3
Q
Using Registry Modules in Terraform
- To use Terraform Registry module within the code, we can make use of the source argument that contains the module path.
- The public registry uses a three-part format, and private modules use a four-part format.
- < NAMESPACE > / < MODULE NAME > / < PROVIDER>
- < HOSTNAME > / < ORGANIZATION > / < MODULE NAME > / < PROVIDER >
- Below code references to the EC2 Instance module within terraform registry.
module “ec2-instance” {
source = “terraform-aws-modules/ec2-instance/aws”
version = “2.13.0”
# insert the 10 required variables here
}
A
4
Q
Terraform Workspaces
- Terraform allows us to have multiple workspaces, with each of the workspaces we can have a different set of environment variables associated
- Terraform starts with a single workspace named “default”.
- This workspace is special both because it is the default and also because it cannot ever be deleted.
- If you’ve never explicitly used workspaces, then you’ve only ever worked on the “default” workspace.
- Workspaces are managed with the terraform workspace set of commands.
- To create a new workspace and switch to it, you can use terraform workspace new; to switch workspaces you can use terraform workspace select; etc.
- Custom workspace state file location: terraform.tfstate.d
- Workspaces, managed with the terraform workspace command, isn’t the same thing as Terraform Cloud’s workspaces. Terraform Cloud workspaces act more like completely separate working directories.
A
5
Q
Terraform Workspaces Commands
Usage: terraform workspace <subcommand> [options] [args]</subcommand>
- list
- select
- new
- delete
- show
A