Skip to main content

Posts

The new way of importing resources in Terraform

Terraform has recently launched the version 1.5.0 which introduced the much awaited feature of creation of configurations for imported resources. With the introduction of this new feature, users don't need to write the imported resources configuration manually.  Let's understand in detail about this new way of importing the resources to bring them under the management of terraform. The new way of Terraform Import In new way of terraform import, Terraform has introduced a new import block which you can add to any Terraform configuration file. A common pattern is to create a separate file for all of your import blocks with the name "imports.tf". Syntax # Write an import block import { to = RESOURCE_ADDRESS id = RESOURCE_ID } Let's see the new workflow for importing the resources. Example : Let's say, we have manually created a vpc and two subnets inside it in google cloud. Now we want to import and manage these manually created resources using terraform. Ste...

The comparison between Old vs New way of Terraform Import

Recently, Terraform has launched the version 1.5.0 with the feature of configuration generation for resources to be imported and bring them under terraform management. But make a note of it that configuration generation is available in Terraform v1.5 as an experimental feature. Terraform Import before Terraform v1.5 Before v1.5, `terraform import` command was used to import existing resources into Terraform.  The import command takes two arguments - the resource address and ID. Import will find the existing resource using its ID and import it into your Terraform state at the given ADDRESS in your state file. Syntax > terraform import ADDRESS ID Let's see the import workflow in steps to understand it better. Example : Let's say, we have manually created a subnet inside a VPC in google cloud. Now we want to import and manage this manually created subnet using terraform. Step 01 Write a blank resource block according to the resource being imported. In our case, we will use the ...

Implicit Type Conversion in Terraform

Where possible, Terraform automatically converts values from one type to another in order to produce the expected type. If this isn't possible, Terraform will produce a type mismatch error and you must update the configuration with a more suitable expression. Example 01 If, You have declared a variable with the type - bool and provided its value - "true" i.e. string as mentioned below. # Variable  Declaration variable "example" { type = bool } # Variable  Definition example = "true" In this case, Terraform will internally transform the value to "true" to true (i.e. a bool type). Example 02 If, You have declared a variable with the type - list(string) and provided its value - ["a", 15, true] i.e. Tuple as mentioned below. # Variable  Declaration variable "example" { type = list(string) } # Variable  Definition example = ["a", 15, true] In this case, Terraform will internally transform the value to ["a...