This repository contains Terraform code for provisioning infrastructure. The following documentation describes the code, its dependencies, requirements, configuration, usage, and examples.
The Terraform code in this folder is designed to automate the deployment and management of cloud resources. It leverages Terraform as the Infrastructure as Code (IaC) tool and may integrate with external providers such as DigitalOcean via doctl.
- terraform: Required for running and applying the infrastructure code. Install Terraform. Should also work with Opentofu but hasn't been tested.
- doctl (optional): Command-line tool for managing DigitalOcean resources. Install doctl.
- tfenv (optional): Terraform version manager for easily switching between Terraform versions. Install tfenv.
- direnv (optional): Environment variable manager for loading project-specific environment variables automatically. Install direnv.
- Terraform v1.10 or higher (recommended to manage via tfenv)
- doctl (if DigitalOcean provider is used)
- tfenv (for managing Terraform versions)
- direnv (for managing environment variables)
- API credentials for the cloud provider (e.g., DigitalOcean API token)
- Internet access for downloading provider plugins
-
Clone the repository:
git clone https://github.com/AndDeluiz/bootcamp-devops-com-ia-iac.git
-
Set up provider credentials:
- For DigitalOcean, export your API token:
export TF_VAR_digitalocean_token=your_token_here - For other providers, refer to their documentation.
- For DigitalOcean, export your API token:
-
Configure
locals.tffile according to your needs:locals { default_region = "nyc1" default_tags = "project:bootcamp-devops-com-ia" # separate tags with commas if more than one tag is needed k8s_cluster = { "prd" = { cluster_name = "doks-${local.default_region}-prd-cluster-01" cluster_region = local.default_region cluster_version = "1.33.1-do.5" # list versions with "doctl kubernetes options versions" command cluster_ha = false cluster_tags = ["env:prd", "${local.default_tags}"] np_name = "doks-${local.default_region}-prd-cluster-01-np-001" np_size = "s-2vcpu-4gb" # list sizes with "doctl compute size list" command np_node_count = 2 np_autoscale = false np_tags = ["env:prd", "nodetype:std", local.default_tags] vpc_uuid = digitalocean_vpc.this.id } } db_pgsql = { "prd" = { name = "dodb-${local.default_region}-prd-pgsql-cluster-01" engine = "pg" size = "db-s-1vcpu-1gb" # list sizes with "doctl database options slugs --engine pg" command version = "17" region = local.default_region node_count = 1 vpc_uuid = digitalocean_vpc.this.id tags = ["env:prd", local.default_tags] } "hml" = { name = "dodb-${local.default_region}-hml-pgsql-cluster-01" engine = "pg" size = "db-s-1vcpu-1gb" # list sizes with "doctl database options slugs --engine pg" command version = "17" region = local.default_region node_count = 1 vpc_uuid = digitalocean_vpc.this.id tags = ["env:hml", "${local.default_tags}"] } } }
-
Initialize Terraform:
terraform init
-
Review the plan:
terraform plan
-
Apply the changes:
terraform apply
Confirm the action when prompted.
| Name | Version |
|---|---|
| digitalocean | 2.68.0 |
| Name | Version |
|---|---|
| digitalocean | 2.68.0 |
No modules.
| Name | Type |
|---|---|
| digitalocean_database_cluster.this | resource |
| digitalocean_kubernetes_cluster.this | resource |
| digitalocean_vpc.this | resource |
| Name | Description | Type | Default | Required |
|---|---|---|---|---|
| digitalocean_token | Digital Ocean API token. | string |
n/a | yes |
| Name | Description |
|---|---|
| db_clusters | n/a |
| db_credentials | n/a |
| k8s_clusters | Output definitions |
| kubeconfig | n/a |
- State files (
terraform.tfstate*) and.terraform*directories are ignored and should not be committed. - Always review changes with
terraform planbefore applying. - Refer to individual
.tffiles for specific resource configurations.