teluzia.Cloud Engineer · Day 90
CHAPTER 13 · TERRAFORM FUNDAMENTALS

Modules and VPC/EC2/S3 project

4–5 hours including independent practice3 topics
LET’S MAKE THIS SIMPLE

What you’re learning today

Modules are reusable blueprint sections; the project combines network, compute, and storage sections through explicit interfaces. A module groups configuration under a directory and presents inputs and outputs. The root module calls child modules. Avoid hiding all configuration behind many trivial modules; boundaries should reflect reusable responsibility with clear validation, versioning, and documentation. A compute module depends on network information, security-group rules, and suitable AMI and instance settings. Public reachability requires more than a public subnet name. Draw routing and access before provisioning, and avoid unrestricted administrative ingress in beginner examples.

Think of it this way

Modules are reusable blueprint sections; the project combines network, compute, and storage sections through explicit interfaces.

TOPIC 01 / 03Step by step

Module structure and interfaces

A module groups configuration under a directory and presents inputs and outputs. The root module calls child modules. Avoid hiding all configuration behind many trivial modules; boundaries should reflect reusable responsibility with clear validation, versioning, and documentation. For example, modules/network accepts a CIDR and returns vpc_id and subnet IDs for callers.

WORKED EXAMPLE
modules/network accepts a CIDR and returns vpc_id and subnet IDs for callers.

Split a learning stack into a network module, a compute module, and a storage module only when each has a clear responsibility. The root module supplies environment inputs, passes network outputs into compute, and exposes a small set of useful results. The modules are configuration directories, not independently running services.

A root module is the configuration where Terraform starts. A child module is called through a module block. An interface consists of inputs and outputs. Define ownership before reuse: two callers must not both manage the same shared bucket unintentionally. Avoid modules that simply wrap one setting without adding meaningful policy or interface value. Larger modules can encode useful defaults but may hide cost or permissions, so inspect their resources and versions. Document prerequisites and expected changes. A modular project is easier to compose only when its interfaces make dependencies clearer rather than conceal them.

Why this matters

modules/network accepts a CIDR and returns vpc_id and subnet IDs for callers.

A common trap

Do not overlook this operational distinction: Avoid hiding all configuration behind many trivial modules; boundaries should reflect reusable responsibility with clear validation, versioning, and documentation.

Read all topics in this lesson

A complete reference to revisit alongside the guided steps above.

Module structure and interfaces

A module groups configuration under a directory and presents inputs and outputs. The root module calls child modules. Avoid hiding all configuration behind many trivial modules; boundaries should reflect reusable responsibility with clear validation, versioning, and documentation. For example, modules/network accepts a CIDR and returns vpc_id and subnet IDs for callers.

WORKED EXAMPLE
modules/network accepts a CIDR and returns vpc_id and subnet IDs for callers.

Split a learning stack into a network module, a compute module, and a storage module only when each has a clear responsibility. The root module supplies environment inputs, passes network outputs into compute, and exposes a small set of useful results. The modules are configuration directories, not independently running services.

A root module is the configuration where Terraform starts. A child module is called through a module block. An interface consists of inputs and outputs. Define ownership before reuse: two callers must not both manage the same shared bucket unintentionally. Avoid modules that simply wrap one setting without adding meaningful policy or interface value. Larger modules can encode useful defaults but may hide cost or permissions, so inspect their resources and versions. Document prerequisites and expected changes. A modular project is easier to compose only when its interfaces make dependencies clearer rather than conceal them.

Why this matters

modules/network accepts a CIDR and returns vpc_id and subnet IDs for callers.

A common trap

Do not overlook this operational distinction: Avoid hiding all configuration behind many trivial modules; boundaries should reflect reusable responsibility with clear validation, versioning, and documentation.

VPC and EC2 dependencies

A compute module depends on network information, security-group rules, and suitable AMI and instance settings. Public reachability requires more than a public subnet name. Draw routing and access before provisioning, and avoid unrestricted administrative ingress in beginner examples. For example, an EC2 instance references an explicit subnet ID and a security group permitting only the intended management path.

WORKED EXAMPLE
An EC2 instance references an explicit subnet ID and a security group permitting only the intended management path.

Compute configuration needs a subnet, suitable security groups, an image, an instance role, and a management approach. The root obtains subnet IDs from the network module, then passes the intended subnet to compute. The VPC ID is a different object identifier and cannot stand in for the subnet merely because both strings start with recognizable prefixes.

A subnet defines an address range inside a VPC. A route table governs its network paths. A security group defines stateful traffic permission for attached resources. Public access requires the appropriate combination of addressing, routes, publication, and permitted traffic; no single public label establishes it. Prefer a scoped management path rather than unrestricted administrative ports. Module input descriptions should identify expected object type and placement. Network correctness also requires availability and capacity planning, so successfully creating an instance does not prove it can reach dependencies or remain useful during a zone failure.

Why this matters

An EC2 instance references an explicit subnet ID and a security group permitting only the intended management path.

A common trap

Do not overlook this operational distinction: Draw routing and access before provisioning, and avoid unrestricted administrative ingress in beginner examples.

S3 storage and ownership

Storage modules should establish private access defaults, encryption, versioning, tags, and a deliberate deletion policy as requirements demand. Bucket names must meet service constraints and ownership must be clear. A force-destroy setting can remove data and should not be used casually to make teardown easy. For example, a draft S3 module blocks public access and documents whether nonempty buckets may be destroyed in the learning environment.

WORKED EXAMPLE
A draft S3 module blocks public access and documents whether nonempty buckets may be destroyed in the learning environment.

A storage module creates an application bucket with private access, encryption settings, ownership tags, and required versioning. It exposes the bucket name for application configuration, while a separate role policy authorizes intended object operations. Outputting the name does not make the bucket public or grant access.

A bucket is an object namespace with service-specific naming constraints. Versioning retains multiple object versions. A destruction policy determines whether stored contents may be removed during teardown. Some module defaults prioritize convenience, including force deletion of nonempty storage; review them against data-retention requirements. Versioning can improve recovery while increasing retained-storage cost. Application storage must also be separate from the backend bucket holding Terraform state, because destroying a practice app should not remove its management inventory. Decide what happens to objects after environment teardown and demonstrate both permitted reads and rejection of unintended callers in any real deployment.

Why this matters

A draft S3 module blocks public access and documents whether nonempty buckets may be destroyed in the learning environment.

A common trap

Do not overlook this operational distinction: A force-destroy setting can remove data and should not be used casually to make teardown easy.

KEEP THESE WITH YOU

Today’s takeaways

Module structure and interfaces: A module groups configuration under a directory and presents inputs and outputs. The root module calls child modules. Avoid hiding all configuration behind many trivial modules; boundaries should reflect reusable responsibility with clear validation, versioning, and documentation.

VPC and EC2 dependencies: A compute module depends on network information, security-group rules, and suitable AMI and instance settings. Public reachability requires more than a public subnet name. Draw routing and access before provisioning, and avoid unrestricted administrative ingress in beginner examples.

S3 storage and ownership: Storage modules should establish private access defaults, encryption, versioning, tags, and a deliberate deletion policy as requirements demand. Bucket names must meet service constraints and ownership must be clear. A force-destroy setting can remove data and should not be used casually to make teardown easy.

CLOSE THE LOOP

Ready to complete this day?

Verify the practical steps and pass the knowledge check (at least two thirds correct).

Lab steps verifiedKnowledge check passed