diff --git a/Days/IaC/Hello-world/main.tf b/Days/IaC/Hello-world/main.tf new file mode 100644 index 0000000..3f06a22 --- /dev/null +++ b/Days/IaC/Hello-world/main.tf @@ -0,0 +1,11 @@ +terraform { + # This module is now only being tested with Terraform 0.13.x. However, to make upgrading easier, we are setting + # 0.12.26 as the minimum version, as that version added support for required_providers with source URLs, making it + # forwards compatible with 0.13.x code. + required_version = ">= 0.12.26" +} + +# website::tag::1:: The simplest possible Terraform module: it just outputs "Hello, World!" +output "hello_world" { + value = "Hello, 90DaysOfDevOps from Terraform" +} \ No newline at end of file diff --git a/Days/IaC/Hello-world/terraform.tfstate b/Days/IaC/Hello-world/terraform.tfstate new file mode 100644 index 0000000..35f2fdf --- /dev/null +++ b/Days/IaC/Hello-world/terraform.tfstate @@ -0,0 +1,13 @@ +{ + "version": 4, + "terraform_version": "1.1.6", + "serial": 1, + "lineage": "a74296e7-670d-0cbb-a048-f332696ca850", + "outputs": { + "hello_world": { + "value": "Hello, 90DaysOfDevOps from Terraform", + "type": "string" + } + }, + "resources": [] +} diff --git a/Days/Images/Day58_IAC1.png b/Days/Images/Day58_IAC1.png new file mode 100644 index 0000000..72fbe78 Binary files /dev/null and b/Days/Images/Day58_IAC1.png differ diff --git a/Days/Images/Day58_IAC2.png b/Days/Images/Day58_IAC2.png new file mode 100644 index 0000000..108dc5d Binary files /dev/null and b/Days/Images/Day58_IAC2.png differ diff --git a/Days/Images/Day58_IAC3.png b/Days/Images/Day58_IAC3.png new file mode 100644 index 0000000..c5120ba Binary files /dev/null and b/Days/Images/Day58_IAC3.png differ diff --git a/Days/Images/Day58_IAC4.png b/Days/Images/Day58_IAC4.png new file mode 100644 index 0000000..cf619a7 Binary files /dev/null and b/Days/Images/Day58_IAC4.png differ diff --git a/Days/Images/Day59_IAC1.png b/Days/Images/Day59_IAC1.png new file mode 100644 index 0000000..dced9fd Binary files /dev/null and b/Days/Images/Day59_IAC1.png differ diff --git a/Days/Images/Day60_IAC1.png b/Days/Images/Day60_IAC1.png new file mode 100644 index 0000000..5103a09 Binary files /dev/null and b/Days/Images/Day60_IAC1.png differ diff --git a/Days/Images/Day61_IAC1.png b/Days/Images/Day61_IAC1.png new file mode 100644 index 0000000..6ddade0 Binary files /dev/null and b/Days/Images/Day61_IAC1.png differ diff --git a/Days/day58.md b/Days/day58.md index e69de29..247882a 100644 --- a/Days/day58.md +++ b/Days/day58.md @@ -0,0 +1,224 @@ +## HashiCorp Configuration Language (HCL) + +Before we start making stuff with Terraform we have to dive a little into HashiCorp Configuration Language (HCL). So far during our challenge we have looked at a few different scripting and programming languages and here is another one. We touched on the [Go programming language](Days/day07.md) then [bash scripts](Days/day19.md) we even touched on a little python when it came to [network automation](Days/day27.md) + +Now we must cover HashiCorp Configuration Language (HCL) if this is the first time you are seeing the language it might look a little daunting but its quite simple and ver powerful. + +As we move through this section, we are going to be using examples that we can run locally on our system regardless of what OS you are using, we will be using virtualbox albeit not the infrastructure platform you would be using with Terraform it is free and will allow us to achieve what we are looking to do we can also do this with Docker and Kubernetes. + +In general though you would or should be using Terraform to deploy your infrastructure in the public cloud (AWS, Google, Microsoft Azure) but then also in your virtualisation environments such as (VMware, Microsoft Hyper-V, Nutanix AHV) In the public cloud Terraform allows for us to do a lot more than just Virtual Machine automated deployment, we can create all the required infrastructure such as PaaS workloads and all of the networking required assets such as VPCs and Security Groups. + +There are two important aspects to Terraform we have the code which we are going to get into here and then we also have the state both of this together could be called the Terraform core. We then have the environment we wish to speak to and deploy into and we do this via providers, briefly mentioned in the last session but we have an AWS provider, we have an Azure providers etc. There are hundreds. + +### Basic Terraform Usage + +Let's take a look at a Terraform `.tf` file to see how they are made up. The first example we will walk through will in fact be code to deploy resources to AWS, this would then also require the AWS CLI to be installed on your system and configured for your account. + + +### Providers + +At the top of our `.tf` generally called main.tf at least until we make things more complex. Here we will define the providers that we have mentioned before. Our source of the aws provider as you can see is `hashicorp/aws` this means this provider is maintained or has been published by hashicorp themselves. + +``` +terraform { + required_providers { + aws = { + source = "hashicorp/aws" + version = "~> 3.0" + } + } +} +``` +We might also add in a region as well here to determine which AWS region we would like to provision to we can do this by adding the following: + +``` +provider "aws" { + region = "ap-southeast-1" //region where resources need to be deployed +} +``` + +### Resources + +- Another important component of a terraform config file which describes one or more infrastructure objects like EC2, Load Balancer, VPC, etc. + +- A resource block declares a resource of a given type ("aws_instance") with a given local name ("90daysofdevops"). + +- The resource type and name together serve as an identifier for a given resource. + + +``` +resource "aws_instance" "90daysofdevops" { + ami = data.aws_ami.instance_id.id + instance_type = "t2.micro" + availability_zone = "us-west-2a" + security_groups = [aws_security_group.allow_web.name] + user_data = <<-EOF + #! /bin/bash + sudo yum update + sudo yum install -y httpd + sudo systemctl start httpd + sudo systemctl enable httpd + echo " +
+
+Now that we have our code defined we can now perform the `terraform init` on our folder to download the provider for virtualbox.
+
+
+
+
+Obviously you will also need to have virtualbox installed on your system as well. We can then next run `terraform plan` to see what our code will create for us. Followed by `terraform apply`
+
+
+
+
+### Change configuration so that it then becomes a web server
+
+
+
+### Add additional virtual machine to change our desired state
+
+
+
+### Variables & Outputs
+
+We did mention outputs when we ran our hello-world example in the last session. But we can get into more detail here.
+
+But there are many other variables that we can use here as well, there are also a few different ways in which we can define variables.
+
+- We can manually enter our variables with the `terraform plan` or `terraform apply` command
+
+- We can define them in the .tf file within the block
+
+- We can use environment variables within our system using `TF_VAR_NAME` as the format.
+
+- My preference is to use a terraform.tfvars file in our project folder.
+
+- There is an *auto.tfvars file option
+
+- or we can define when we run the `terraform plan` or `terraform apply` with the `-var` or `-var-file`.
+
+Starting from the bottom moving up would be the order in which the variables are defined.
+
+We have also mentioned that the state file will contain sensitive information. We can define our sensitive information as a variable and we can define this as being sensitive.
+
+```
+variable "some resource" {
+ description = "something important"
+ type: string
+ sensitive = true
+
+}
+```
+
+
+
+
+Variables and Outputs
+Additional Language Features
+Project Organization + Modules
+Managing Multiple Environments
+Testing Terraform Code
+Developer Workflows and Automation
+
+
+
+
+## Resources
+I have listed a lot of resources down below and I think this topic has been covered so many times out there, If you have additional resources be sure to raise a PR with your resources and I will be happy to review and add them to the list.
+
+- [What is Infrastructure as Code? Difference of Infrastructure as Code Tools ](https://www.youtube.com/watch?v=POPP2WTJ8es)
+- [Terraform Tutorial | Terraform Course Overview 2021](https://www.youtube.com/watch?v=m3cKkYXl-8o)
+- [Terraform explained in 15 mins | Terraform Tutorial for Beginners ](https://www.youtube.com/watch?v=l5k1ai_GBDE)
+- [Terraform Course - From BEGINNER to PRO!](https://www.youtube.com/watch?v=7xngnjfIlK4&list=WL&index=141&t=16s)
+- [HashiCorp Terraform Associate Certification Course](https://www.youtube.com/watch?v=V4waklkBC38&list=WL&index=55&t=111s)
+- [Terraform Full Course for Beginners](https://www.youtube.com/watch?v=EJ3N-hhiWv0&list=WL&index=39&t=27s)
+- [KodeKloud - Terraform for DevOps Beginners + Labs: Complete Step by Step Guide!](https://www.youtube.com/watch?v=YcJ9IeukJL8&list=WL&index=16&t=11s)
+- [Terraform Simple Projects](https://terraform.joshuajebaraj.com/)
+- [Terraform Tutorial - The Best Project Ideas](https://www.youtube.com/watch?v=oA-pPa0vfks)
+- [Awesome Terraform](https://github.com/shuaibiyy/awesome-terraform)
+
+See you on [Day 57](day57.md)
\ No newline at end of file
diff --git a/Days/day60.md b/Days/day60.md
index e69de29..010ec38 100644
--- a/Days/day60.md
+++ b/Days/day60.md
@@ -0,0 +1,48 @@
+## Docker Containers, Provisioners & Modules
+
+Docker demo
+
+`terraform init`
+
+
+
+### Provisioners
+
+- file
+- local-exec
+- remote-exec
+- vendor
+ - ansible
+ - chef
+ - puppet
+
+### Modules
+
+Modules are containers for multiple resources that are used together. A module consists of a collection of .tf files in the same directory.
+
+Modules are a good way to separate your infrastructure resources as well as being able to pull in third party modules that have already been created so you do not have to re invent the wheel.
+
+For example if we wanted to use the same project to build out some VMs, VPCs, Security Groups and then also a Kubernetes cluster we would likely want to split our resources out into modules to better define our resources and where they are grouped.
+
+Another benefit to modules is that you can take these modules and use them on other projects or share publicly to help the community.
+
+We are breaking down our infrastructure into components, components are known here as modules.
+
+
+
+
+## Resources
+I have listed a lot of resources down below and I think this topic has been covered so many times out there, If you have additional resources be sure to raise a PR with your resources and I will be happy to review and add them to the list.
+
+- [What is Infrastructure as Code? Difference of Infrastructure as Code Tools ](https://www.youtube.com/watch?v=POPP2WTJ8es)
+- [Terraform Tutorial | Terraform Course Overview 2021](https://www.youtube.com/watch?v=m3cKkYXl-8o)
+- [Terraform explained in 15 mins | Terraform Tutorial for Beginners ](https://www.youtube.com/watch?v=l5k1ai_GBDE)
+- [Terraform Course - From BEGINNER to PRO!](https://www.youtube.com/watch?v=7xngnjfIlK4&list=WL&index=141&t=16s)
+- [HashiCorp Terraform Associate Certification Course](https://www.youtube.com/watch?v=V4waklkBC38&list=WL&index=55&t=111s)
+- [Terraform Full Course for Beginners](https://www.youtube.com/watch?v=EJ3N-hhiWv0&list=WL&index=39&t=27s)
+- [KodeKloud - Terraform for DevOps Beginners + Labs: Complete Step by Step Guide!](https://www.youtube.com/watch?v=YcJ9IeukJL8&list=WL&index=16&t=11s)
+- [Terraform Simple Projects](https://terraform.joshuajebaraj.com/)
+- [Terraform Tutorial - The Best Project Ideas](https://www.youtube.com/watch?v=oA-pPa0vfks)
+- [Awesome Terraform](https://github.com/shuaibiyy/awesome-terraform)
+
+See you on [Day 57](day57.md)
\ No newline at end of file
diff --git a/Days/day61.md b/Days/day61.md
index e69de29..e5dde7c 100644
--- a/Days/day61.md
+++ b/Days/day61.md
@@ -0,0 +1,41 @@
+## Kubernetes & Multiple Environments
+
+Kubernetes Demo
+
+`terraform init`
+
+
+
+
+### Multiple Environments
+
+If we wanted to take any of the demos we have ran through but wanted to now have specific production, staging and development environments looking exactly the same and leveraging this code there are two approaches to achieve this with Terraform
+
+- `terraform workspaces` - multiple named sections within a single backend
+
+- file structure - Directory layout provides separation, modules provide reuse.
+
+Each of the above do have their pros and cons though.
+
+### terraform workspaces
+
+Pros
+-
+
+Cons
+
+## Resources
+I have listed a lot of resources down below and I think this topic has been covered so many times out there, If you have additional resources be sure to raise a PR with your resources and I will be happy to review and add them to the list.
+
+- [What is Infrastructure as Code? Difference of Infrastructure as Code Tools ](https://www.youtube.com/watch?v=POPP2WTJ8es)
+- [Terraform Tutorial | Terraform Course Overview 2021](https://www.youtube.com/watch?v=m3cKkYXl-8o)
+- [Terraform explained in 15 mins | Terraform Tutorial for Beginners ](https://www.youtube.com/watch?v=l5k1ai_GBDE)
+- [Terraform Course - From BEGINNER to PRO!](https://www.youtube.com/watch?v=7xngnjfIlK4&list=WL&index=141&t=16s)
+- [HashiCorp Terraform Associate Certification Course](https://www.youtube.com/watch?v=V4waklkBC38&list=WL&index=55&t=111s)
+- [Terraform Full Course for Beginners](https://www.youtube.com/watch?v=EJ3N-hhiWv0&list=WL&index=39&t=27s)
+- [KodeKloud - Terraform for DevOps Beginners + Labs: Complete Step by Step Guide!](https://www.youtube.com/watch?v=YcJ9IeukJL8&list=WL&index=16&t=11s)
+- [Terraform Simple Projects](https://terraform.joshuajebaraj.com/)
+- [Terraform Tutorial - The Best Project Ideas](https://www.youtube.com/watch?v=oA-pPa0vfks)
+- [Awesome Terraform](https://github.com/shuaibiyy/awesome-terraform)
+
+See you on [Day 57](day57.md)
\ No newline at end of file
diff --git a/Days/day62.md b/Days/day62.md
index e69de29..08a41cb 100644
--- a/Days/day62.md
+++ b/Days/day62.md
@@ -0,0 +1,17 @@
+##
+
+## Resources
+I have listed a lot of resources down below and I think this topic has been covered so many times out there, If you have additional resources be sure to raise a PR with your resources and I will be happy to review and add them to the list.
+
+- [What is Infrastructure as Code? Difference of Infrastructure as Code Tools ](https://www.youtube.com/watch?v=POPP2WTJ8es)
+- [Terraform Tutorial | Terraform Course Overview 2021](https://www.youtube.com/watch?v=m3cKkYXl-8o)
+- [Terraform explained in 15 mins | Terraform Tutorial for Beginners ](https://www.youtube.com/watch?v=l5k1ai_GBDE)
+- [Terraform Course - From BEGINNER to PRO!](https://www.youtube.com/watch?v=7xngnjfIlK4&list=WL&index=141&t=16s)
+- [HashiCorp Terraform Associate Certification Course](https://www.youtube.com/watch?v=V4waklkBC38&list=WL&index=55&t=111s)
+- [Terraform Full Course for Beginners](https://www.youtube.com/watch?v=EJ3N-hhiWv0&list=WL&index=39&t=27s)
+- [KodeKloud - Terraform for DevOps Beginners + Labs: Complete Step by Step Guide!](https://www.youtube.com/watch?v=YcJ9IeukJL8&list=WL&index=16&t=11s)
+- [Terraform Simple Projects](https://terraform.joshuajebaraj.com/)
+- [Terraform Tutorial - The Best Project Ideas](https://www.youtube.com/watch?v=oA-pPa0vfks)
+- [Awesome Terraform](https://github.com/shuaibiyy/awesome-terraform)
+
+See you on [Day 57](day57.md)
\ No newline at end of file
diff --git a/README.md b/README.md
index 83f4b94..953147a 100644
--- a/README.md
+++ b/README.md
@@ -94,11 +94,11 @@ This will not cover all things DevOps but it will cover the areas that I feel wi
- [✔️] 🤖 56 > [The Big Picture: IaC](Days/day56.md)
- [✔️] 🤖 57 > [An intro to Terraform ](Days/day57.md)
-- [🚧] 🤖 58 > [](Days/day58.md)
-- [] 🤖 59 > [](Days/day59.md)
-- [] 🤖 60 > [](Days/day60.md)
-- [] 🤖 61 > [](Days/day61.md)
-- [] 🤖 62 > [](Days/day62.md)
+- [✔️] 🤖 58 > [HashiCorp Configuration Language (HCL)](Days/day58.md)
+- [✔️] 🤖 59 > [Create a VM with Terraform & Variables](Days/day59.md)
+- [✔️] 🤖 60 > [Docker Containers, Provisioners & Modules](Days/day60.md)
+- [✔️] 🤖 61 > [](Days/day61.md)
+- [🚧] 🤖 62 > [](Days/day62.md)
### Automate Configuration Management