https://github.com/harisekhon/terraform
Terraform HCL code for AWS / GCP / Azure / GitHub management
https://github.com/harisekhon/terraform
aws cloudflare devops gcp github hacktoberfest hcl terraform
Last synced: 4 months ago
JSON representation
Terraform HCL code for AWS / GCP / Azure / GitHub management
- Host: GitHub
- URL: https://github.com/harisekhon/terraform
- Owner: HariSekhon
- License: mit
- Created: 2021-01-18T18:09:50.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2024-09-17T12:09:59.000Z (about 1 year ago)
- Last Synced: 2024-09-17T14:53:45.000Z (about 1 year ago)
- Topics: aws, cloudflare, devops, gcp, github, hacktoberfest, hcl, terraform
- Language: HCL
- Homepage: https://www.linkedin.com/in/HariSekhon
- Size: 351 KB
- Stars: 42
- Watchers: 2
- Forks: 22
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
- Codeowners: .github/CODEOWNERS
- Security: security_groups.tf
Awesome Lists containing this project
README
# Terraform Templates
[](https://github.com/HariSekhon/Terraform//stargazers)
[](https://github.com/HariSekhon/Terraform/network)
[](https://github.com/boyter/scc/)
[](https://github.com/boyter/scc/)
[](https://github.com/HariSekhon/Terraform/blob/master/LICENSE)
[](https://www.linkedin.com/in/HariSekhon/)
[](https://github.com/HariSekhon/Terraform/commits/master)[](https://harisekhon.github.io/CI-CD/)
[](https://github.com/HariSekhon/Terraform/actions/workflows/terraform-fmt-write.yaml)
[](https://github.com/HariSekhon/Terraform/actions/workflows/yaml.yaml)
[](https://github.com/HariSekhon/Terraform/actions/workflows/shellcheck.yaml)
[](https://github.com/HariSekhon/Terraform/actions/workflows/markdown.yaml)
[](https://github.com/HariSekhon/Terraform/actions/workflows/validate.yaml)
[](https://github.com/HariSekhon/Terraform/actions/workflows/tfsec.yaml)
[](https://github.com/HariSekhon/Terraform/actions/workflows/checkov.yaml)
[](https://github.com/HariSekhon/Terraform/actions/workflows/grype.yaml)
[](https://github.com/HariSekhon/Terraform/actions/workflows/kics.yaml)
[](https://github.com/HariSekhon/Terraform/actions/workflows/semgrep.yaml)
[](https://github.com/HariSekhon/Terraform/actions/workflows/semgrep-cloud.yaml)
[](https://github.com/HariSekhon/Terraform/actions/workflows/trivy.yaml)[](https://github.com/HariSekhon/Terraform)
[](https://gitlab.com/HariSekhon/Terraform)
[](https://dev.azure.com/harisekhon/GitHub/_git/Terraform)
[](https://bitbucket.org/HariSekhon/Terraform)[git.io/tf-templates](https://git.io/tf-templates)
Terraform templates for AWS / GCP / Azure.
Forked from the [Templates](https://github.com/HariSekhon/Templates) repo for which this is now a submodule.
## New
`new.pl` can instantiate these templates as new date-timestamped files, autopopulating the date, vim tags, GitHub URL and other headers and drops you in to your `$EDITOR` of choice (eg. `vim`).
You can give an exact filename like `provider.tf` or `backend.tf` to instantiate that exact template, or any filename ending in `.tfvars` will instantitate some common terraform variables such as `project`, `region`, `vpc_name` etc... otherwise any filename ending in `tf` will give you a blank terraform template.
Examples:
```bash
new provider.tf
``````bash
new backend.tf
````new.pl` can be found in the [DevOps Perl tools](https://github.com/HariSekhon/DevOps-Perl-tools) repo.
`alias new=new.pl`
(done automatically in the [DevOps Bash tools](https://github.com/HariSekhon/DevOps-Bash-tools) repo `.bash.d/`)
### New Terraform Structure
```bash
new terraform
```or shorter:
```bash
new tf
```Instantly creates and opens all standard files for a Terraform deployment in your `$EDITOR` of choice:
- [provider.tf](https://github.com/HariSekhon/Terraform/blob/master/provider.tf)
- [backend.tf](https://github.com/HariSekhon/Terraform/blob/master/backend.tf)
- [variables.tf](https://github.com/HariSekhon/Terraform/blob/master/variables.tf)
- [versions.tf](https://github.com/HariSekhon/Terraform/blob/master/versions.tf)
- [terraform.tfvars](https://github.com/HariSekhon/Terraform/blob/master/terraform.tfvars)
- [main.tf](https://github.com/HariSekhon/Terraform/blob/master/main.tf)all heavily commented to get a new Terraform environment up and running quickly - with links to things like AWS / GCP regions, Terraform backend providers, state locking etc.
## Troubleshooting
### DeleteConflict: Recreating Resources with Dependencies That Do Not Permit Deletion
Example:
`│Error: error deleting IAM policy arn:aws:iam::***:policy/MYPOLICY: DeleteConflict: Cannot delete a policy attached to entities.`The Terraform AWS Provider does not help you when you recreate a resource that another resources depends on, such as recreating an IAM policy due to a rename, while it is still attached to a role, or recreating an AWS Batch compute environment while it's still attached to queues.
Unfortunately the Terraform AWS Provider isn't smart enough to know that for such dependencies with AWS specific API constraints that it should simply detach, and then reattach afterwards.
The quickest solution / workaround is to find the dependent resources, and `terraform taint` them so that they are destroyed first using the generic implicit Terraform dependency ordering, eg. the role gets deleted first for recreation because its tainted, then the IAM policy is deleted and recreated with the new name, and then the role is recreated and attached to the new policy.
Example:
`terraform taint `
## Terraform CI/CD
Production-grade Terraform CI/CD pipelines can be found for Jenkins and GitHub Actions in my adjacent repos:
- [Jenkins](https://github.com/HariSekhon/Jenkins) - runs terraform code with a specific version of Terraform:
- `fmt` (info only)
- `validate`
- `plan` (saves plan so apply is this exact plan, recommended)
- prompts for plan approval
- runs `apply`
- has full locking and milestones for Plan and Apply stages for serialized queuing to avoid terraform state lock failures
- skips intermediate queued runs for efficiency- [GitHub Actions](https://github.com/HariSekhon/GitHub-Actions) - similar to above, plus:
- optional environment / approvals (protects admin credentials for things like GitHub which doesn't have read-only repo API tokens)
- posts the full `terraform plan` result into the Pull Request that triggered the workflow, along with the status of `fmt` & `validate`
- applies once Pull Request is merged to the default branch or master or main### Jenkins screenshots
Applied, ignoring informational fmt check:

Plan found no changes so skipped Apply or asking for Approval:

Plan found changes but Approval was not authorized, so Apply did not proceed:

## Star History
[](https://star-history.com/#HariSekhon/Terraform&Date)
[git.io/tf-templates](https://git.io/tf-templates)
## More Core Repos
### Knowledge
[](https://github.com/HariSekhon/Knowledge-Base)
[](https://github.com/HariSekhon/Diagrams-as-Code)### DevOps Code
[](https://github.com/HariSekhon/DevOps-Bash-tools)
[](https://github.com/HariSekhon/DevOps-Python-tools)
[](https://github.com/HariSekhon/DevOps-Perl-tools)
[](https://github.com/HariSekhon/DevOps-Golang-tools)### Containerization
[](https://github.com/HariSekhon/Kubernetes-configs)
[](https://github.com/HariSekhon/Dockerfiles)### CI/CD
[](https://github.com/HariSekhon/GitHub-Actions)
[](https://github.com/HariSekhon/Jenkins)### DBA - SQL
[](https://github.com/HariSekhon/SQL-scripts)
### DevOps Reloaded
[](https://github.com/HariSekhon/Nagios-Plugins)
[](https://github.com/HariSekhon/HAProxy-configs)
[](https://github.com/HariSekhon/Terraform)
[](https://github.com/HariSekhon/Packer-templates)
[](https://github.com/HariSekhon/Nagios-Plugin-Kafka)### Templates
[](https://github.com/HariSekhon/Templates)
[](https://github.com/HariSekhon/Template-repo)### Misc
[](https://github.com/HariSekhon/Spotify-tools)
[](https://github.com/HariSekhon/Spotify-playlists)The rest of my original source repos are
[here](https://github.com/HariSekhon?tab=repositories&q=&type=source&language=&sort=stargazers).Pre-built Docker images are available on my [DockerHub](https://hub.docker.com/u/harisekhon/).
