"Creating & Managing Resources with Terraform: A Guide to Using Variables, Outputs, and the GitHub Provider"

"Creating & Managing Resources with Terraform: A Guide to Using Variables, Outputs, and the GitHub Provider"

Task-1 Print "Hello World"

The code is defined output named "name" with a string value of "Hello World".

Task-2 Print Multiple Values:

This code is defining two outputs in HCL for infrastructure management tools like Terraform or Packer.

The first output is named "name" and has a string value of "Hello World". The second output is named "multiple values" and also has a string value of "This is the second value".

Task-3 Define Variable in HCL:

Terraform 101 : An introduction to terraform concepts - PISQUARE

This code defines a variable named "name" in HCL for infrastructure management tools like Terraform or Packer, and an output named "names" that references the variable. The output "names" is defined with a string value that includes the value of the "name" variable interpolated with the string "Hey!!! my name is". When the Terraform script is executed and the variable "name" is set to a value, the output will display the interpolated string with the value of the variable.

Instead of providing value, we can just put in command also

Instead of defining value in the Command line, we can provide a default value in HCL too

This code defines two variables, "name" and "age", and an output named "names" that references both variables.

The variable "name" is defined as a string with a default value of "Abhijeet". The variable "age" is defined with a type of "number" and a default value of 25.

The output "names" is defined with a string value that includes the values of both variables interpolated into the string using ${var.name} and ${var.age} respectively. When the Terraform script is executed, the output will display the interpolated string with the values of the variables.

Define "List" in HCL:

This code defines a variable named "name" as a list and an output named "names" that references the first element of the "name" list.

The variable "name" is defined with a type of "list" but does not have a default value, which means that it must be provided by the user when the Terraform script is executed. but we can define it in default value too.

Define "Join" in HCL:

This code defines a variable named "name" as a list with a default value of ["abhijeet", "Devops"] and an output named "names" that concatenates the elements of the "name" list using the "join" function.

The variable "name" is defined with a type of "list" and a default value of ["abhijeet", "Devops"], which means that if a user does not provide a value for "name" when the Terraform script is executed, these default values will be used.

The output "names" is defined with a string value that includes all the elements of the "name" list concatenated together with the separator " --> ". The "join" function is used to join the elements of the list together with the separator specified as the first argument, which in this case is " --> ". The result is a string that includes all the elements of the "name" list separated by " --> ".

Define "Lookup" in HCL:

In this code, the "name" variable is defined as a map with two key-value pairs: "Abhijeet" = 25 and "Abhi" = 26. The output "names" uses the lookup function to retrieve the value associated with the "Abhi" key in the "name" map, and interpolates it into the output string.

Creating the first Terraform Resource - (GitHub Repository)

Automating Terraform with GitHub Actions | by Rohan Singh | Jun, 2021 ...

This Terraform code block uses the github provider to interact with the GitHub API. It sets the authentication token using a personal access token.

It then declares a resource github_repository with the name terraform-first-repo. The github_repository resource creates a new repository on the GitHub platform with the specified name, description, auto-initialization, and visibility.

Once the repository is created, the state of the resource is saved by Terraform and can be managed and modified in subsequent runs.

Verify it on Github: