Exercise
Understand how to import existing remote Terraform resources by using resource IDs and adding them to your Terraform state file. This lesson guides you through importing components such as AWS VPC, subnets, and local files, enabling management of existing infrastructure with Terraform.
We'll cover the following...
We'll cover the following...
Problem statement
We have created a remote VPC by hand. Now we have to find a way to use resource IDs to import while using Terraform.
Take some time to figure out the best way to solve this problem. The code widget is given below. Try to figure out which commands are used to import resources.
variable "region"{
type= string
}
provider "aws"{
region = var.region
}
resource "aws_vpc" "ltthw-vpc" {
cidr_block = "10.0.0.0/16"
tags={
Name = "ltthw-vpc"
}
}
resource "aws_subnet" "ltthw-vpc-subnet" {
vpc_id = aws_vpc.ltthw-vpc.id
cidr_block = aws_vpc.ltthw-vpc.cidr_block
}
resource "local_file" "hello_local_file" {
content = "Hello terraform local!"
filename = "${path.module}/hello_local.txt"
depends_on = [aws_vpc.ltthw-vpc]
}Exercise: Importing resources
If ...