Skip to main content

Map Your Cyber Essentials Cloud Scope From Terraform State

Cloud services cannot be excluded from Cyber Essentials scope. Export managed resources from Terraform state with show -json and jq, then classify them.

KBY Technologies12 min readTier L115 min
Map Your Cyber Essentials Cloud Scope From Terraform State

Advertising disclosure: this article includes partner links. KBY may earn a commission if you sign up or buy through one, at no extra cost to you. How we make money.

Underlined words are defined in the KBY Lexicon. Tap or click one to see what it means.

Cyber Essentials expects you to name every cloud service that holds your organisation’s data or runs its services. If most of that estate is built with , the state files already list it, so the scope can come from evidence rather than memory.

Run terraform show -json against each Terraform state, keep only the managed resources’ addresses, types and providers, and map each resource type to its cloud service model. The constraint that shapes everything else is in version 3.3 of the NCSC’s Cyber Essentials: Requirements for IT Infrastructure (April 2026): cloud services cannot be excluded from scope. Terraform state only shows what Terraform manages, so the export is the start of the cloud scope, never all of it.

Nothing here changes a cloud resource or a Terraform state. The output of terraform show prints sensitive values in plain text, which is why the export below filters it before anything reaches disk.

#How the cloud scope question is handled today

The scope answer is usually written from memory, often by whoever owns the certification that year. Someone lists the cloud accounts and main virtual machines they remember. The list goes into the self-assessment, and nobody checks it against what is actually deployed.

That approach fails in predictable places. A team that builds a new environment between assessments adds services nobody tells the certification owner about. Functions and web apps get forgotten because they do not look like servers. The requirements also say an organisation remains responsible for every control on a cloud service, even where the provider implements some of them, so an unlisted service is an unchecked one.

The requirements are clear about the boundary you must draw. The assessment covers the whole IT infrastructure, or a well-defined and separately managed sub-set. Either way you define the business unit, the network boundary and the physical location, and agree the scope with the Certification Body before the assessment begins. Excluding part of the infrastructure needs a justification to the assessor.

#A better workflow: read the scope from Terraform state

Terraform relies on state to associate resources with real-world objects, so the state is the most complete record you have of what Terraform built. The workflow turns that record into a reviewed scope list in four stages, each producing something a reviewer can check.

  1. Find every state. Each Terraform CLI workspace is a separate instance of state data in the same working directory, and most commands only touch the selected one. A working directory with three workspaces therefore needs three exports.
  2. Prove each state is current. A refresh-only plan reads the remote objects and reports whether they still match the state, without changing anything. An export from a stale state would put the wrong things in scope.
  3. Export only what the scope needs: the resource address, its type and its provider. Values stay out, because they can include secrets.
  4. Classify and complete. Map each resource type to IaaS or PaaS, then add the cloud services Terraform does not manage, such as SaaS subscriptions.

Following along? Tap a step’s number to tick it off.

The choice you are making is to trust Terraform’s view of the estate for the parts it manages, and to collect everything else by hand. That is a real improvement only if the drift check passes, which is why it sits before the export rather than after it.

Rendering diagram...

The classification step matters because the requirements split responsibility by cloud service model. The table below follows Table 1 of the v3.3 requirements, which explains who may typically implement each control.

Who typically implements each Cyber Essentials control, by cloud service model (Requirements for IT Infrastructure v3.3, Table 1)
ControlIaaSPaaSSaaS
FirewallsBoth your organisation and the cloud providerThe cloud provider and sometimes also your organisationThe cloud provider
Secure configurationBothBothBoth
Security update managementBothBothThe cloud provider
User access controlYour organisationYour organisationYour organisation
Malware protectionBothThe cloud provider and sometimes also your organisationThe cloud provider

The requirements give examples for each model. Amazon EC2 and Google Compute Engine are IaaS, so an aws_instance or google_compute_instance in your state lands in the IaaS column. Azure Web Apps and are PaaS, so an aws_lambda_function lands in the PaaS column. Where the provider implements a control for you, the requirements say you must confirm it has committed to that through contractual clauses or documents referenced by contract.

#Step by step: build the inventory for one state

Work from a clean checkout of the configuration, initialised with the same backend settings your pipeline uses, and with read-only cloud credentials. Repeat the steps for every working directory and every workspace in it.

  1. Record the Terraform version. The JSON output of terraform show needs Terraform 0.12 or later, and refresh-only plans need 0.15.4 or later.

    1terraform version

    Expected evidence: a line such as Terraform v1.x.y followed by the installed providers. Stop if the version is older than 0.15.4.

  2. List the workspaces. The current one is marked with an asterisk.

    1terraform workspace list

    Write down the selected workspace before you change anything, so you can return to it. To move between workspaces, use terraform workspace select with the workspace name; it changes which workspace’s state the following commands use.

  3. Check that the state still matches the real objects.

    1terraform plan -refresh-only -detailed-exitcode

    The plan command alone does not carry out the changes it proposes. With -detailed-exitcode, exit code 0 means an empty diff, 1 means an error and 2 means changes are present. Stop on 1 or 2. Exit code 2 usually means objects were changed outside Terraform, and the plan output shows which; reconcile that before trusting the export. The guide to fixing Terraform drift after console edits safely covers that change.

  4. See what the state holds. This prints every resource address, sorted by module depth and then alphabetically.

    1terraform state list

    Expected evidence: addresses such as aws_instance.web[0] and module.api.aws_lambda_function.handler. Addresses beginning with data. are data sources Terraform reads rather than manages.

  5. Export the managed resources, keeping only address, type and provider.

    1terraform show -json | jq -r '.values.root_module | recurse(.child_modules[]?) | .resources[]? | select(.mode == "managed") | [.address, .type, .provider_name] | @tsv' > ce-scope-production.tsv

    The filter walks the root module and every child module, keeps resources whose mode is managed, and writes one tab-separated line per resource instance. Resource values never reach the file. Stop if the file is empty while terraform state list printed managed addresses.

  6. List the distinct resource types to classify.

    1terraform show -json | jq -r '[.values.root_module | recurse(.child_modules[]?) | .resources[]? | select(.mode == "managed") | .type] | unique | .[]'

    Expected evidence: a sorted list such as aws_instance, aws_lambda_function and aws_security_group. Classify each type once as IaaS, PaaS or supporting configuration, and record who owns it.

When every state is done, add the cloud services no state mentions. Typical gaps are SaaS subscriptions such as Microsoft 365, accounts created by hand in a provider console, and services a supplier runs for you. The requirements put accounts used by a third party, such as a managed service provider, in scope whenever your organisation owns them.

Illuminated laptop keyboard with Matrix-style green code cascading down screen.
Photo by Rafael Minguet Delgado on Pexels

#Who can run it, and what it must never write

The person running the export needs to read every state and every cloud account behind it, which makes the credentials sensitive even though nothing changes. Use a role that can read but not modify the cloud resources. The refresh-only plan needs to read the remote objects, so a role without read access fails at step 3, which is the correct outcome.

  • Never save the unfiltered output of terraform show -json. The command prints sensitive values from state in plain text.
  • Never run terraform apply -refresh-only as part of this workflow. It writes the refreshed values into state, which is a change that needs its own review.
  • Never add -lock=false to the plan. Holding the state lock stops your read overlapping someone else’s apply.
  • Keep the inventory files with the certification evidence, not in a public repository, because addresses and types describe your estate’s layout.

The residual risk is the credentials themselves, so remove them from the workstation once the run ends.

#Check it worked before the scope goes to the assessor

An inventory is only useful if a second person can repeat it and get the same answer. Before the list leaves the team, check four things.

  1. Each state’s refresh-only plan exited 0 on the day of the export, and the date is recorded beside the file.
  2. The address column in each .tsv file contains every address from terraform state list that does not start with data..
  3. Every distinct resource type has a classification and an owner.
  4. The final scope list includes the services Terraform does not manage, each marked as added by hand.

If any check fails, fix the cause and rerun that state’s export rather than editing the file by hand. A hand-edited inventory is no longer evidence of what the state contained.

#Where it goes wrong

Most failures show up as a scope that looks complete but is not. Each of these has a clear symptom you can check for.

  • Only one workspace exported. The inventory looks small next to the console. Most commands only interact with the selected workspace, so run terraform workspace list again and export the rest.
  • The plan cannot get the state lock. Step 3 fails with a lock error because an apply is running or a past run was interrupted. Wait, and follow the guide to recovering safely from a Terraform state lock error before anyone forces an unlock.
  • The export fails after a provider upgrade. HashiCorp’s documentation says to upgrade the state before show -json can display it when newer provider schemas exist. That upgrade writes state, so treat it as a planned change for the state’s owner, not part of the inventory run.
  • PaaS treated as fully the provider’s problem. Secure configuration and security update management are shared for PaaS, and user access control is always yours.
  • End-user devices missing. Terraform rarely manages laptops, but the requirements say a scope that does not include end-user devices is not acceptable.
Dark room setup with code displayed on PC monitors highlighting cybersecurity themes.
Photo by Tima Miroshnichenko on Pexels

#How to recover when a run goes wrong

Because the workflow writes nothing to state or to the cloud accounts, recovery is mostly about files and sessions on the workstation. The order below goes from the most to the least serious.

  1. If someone saved the unfiltered JSON, delete the file and any copies, then tell the owners of the secrets it may have held so they can decide whether to rotate them.
  2. If someone ran terraform apply -refresh-only by mistake, stop and hand it to the state’s owner. The state now records the refreshed values, and putting the previous state back is a decision for that owner.
  3. If you changed workspace, run terraform workspace select with the name you recorded in step 2, then check the asterisk in terraform workspace list.
  4. If an export is wrong, delete that state’s .tsv file and rerun steps 3 to 6 for it.

After any of these, rerun the refresh-only plan. An exit code of 0 shows the state and the real objects still agree, and the export can be trusted again.

#What to track between assessments

The point of building the scope from state is that it can be repeated cheaply, so measure how far the repeated answer drifts from the submitted one. Take your baseline from the export made for the current certificate.

  • The number of managed resource types per state, compared with the baseline. A new type needs a classification before the next assessment.
  • The number of cloud services added by hand. If it grows, more of the estate is being built outside Terraform.
  • The share of refresh-only plans that exit 0 on the first run. Repeated exit code 2 usually means console changes are common and the state is a weak record.

A monthly run is a sensible starting cadence for most teams, with an extra run whenever a new environment or account is created. If any new resource type or hand-added service appears, review the scope with the certification owner before the next assessment rather than at it. The Infrastructure as Code hub collects related Terraform guides.

#Checklist before you send the cloud scope to your Certification Body

  • Every working directory and every workspace has a dated export.
  • Each state’s refresh-only plan exited 0 on the export date.
  • No file contains unfiltered terraform show -json output.
  • Every resource type is classified as IaaS, PaaS or supporting configuration, with an owner.
  • Cloud services that Terraform does not manage, including SaaS, are listed and marked as added by hand.
  • Where the provider implements a control, the contract or referenced document that commits it is named.
  • The scope names the business unit, network boundary and physical location, and the Certification Body has agreed it.

If every item holds, send the scope. If the drift check or a classification is still open, the safe decision is to resolve it first, because the requirements give no route to excluding a cloud service that holds your data.

About this page

Credited to

Dates

Published

Sources

This page lists no external sources.

Corrections

No corrections are listed for this page. Some review sweeps corrected pages without naming each one; those are in the corrections log.

Found this useful? Follow KBY for more like it.

Reader Interaction

Comments

Add a thoughtful note on Map Your Cyber Essentials Cloud Scope From Terraform State. Comments are checked for spam and held for moderation before appearing.

Loading comments...

More from KBY that goes with this article.

Discover more

Was this useful?

Reports go to the site owner and are used to correct pages. Corrections are listed at /corrections.

Operate smarter, with fewer recurring tickets.

Receive new operational playbooks, incident-prevention guidance, automation scripts and recovery runbooks.