From 30325f1396318247d550a99fb7aba444995543f2 Mon Sep 17 00:00:00 2001 From: abduvik Date: Sun, 23 Oct 2022 19:37:07 +0200 Subject: [PATCH 1/2] Add content for terraform --- courses/terraform/README.md | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 courses/terraform/README.md diff --git a/courses/terraform/README.md b/courses/terraform/README.md new file mode 100644 index 0000000..2d240ce --- /dev/null +++ b/courses/terraform/README.md @@ -0,0 +1,31 @@ +# Terraform + +## YouTube + +## Summary + +Terraform consists of: + +- Providers: Allow connecting the configuration to the cloud provider API +- tfstate file: It stores the current state of our architecture. Must be encrypted. + +Important Commands + +- `terraform init`: Add required providers plugins code +- `terraform plan`: Check what will change to our system +- `terraform apply`: Apply the changes +- `terraform destroy`: Delete the whole system. + +Every resource consists of like this + +```tf +resource "_" "" { + = +} +``` + +We can reference data from one resource into another resouce + +``` +vpc_id = _.. +``` From 62e431524dcd66246ce5e534670a3b2aa263393b Mon Sep 17 00:00:00 2001 From: abduvik Date: Fri, 30 Dec 2022 23:15:34 +0100 Subject: [PATCH 2/2] Add --- courses/terraform/README.md | 83 ++++++++++++++++++++++++++++++++++++- 1 file changed, 81 insertions(+), 2 deletions(-) diff --git a/courses/terraform/README.md b/courses/terraform/README.md index 2d240ce..fe0c81c 100644 --- a/courses/terraform/README.md +++ b/courses/terraform/README.md @@ -7,7 +7,7 @@ Terraform consists of: - Providers: Allow connecting the configuration to the cloud provider API -- tfstate file: It stores the current state of our architecture. Must be encrypted. +- `*.tfstate` file: It stores the current state of our architecture. Must be encrypted. Important Commands @@ -18,7 +18,7 @@ Important Commands Every resource consists of like this -```tf +```terraform resource "_" "" { = } @@ -29,3 +29,82 @@ We can reference data from one resource into another resouce ``` vpc_id = _.. ``` + +Terraform gives support to concepts similar to other programming languages like: + +- Variables +- Outputs +- Conditionals & Loops +- Modules + +### Variables + +To create a variable + +```tf +variable "instance_type" { + description = "just a description for the variable" + type = string # also boolean & number + default = "default value" + sensitive = true # in case of sensitive data to hide from logs +} +``` + +to set the varibles we can + +- Manually entry in Terraform plan/apply +- Inside the `local` block +- `TF_VAR_` environment variables +- `*.tfvars` files +- Command Line `-var` and `-var-file` + +Types can be + +- Primative: string, number, bool +- Complex: list, set, mao, object, tuple + +### Outputs + +They are like the return of functions, when we run a certain resource, we get the object returns and we can reference them using the `output` block + +```tf +output "instance_ip_addr" { + value = aws_instance.server.private_ip +} +``` + +### Modules + +They are used to abstract creating multiple resources into a single module. They can be hosted on many places like: + +- Local paths +- Terraform Repository +- Git +- HTTP Urls +- S3 Buckets + +```tf +module "module_name" { + source "../webapp" # path to the module root directory + + # Input variables + bucket_name = "webapp-bucket" + domain = "example.com" +} +``` + +### Workspaces + +Terraform has workspaces to manage multiple environments + +- `terraform workspace list`: List available workspaces +- `terraform workspace new `: Create a new workspace +- `terraform workspace select `: Select a workspace + +Available variable is `terraform.workspace` for the current workspace + +We can also use files and directories structure to manage workspaces instead of using terraform workspaces and it's more recommended. + +## Resources + +- [Complete Terraform Course - From BEGINNER to PRO! (Learn Infrastructure as Code)](https://www.youtube.com/watch?v=7xngnjfIlK4)