Question 1easymultiple choice
Read the full Interact with Terraform modules explanation →TF-003 Interact with Terraform modules • Complete Question Bank
Complete TF-003 Interact with Terraform modules question bank — all 0 questions with answers and detailed explanations.
Refer to the exhibit.
```hcl
module "vpc" {
source = "terraform-aws-modules/vpc/aws"
version = "3.19.0"
name = "my-vpc"
cidr = "10.0.0.0/16"
azs = ["us-east-1a", "us-east-1b"]
private_subnets = ["10.0.1.0/24", "10.0.2.0/24"]
public_subnets = ["10.0.101.0/24", "10.0.102.0/24"]
}
output "vpc_id" {
value = module.vpc.vpc_id
}
```Refer to the exhibit.
```hcl
module "bucket" {
source = "./modules/s3-bucket"
bucket_name = "my-app-data"
}
resource "aws_s3_bucket_object" "config" {
bucket = module.bucket.bucket_name
key = "config.json"
source = "config.json"
}
```
The module at './modules/s3-bucket' contains:
```hcl
variable "bucket_name" {}
resource "aws_s3_bucket" "this" {
bucket = var.bucket_name
}
output "bucket_name" {
value = aws_s3_bucket.this.id
}
```Refer to the exhibit.
```hcl
module "vpc" {
source = "terraform-aws-modules/vpc/aws"
version = "3.18.0"
name = "my-vpc"
cidr = "10.0.0.0/16"
azs = ["us-east-1a", "us-east-1b"]
private_subnets = ["10.0.1.0/24", "10.0.2.0/24"]
public_subnets = ["10.0.101.0/24", "10.0.102.0/24"]
enable_nat_gateway = true
enable_vpn_gateway = true
tags = {
Terraform = "true"
Environment = "dev"
}
}
```Refer to the exhibit.
```hcl
module "vpc" {
source = "terraform-aws-modules/vpc/aws"
version = "5.0.0"
name = "my-vpc"
cidr = "10.0.0.0/16"
azs = ["us-east-1a", "us-east-1b"]
private_subnets = ["10.0.1.0/24", "10.0.2.0/24"]
public_subnets = ["10.0.101.0/24", "10.0.102.0/24"]
enable_nat_gateway = true
enable_vpn_gateway = false
}
output "vpc_id" {
value = module.vpc.vpc_id
}
```Drag steps to the numbered slots on the right, or tap a step then tap a slot.
Drag a concept onto its matching description — or click a concept then click the description.
List function
Map function
IP network function
Encoding function
Date and time function
Refer to the exhibit.
```
Terraform will perform the following actions:
# module.instances["web"].aws_instance.this will be created
+ resource "aws_instance" "this" {
+ ami = "ami-123456"
+ instance_type = "t2.micro"
+ subnet_id = (known after apply)
...
}
# module.instances["app"].aws_instance.this will be created
+ resource "aws_instance" "this" {
+ ami = "ami-789012"
+ instance_type = "t2.small"
+ subnet_id = (known after apply)
...
}
Plan: 2 to add, 0 to change, 0 to destroy.
```Refer to the exhibit.
```
module "networks" {
source = "./modules/network"
for_each = {
dev = "10.0.1.0/24"
prod = "10.0.2.0/24"
}
cidr_block = each.value
name = each.key
}
resource "aws_flow_log" "example" {
for_each = module.networks
vpc_id = each.value.vpc_id
...
}
```Refer to the exhibit.
```
module "bucket" {
source = "terraform-aws-modules/s3-bucket/aws"
bucket = "my-company-logs"
acl = "log-delivery-write"
}
```
Error during terraform plan:
```
Error: Unsupported argument
on main.tf line 4, in module "bucket":
4: acl = "log-delivery-write"
An argument named "acl" is not expected here.
```Refer to the exhibit.
```hcl
module "networking" {
source = "./modules/networking"
vpc_cidr = "10.0.0.0/16"
}
```
The module in `./modules/networking` has `variables.tf`:
```hcl
variable "vpc_cidr" {
description = "CIDR block for the VPC"
type = string
}
variable "environment" {
description = "Environment name"
type = string
}
```Refer to the exhibit.
```
$ terraform init
Initializing modules...
Downloading hashicorp/consul/aws 0.7.2 from registry.terraform.io...
- consul in .terraform/modules/consul
Initializing the backend...
Initializing provider plugins...
- Finding hashicorp/aws versions matching ">= 3.0"...
- Installing hashicorp/aws v3.74.0...
- Installed hashicorp/aws v3.74.0
Error: Unsupported terraform provider version
on .terraform/modules/consul/main.tf line 1, in terraform:
1: terraform {
2: required_providers {
3: aws = {
4: source = "hashicorp/aws"
5: version = "~> 2.70"
6: }
7: }
8: }
The root module requires hashicorp/aws >= 3.0, but the module requires ~> 2.70.
```Refer to the exhibit.
```hcl
module "myapp" {
source = "terraform-aws-modules/vpc/aws"
version = "~> 3.0"
name = "my-vpc"
cidr = "10.0.0.0/16"
azs = ["us-east-1a", "us-east-1b"]
private_subnets = ["10.0.1.0/24", "10.0.2.0/24"]
public_subnets = ["10.0.101.0/24", "10.0.102.0/24"]
}
```
After running `terraform init`, the console shows it downloaded version 3.19.0 of the module. Why did it download that version?Refer to the exhibit.
```hcl erraform {
required_version = ">= 1.0"
}
module "network" {
source = "./modules/networking"
vpc_id = "vpc-12345"
}
```
Output from `terraform plan`:
```
Error: Module not found
The module at "./modules/networking" could not be found.
```