Skip to content

Instantly share code, notes, and snippets.

@pizofreude
Created April 17, 2025 17:10
Show Gist options
  • Save pizofreude/1d77dc0a217d175fa195988e62b0146e to your computer and use it in GitHub Desktop.
Save pizofreude/1d77dc0a217d175fa195988e62b0146e to your computer and use it in GitHub Desktop.
Terraform Code Artifacts and Descriptions

Terraform Code Artifacts and Descriptions

  • providers.tf
    Description: The providers.tf file is used to configure and declare provider settings in Terraform. Providers enable Terraform to interact with cloud platforms (e.g., AWS, Azure, GCP) or other services. This file specifies provider versions, regions, and authentication methods.

  • variables.tf
    Description: The variables.tf file defines input variables for Terraform configurations. These variables allow parameterization of values like resource names, regions, or instance types, making configurations more reusable and dynamic.

  • outputs.tf
    Description: The outputs.tf file is used to expose the results of a Terraform run. It outputs values, such as IP addresses, URLs, or resource attributes, for use by other configurations, tools, or workflows.

  • main.tf
    Description: The main.tf file serves as the core configuration file in Terraform. It typically contains the main resource definitions and logic for creating and managing infrastructure resources.

  • terraform.tfvars
    Description: The terraform.tfvars file is used to define variable values for Terraform configurations. By separating variable values from the configuration files, it allows for better management and flexibility across different environments.

  • backend.tf
    Description: The backend.tf file configures the backend for Terraform's state management. It specifies where the state file is stored, such as in an S3 bucket or a local file, ensuring proper tracking and collaboration.

  • data.tf
    Description: The data.tf file is used to define data sources in Terraform. Data sources allow Terraform to fetch or reference existing resources without creating new ones, enabling integration with pre-existing infrastructure.

  • locals.tf
    Description: The locals.tf file is used to define local values that simplify and group expressions in Terraform. These local values are reusable throughout the configuration for better readability and maintainability.

  • modules/
    Description: The modules/ directory contains reusable modules in Terraform. Modules encapsulate groups of resources and logic, enabling modular, DRY (Don't Repeat Yourself) practices for complex configurations.

  • versions.tf
    Description: The versions.tf file is used to specify required versions for Terraform and its providers. This ensures compatibility and avoids unintended behavior caused by version mismatches.

  • environment.tfvars
    Description: The environment.tfvars file is typically used to define environment-specific variable overrides. It allows configurations to adapt to environments like development, staging, or production.

  • terraform.lock.hcl
    Description: The terraform.lock.hcl file is an auto-generated dependency lock file. It ensures that Terraform uses the same dependency versions across runs, improving consistency and reducing unexpected changes.

  • init.sh
    Description: The init.sh file is a custom script that may be used to automate the initialization of Terraform configurations, including commands like terraform init and setting up required environment variables.

@pizofreude
Copy link
Author

pizofreude commented Apr 17, 2025

Additional Terraform Code Artifacts and Descriptions - AWS

  • s3.tf
    Description: The s3.tf file is used to define and manage AWS S3 buckets and related configurations. This includes bucket policies, versioning, encryption, and lifecycle rules for efficient and secure object storage.

  • iam.tf
    Description: The iam.tf file is used to manage AWS Identity and Access Management (IAM) resources. It defines users, roles, policies, groups, and permissions to securely control access to AWS resources.

  • vpc.tf
    Description: The vpc.tf file is used to define Virtual Private Cloud (VPC) resources, including subnets, route tables, internet gateways, and security groups. It sets up networking infrastructure for secure and scalable applications.

  • ec2.tf
    Description: The ec2.tf file is used to define configurations for AWS EC2 instances. This includes instance type, AMI, key pairs, and security group associations to launch virtual machines.

  • rds.tf
    Description: The rds.tf file is used to manage AWS Relational Database Service (RDS) resources. It defines database instances, clusters, parameter groups, and backups for managed SQL databases.

  • eks.tf
    Description: The eks.tf file is used to configure an AWS Elastic Kubernetes Service (EKS) cluster. It defines cluster nodes, networking, and IAM roles needed for running containerized workloads.

  • alb.tf
    Description: The alb.tf file is used to configure Application Load Balancers (ALB). It includes listener rules, target groups, and health checks for managing web traffic efficiently.

  • cloudwatch.tf
    Description: The cloudwatch.tf file is used to define CloudWatch log groups, metrics, and alarms for monitoring the health and performance of AWS resources.

  • lambda.tf
    Description: The lambda.tf file is used to manage AWS Lambda functions. It defines function configurations, triggers, and permissions for running serverless workloads.

  • sns.tf
    Description: The sns.tf file is used to configure AWS Simple Notification Service (SNS). It includes topics, subscriptions, and policies for messaging and alerting.

  • sqs.tf
    Description: The sqs.tf file is used to define AWS Simple Queue Service (SQS) configurations. It includes queue attributes, policies, and dead-letter queue settings for asynchronous messaging.

  • route53.tf
    Description: The route53.tf file is used to manage AWS Route 53 resources. It defines DNS zones, records, and configurations for domain name management.

  • autoscaling.tf
    Description: The autoscaling.tf file is used to configure auto-scaling groups and policies. It ensures scalability and high availability by dynamically adjusting resource capacity.

  • elasticache.tf
    Description: The elasticache.tf file is used to manage AWS ElastiCache resources. It defines Redis or Memcached clusters for in-memory caching solutions.

  • ecr.tf
    Description: The ecr.tf file is used to manage AWS Elastic Container Registry (ECR). It defines repositories and lifecycle policies for storing and managing Docker container images.

  • cloudfront.tf
    Description: The cloudfront.tf file is used to configure AWS CloudFront distributions. It defines content delivery settings, origins, and caching policies for low-latency delivery of web content.

  • kms.tf
    Description: The kms.tf file is used to manage AWS Key Management Service (KMS) resources. It defines encryption keys and policies for securely managing sensitive data.

  • dynamodb.tf
    Description: The dynamodb.tf file is used to define AWS DynamoDB tables and configurations. It includes table attributes, indexes, and throughput settings for NoSQL database solutions.

  • elasticbeanstalk.tf
    Description: The elasticbeanstalk.tf file is used to configure AWS Elastic Beanstalk applications, environments, and settings for deploying and managing scalable web applications.

@pizofreude
Copy link
Author

pizofreude commented Apr 17, 2025

.gitignore for Terraform

When working with Terraform, you should include the following items in your .gitignore file to avoid committing sensitive data, temporary files, and unnecessary state-related files to your repository:

# IaC - Terraform
## Local Terraform directories
.terraform/
.terraform.lock.hcl

## Terraform state files
*.tfstate
*.tfstate.backup

## Crash logs
crash.log

## Override files (used for local configurations)
*.tfvars
*.tfvars.json

## Sensitive files
*.auto.tfvars
*.auto.tfvars.json

## Plan output files
*.tfplan

## Ignore editor or system-specific files
.DS_Store
Thumbs.db
*.swp
*.bak
*.tmp

Explanation of the entries:

  1. .terraform/: The directory where Terraform downloads provider plugins and stores temporary files. This is system-specific and should not be committed.
  2. .terraform.lock.hcl: The dependency lock file. While optional, it is generally a good practice to commit this file to ensure consistent provider versions, but you may choose to ignore it in specific cases.
  3. *.tfstate and *.tfstate.backup: State files that store the current state of your infrastructure. These files often contain sensitive information (e.g., secrets, IDs) and should never be committed.
  4. crash.log: Logs generated when Terraform crashes. Useful for debugging but not relevant to version control.
  5. *.tfvars and *.tfvars.json: Files used to define variable values, often containing sensitive data like passwords or API keys.
  6. *.auto.tfvars and *.auto.tfvars.json: Automatically loaded variable files, often containing sensitive configuration data.
  7. *.tfplan: Files generated by terraform plan commands for storing execution plans. These are ephemeral and not required for version control.
  8. Editor/OS-specific files: Files like .DS_Store, Thumbs.db, or *.swp are generated by text editors or operating systems and should be ignored.

This .gitignore ensures that sensitive information and unnecessary files are excluded from your repository. Let me know if you'd like any clarifications or additions!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment