Terraform Variables episode artwork

EPISODE · Jun 16, 2022 · 9 MIN

Terraform Variables

from Programmers · host Software Engineering

With terraform we can use variables for example an integer which is defined as a number or a string or a list of strings and then we can reference these variables further down in the code in order to reuse them you can also output variables to the screen and we could also ask the customer to input interactively variable values into the console In this session - init plan apply destroy - state file - variables - terraform pattern consistent - resource keyword - resource identifier "aws_vpc" - our name "mypc" - in curly braces the parametesrs like cidr_block = "10.0.0.0/16" - `terraform init` - i's like mvn install - Download the plugins to use aws - We can run this command after created main.tf - pull down modules - `terraform plan` - will show what's its going to do - checks state - Get developer style diff before commit - What already created which diff - don't want to loose this state file - `terraform apply` - showing the diff - click `yes` to continue - resources created in aws! - `terraform destroy` - to delete all reources - confirm - `state file` `terraform.tfstate` - we can see locally all that we created with terraform! - this file will have ALL resources created by terraform - visibility! - we want this file to get missing - json format - .bak - track changes we made - used for diff # Variables - define variables - folder `variables` - `default` is like the value - we have `type` and then `default` for default value - `main.tf` create file in that folder ```json variable "vpcname" { type = string (or number boolean list(string) with values ["val1", "val2"] to access 1 [0]) default = "myvpc" } variable "mymap" { type = map default = { key1 = "value1" key2 = "value2" } } variable "mytuple" { type tuple([string, number, string]) default = ["mystr1", 45, "mystr2"] } variable "myobject" { type = object({name = string, port = number}) default { name = "myval1" default = "232" } } ``` - cidr_range would get used multiple times so just put it in var - use variables - `var.myvarname` can also be done with string interpolation - `var.mylist[0]` - `var.mymap["Key1"]` - interactive input variables ```json variable "inputname" { type = string description = "please enter value for input name" } ``` next use this - `var.inputname` as usuall - `terraform plan` will now ask to input the input vars values # Outputs ```json output "myoutput" { value = aws_vpc.myvpc.id } ``` so nw we can print the dynamic id we get when we run terraform. run `terraform plan` will not print the id as it's created only after the apply is run and resources actually run.

With terraform we can use variables for example an integer which is defined as a number or a string or a list of strings and then we can reference these variables further down in the code in order to reuse them you can also output variables to the screen and we could also ask the customer to input interactively variable values into the console In this session - init plan apply destroy - state file - variables - terraform pattern consistent - resource keyword - resource identifier "aws_vpc" - our name "mypc" - in curly braces the parametesrs like cidr_block = "10.0.0.0/16" - `terraform init` - i's like mvn install - Download the plugins to use aws - We can run this command after created main.tf - pull down modules - `terraform plan` - will show what's its going to do - checks state - Get developer style diff before commit - What already created which diff - don't want to loose this state file - `terraform apply` - showing the diff - click `yes` to continue - resources created in aws! - `terraform destroy` - to delete all reources - confirm - `state file` `terraform.tfstate` - we can see locally all that we created with terraform! - this file will have ALL resources created by terraform - visibility! - we want this file to get missing - json format - .bak - track changes we made - used for diff # Variables - define variables - folder `variables` - `default` is like the value - we have `type` and then `default` for default value - `main.tf` create file in that folder ```json variable "vpcname" { type = string (or number boolean list(string) with values ["val1", "val2"] to access 1 [0]) default = "myvpc" } variable "mymap" { type = map default = { key1 = "value1" key2 = "value2" } } variable "mytuple" { type tuple([string, number, string]) default = ["mystr1", 45, "mystr2"] } variable "myobject" { type = object({name = string, port = number}) default { name = "myval1" default = "232" } } ``` - cidr_range would get used multiple times so just put it in var - use variables - `var.myvarname` can also be done with string interpolation - `var.mylist[0]` - `var.mymap["Key1"]` - interactive input variables ```json variable "inputname" { type = string description = "please enter value for input name" } ``` next use this - `var.inputname` as usuall - `terraform plan` will now ask to input the input vars values # Outputs ```json output "myoutput" { value = aws_vpc.myvpc.id } ``` so nw we can print the dynamic id we get when we run terraform. run `terraform plan` will not print the id as it's created only after the apply is run and resources actually run.

NOW PLAYING

Terraform Variables

0:00 9:56

No transcript for this episode yet

We transcribe on demand. Request one and we'll notify you when it's ready — usually under 10 minutes.

Khanyisa Keke TV Khanyisa Keke On Khanyisa Keke TV, developers can learn and improve their Android for Kotlin Development skills. On this podcast, programmers can learn Android for Kotlin coding from scratch, improve their existing programming skills, get tips, be kept up to date with all the latest happenings and get access to free resources. Powered by Firstory Hosting Command Line Heroes Red Hat Hear the epic true tales of how developers, programmers, hackers, geeks, and open source rebels are revolutionizing the technology landscape. Command Line Heroes is an award-winning podcast hosted by Saron Yitbarek and produced by Red Hat. Get root access to show notes, transcripts, and other associated content at https://redhat.com/commandlineheroes DevDiscuss DevDiscuss is the first original podcast from DEV, a global community of software developers of all backgrounds and experience levels. The show covers burning topics that impact the daily lives of programmers and beyond, hosted by Forem Co-Founder, Ben Halpern, as well as a rotating cast of Forem developers. Startup Data Science Edderic Ugaddan, Apurva Naik, Alex Au Startup Data Science is the podcast where you learn startup-ready data science with programming basics. We discuss how to bootstrap data science techniques and understand their underlying mechanics by discussing open-source learning materials. Startup Data Science helps forward-thinking entrepreneurs, novice programmers, and seasoned software engineers to use Data Science to make a bigger impact.

Frequently Asked Questions

How long is this episode of Programmers?

This episode is 9 minutes long.

When was this Programmers episode published?

This episode was published on June 16, 2022.

What is this episode about?

With terraform we can use variables for example an integer which is defined as a number or a string or a list of strings and then we can reference these variables further down in the code in order to reuse them you can also output variables to the...

Can I download this Programmers episode?

Yes, you can download this episode by clicking the download button on the episode player, or subscribe to the podcast in your preferred podcast app for automatic downloads.
URL copied to clipboard!