Lab Information
The Nautilus DevOps team is strategizing the migration of a portion of their infrastructure to the AWS cloud. As part of this phased migration approach, they need to allocate an Elastic IP address to support external access for specific workloads.
For this task, create an AWS Elastic IP using Terraform with the following requirement:
The Elastic IP name nautilus-eip should be stored in a variable named KKE_eip. The Terraform working directory is /home/bob/terraform.
Note:
The configuration values should be stored in a variables.tf file.
The Terraform script should be structured with a main.tf file referencing variables.tf.
Right-click under the EXPLORER section in VS Code and select Open in Integrated Terminal to launch the terminal.
Lab Solutions
Step 1: Create variables.tf
# variables.tf
# Define variable for Elastic IP name
variable "KKE_eip" {
description = "The name of the Elastic IP"
type = string
default = "nautilus-eip"
}
Step 2: Create main.tf
# main.tf
# Create AWS Elastic IP with variable reference
resource "aws_eip" "this" {
vpc = true
tags = {
Name = var.KKE_eip
}
}
Step 3: To deploy this configuration
Navigate to the Terraform directory:
cd /home/bob/terraform
Initialize Terraform:
terraform init
Output
bob@iac-server ~/terraform via π default β terraform init
Initializing the backend...
Initializing provider plugins...
- Finding hashicorp/aws versions matching "5.91.0"...
- Installing hashicorp/aws v5.91.0...
- Installed hashicorp/aws v5.91.0 (signed by HashiCorp)
Terraform has created a lock file .terraform.lock.hcl to record the provider
selections it made above. Include this file in your version control repository
so that Terraform can guarantee to make the same selections by default when
you run "terraform init" in the future.
Terraform has been successfully initialized!
You may now begin working with Terraform. Try running "terraform plan" to see
any changes that are required for your infrastructure. All Terraform commands
should now work.
If you ever set or change modules or backend configuration for Terraform,
rerun this command to reinitialize your working directory. If you forget, other
commands will detect it and remind you to do so if necessary.
Plan the configuration:
terraform plan
Output
bob@iac-server ~/terraform via π default β terraform plan
Terraform used the selected providers to generate the following execution plan. Resource
actions are indicated with the following symbols:
+ create
Terraform will perform the following actions:
# aws_eip.this will be created
+ resource "aws_eip" "this" {
+ allocation_id = (known after apply)
+ arn = (known after apply)
+ association_id = (known after apply)
+ carrier_ip = (known after apply)
+ customer_owned_ip = (known after apply)
+ domain = (known after apply)
+ id = (known after apply)
+ instance = (known after apply)
+ ipam_pool_id = (known after apply)
+ network_border_group = (known after apply)
+ network_interface = (known after apply)
+ private_dns = (known after apply)
+ private_ip = (known after apply)
+ ptr_record = (known after apply)
+ public_dns = (known after apply)
+ public_ip = (known after apply)
+ public_ipv4_pool = (known after apply)
+ tags = {
+ "Name" = "nautilus-eip"
}
+ tags_all = {
+ "Name" = "nautilus-eip"
}
+ vpc = true
}
Plan: 1 to add, 0 to change, 0 to destroy.
β·
β Warning: Argument is deprecated
β
β with aws_eip.this,
β on main.tf line 5, in resource "aws_eip" "this":
β 5: vpc = true
β
β vpc is deprecated. Use domain instead.
β
β (and one more similar warning elsewhere)
β΅
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
Note: You didn't use the -out option to save this plan, so Terraform can't guarantee to
take exactly these actions if you run "terraform apply" now.
Apply the configuration:
terraform apply
Then type yes when prompted to confirm the creation of the snapshot.
Output
bob@iac-server ~/terraform via π default β terraform apply
Terraform used the selected providers to generate the following execution plan. Resource
actions are indicated with the following symbols:
+ create
Terraform will perform the following actions:
# aws_eip.this will be created
+ resource "aws_eip" "this" {
+ allocation_id = (known after apply)
+ arn = (known after apply)
+ association_id = (known after apply)
+ carrier_ip = (known after apply)
+ customer_owned_ip = (known after apply)
+ domain = (known after apply)
+ id = (known after apply)
+ instance = (known after apply)
+ ipam_pool_id = (known after apply)
+ network_border_group = (known after apply)
+ network_interface = (known after apply)
+ private_dns = (known after apply)
+ private_ip = (known after apply)
+ ptr_record = (known after apply)
+ public_dns = (known after apply)
+ public_ip = (known after apply)
+ public_ipv4_pool = (known after apply)
+ tags = {
+ "Name" = "nautilus-eip"
}
+ tags_all = {
+ "Name" = "nautilus-eip"
}
+ vpc = true
}
Plan: 1 to add, 0 to change, 0 to destroy.
β·
β Warning: Argument is deprecated
β
β with aws_eip.this,
β on main.tf line 5, in resource "aws_eip" "this":
β 5: vpc = true
β
β vpc is deprecated. Use domain instead.
β
β (and one more similar warning elsewhere)
β΅
Do you want to perform these actions?
Terraform will perform the actions described above.
Only 'yes' will be accepted to approve.
Enter a value: yes
aws_eip.this: Creating...
aws_eip.this: Creation complete after 1s [id=eipalloc-52002d8db990e6681]
β·
β Warning: Argument is deprecated
β
β with aws_eip.this,
β on main.tf line 5, in resource "aws_eip" "this":
β 5: vpc = true
β
β vpc is deprecated. Use domain instead.
β΅
Apply complete! Resources: 1 added, 0 changed, 0 destroyed.
Top comments (0)