GitHub Copilot Train-the-Trainer

Terraform from modules to security gate

DevOps & infrastructure | Advanced

Session M4-02 | 2 hours 30 minutes

Session M4-02: Infrastructure as Code with Copilot
GitHub Copilot Train-the-Trainer

Agenda

Time Topic
0:00 to 0:08 Architecture and project model
0:08 to 0:20 Module contracts
0:20 to 0:32 Root composition
0:32 to 0:44 Staged validation
0:44 to 0:54 Security failure
0:54 to 1:00 Bicep comparison and lab handoff
Session M4-02: Infrastructure as Code with Copilot
GitHub Copilot Train-the-Trainer

Terraform is required

Use Terraform for the lab:

architecture → modules → root composition → format → init → validate → security gate

Bicep appears as a prepared comparison. Learners do not build both projects.

Session M4-02: Infrastructure as Code with Copilot
GitHub Copilot Train-the-Trainer

Modules define contracts

Module Consumes Exposes
Network CIDR and names VPC and subnet IDs
Compute VPC and subnet IDs Load balancer DNS and app security group
Database Private subnets and app security group Database endpoint

Keep secrets in sensitive inputs. Do not copy values between layers.

Session M4-02: Infrastructure as Code with Copilot
GitHub Copilot Train-the-Trainer

Prompt from fixed constraints

Complete the network, compute, and database module contracts. Pass values through
typed variables and outputs. Keep the database password sensitive. Do not add
credentials, a backend, plan, or apply command.

Use the architecture to set the boundaries before Copilot drafts the files.

Session M4-02: Infrastructure as Code with Copilot
GitHub Copilot Train-the-Trainer

Validate in stages

terraform fmt -check -recursive
terraform init -backend=false
terraform validate

Fix the first failure before moving on. Each stage answers a different question.

Session M4-02: Infrastructure as Code with Copilot
GitHub Copilot Train-the-Trainer

What local validation does not prove

It does not check:

  • the current cloud state;
  • organization policy;
  • quota or regional availability;
  • the effect of an apply.

A reviewed plan needs an approved identity and target environment.

Session M4-02: Infrastructure as Code with Copilot
GitHub Copilot Train-the-Trainer

One intentional security failure

bash lab/starter/check-security.sh lab/starter/insecure-iac/main.tf

The gate must fail. Inspect the cited lines, repair the file, and check that the
rerun passes.

Session M4-02: Infrastructure as Code with Copilot
GitHub Copilot Train-the-Trainer

Bicep is a comparison

Show:

  • module inputs and outputs;
  • @secure() parameters;
  • az bicep build;
  • the same human review boundary.

Six minutes. No second required build.

Session M4-02: Infrastructure as Code with Copilot
GitHub Copilot Train-the-Trainer

Lab

Complete Terraform, validate each stage, and repair the security-gate failure.

Session M4-02: Infrastructure as Code with Copilot