OCI Terraform Configuration for Snapshot-based Scan
The Qualys Terraform configuration for Oracle Cloud Infrastructure (OCI) deploys the resources required for Qualys CSPM (TotalCloud) and, optionally, FlexScan (Zero-touch Snapshot-based Scan). CSPM is always deployed. FlexScan is deployed when the deploy_flexscan flag is set to true, which is the default.
The configuration creates identity resources only: users, groups, policies, a dynamic group and, optionally, a scanner compartment. It does not create networking, Object Storage buckets, or Functions. Qualys FlexScan creates those at runtime when a region is onboarded, using the manage grants that the FlexScan service group holds on the scanner compartment.
Use this topic to prepare your OCI tenancy before you register it as a Service Account for snapshot-based scanning. For the end-to-end workflow, refer to Configure Zero-Touch Snapshot-based Scan for OCI.
Credential scope: FlexScan does not create a second user. The FlexScan service group is attached to the same qualys-audit-user that CSPM creates, so one API key carries both the CSPM read access and the FlexScan permissions. Enabling deploy_flexscan widens what that key can do. Refer to Security Notes.
Overview
The configuration contains the following modules:
| Module | Purpose | Deployed |
|---|---|---|
cspm |
Creates the Qualys audit user and group, a tenancy-wide read policy, and the API signing key. | Always |
flexscan |
Creates the scanner compartment, the scanner dynamic group, the FlexScan service group (with the audit user as its member), and the FlexScan policies. | When deploy_flexscan = true |
The cspm module is the same module that is used for CSPM-only OCI connectors. Do not modify it. CSPM cannot be turned off, and there is no variable to reference a pre-existing user, because FlexScan builds on the identity that this module creates. If such a user already exists, adopt it with sync_terraform_state.sh. Refer to State Migration.
Architecture
The following diagram shows the identity resources that the configuration creates in the tenancy.
OCI Tenancy (tenancy_ocid)
|
+-- CSPM (always)
| +-- IAM user qualys-audit-user (audit_user_name)
| | +-- API signing key (public key registered in OCI)
| | +-- member of qualys-audit-group
| +-- IAM group qualys-audit-group (audit_group_name)
| +-- Policy qualys-audit-group-policy
| | +-- read all-resources in tenancy
| +-- Local key files
| +-- tls_private_key (RSA 2048, generated by Terraform)
| +-- cspm/oci_api_key.pem (file mode 0600, directory 0700)
|
+-- FlexScan (deploy_flexscan = true)
|
+-- Scanner compartment qualys-flexscan (or compartment_name)
| created directly under the tenancy root,
| or supplied via existing_compartment_id
|
+-- IAM group qualys-flexscan-service-group
| +-- member: the existing qualys-audit-user (no new user, no new key)
| +-- Service policy
| | +-- scanner compartment: manage instance-family, volume-family,
| | | volume-attachments, virtual-network-family, functions-family,
| | | object-family, boot-volumes
| | +-- tenancy: inspect dynamic-groups, policies, users, groups,
| | compartments; read instance-images, objectstorage-namespaces;
| | use key-delegate
| +-- Target policy (always created; one block per target scope)
| +-- Network policy (only when existing_network_compartment_ids is set)
|
+-- Dynamic group qualys-flexscan-scanner-dg
+-- matching rule: instance.compartment.id = '<scanner compartment OCID>'
+-- Dynamic group policy
+-- manage objects in the scanner compartment
| where target.bucket.name=/qualys-qscanner-artifacts-*/
+-- read objectstorage-namespaces in tenancy
Created at runtime by Qualys FlexScan, NOT by this Terraform:
VCN and subnet (or customer-supplied networking), proxy Functions,
scanner instances and scan volumes, and the Object Storage artifacts bucket
qualys-qscanner-artifacts-<6 hex chars>-<region>
Target compartments are the compartments that hold the workloads to scan. You select them with target_compartment_ids. A policy on a parent compartment also covers its descendants. If the list is empty, the target policy is written for the whole tenancy.
If you use customer-managed encryption keys, the service group's use key-delegate in tenancy grant is part of the service policy. You must also create a Block Volume service policy in the key compartment (Allow service blockstorage to use keys in compartment id <key-compartment>). This configuration does not create that policy.
File Structure
oci/terraform/
+-- main.tf Root module: home-region guard, calls cspm and flexscan
+-- variables.tf Root variables
+-- outputs.tf Root outputs
+-- provider.tf Root provider and version constraints
+-- terraform.tfvars.example Example values (copy to terraform.tfvars)
+-- README.md Deployment guide
+-- sync_terraform_state.sh One-time import of existing OCI resources (bash)
+-- check_terraform_policy.sh Static checks on the FlexScan policy definitions (POSIX sh)
+-- cspm/
| +-- main.tf Audit user, group, membership, policy, API key, key files
| +-- variables.tf, outputs.tf, provider.tf, README.md
+-- flexscan/
+-- main.tf Compartment, dynamic group, service group, membership, policies, guard
+-- variables.tf, outputs.tf
+-- policies/accountPermissions.json Scanner-compartment permission templates
Prerequisites
Download the Terraform Configuration
Download the configuration package (a zip file) and extract it. The archive unpacks into an oci-terraform/ folder. Change to that folder and run all Terraform commands from there, next to main.tf.
curl --location --request GET 'https://<gateway-url>/flexscan-api/rest/v1/artifacts/download?cloudType=OCI&fileName=terraform.zip' \
--header 'Authorization: Bearer <Bearer-token>' \
--output oci_terraform.zip
Replace <gateway-url> with the gateway URL for your Qualys platform and <Bearer-token> with your API bearer token. To identify the gateway URL, refer to Qualys Platform Identification.
Runner Permissions
The OCI identity that runs Terraform must be allowed to create and manage the following IAM resources. The configuration does not grant permissions to the runner. In practice, use a tenancy administrator or an equivalent identity.
- CSPM (always): Manage IAM users and their API keys, groups and memberships, and policies at the tenancy root.
- FlexScan (
deploy_flexscan = true): Manage dynamic groups, the service group, its memberships, and tenancy-root policies. Also manage compartments whencreate_scanner_compartment = true. - All runs: List the tenancy's region subscriptions (used by the home-region check).
These are deployment permissions. They are separate from the permissions that the configuration assigns to the audit user, the service group, and the scanner dynamic group.
Software and Configuration
- Terraform version 1.4.0 or later.
- Providers:
oracle/oci ~> 6.0,hashicorp/local >= 2.0.0, andhashicorp/tls ~> 4.0. - A working OCI provider configuration. The providers read the profile named by
oci_config_profile(defaultDEFAULT) from your OCI config file, for example,~/.oci/config. - The OCI CLI, for verification, troubleshooting, and
sync_terraform_state.sh. - The tenancy OCID and the tenancy home region. IAM resources can only be created in the home region, and the plan fails if
regionis not the home region. audit_user_email, when the tenancy uses Identity Domains that require a primary email.- An existing compartment OCID in
existing_compartment_id, whencreate_scanner_compartment = false.
Protect the Terraform state and the generated private key. Use an encrypted state backend, and never commit state, PEM, plan, or terraform.tfvars files.
FlexScan scanner regions are onboarded through the Qualys platform. This configuration does not set or enforce a scanner region list.
Variables
Required Variables
| Variable | Type | Description |
|---|---|---|
tenancy_ocid |
string | OCID of the tenancy. |
region |
string | The tenancy home region, for example, us-ashburn-1. Must be a valid OCI region identifier and must match the tenancy's home region, otherwise the plan fails. |
Optional Variables
| Variable | Type | Default | Description |
|---|---|---|---|
deploy_flexscan |
bool | true |
Deploys FlexScan in addition to CSPM. CSPM itself cannot be disabled. |
oci_config_profile |
string | "DEFAULT" |
Profile in the OCI config file used by the providers. |
is_first_region_apply |
bool | true |
Gates every FlexScan IAM resource. Leave it set to true. Setting it to false on an existing state plans to destroy the FlexScan dynamic group, service group, membership, policies, and compartment. |
create_scanner_compartment |
bool | true |
When false, the configuration uses existing_compartment_id instead of creating a compartment. |
existing_compartment_id |
string | "" |
Compartment OCID to use. Required and validated (ocid1.compartment...) when create_scanner_compartment = false or is_first_region_apply = false. |
compartment_name |
string | "" |
Name of the created scanner compartment. Defaults to qualys-flexscan. |
target_compartment_ids |
list(string) | [] |
Compartments the service group may scan. An empty list means the whole tenancy. |
existing_network_compartment_ids |
list(string) | [] |
Compartments that hold customer-supplied networking. Adds a use virtual-network-family grant for each. An empty list creates no network policy. |
enable_tenancy_compartment_inspection |
bool | true |
When true, grants inspect compartments in tenancy. When false and target_compartment_ids is set, inspection is limited to the scanner compartment and each target. |
audit_user_name |
string | "qualys-audit-user" |
Name of the CSPM user. |
audit_user_email |
string | null |
Email for the audit user. Required by some Identity Domain configurations. Must be a valid email if set. |
audit_group_name |
string | "qualys-audit-group" |
Name of the CSPM group. The audit policy is named <audit_group_name>-policy. |
Behavior to Know Before You Apply
target_compartment_ids: If the list is empty, the scope is the whole tenancy and the target policy is still created. The service group then gets the following permissions across the tenancy:read instances,read vnics,inspect vnic-attachments,inspect volume-attachments,inspect volumes,use volumes,use boot-volumes,manage volume-groups,manage volume-group-backups,manage boot-volume-backups, andmanage volume-backups. Settarget_compartment_idsunless you intend tenancy-wide scanning. If you list a compartment, the same 11 statements are written for it and, through policy inheritance, for its descendants.is_first_region_apply: Whentrue, the FlexScan IAM resources and, if requested, the scanner compartment are created. Whenfalse, none of the FlexScan IAM resources are created, and a validexisting_compartment_idis required or the plan fails. On an existing state, changing the flag tofalseplans to destroy the FlexScan IAM resources. Keep it set totrue.enable_tenancy_compartment_inspection: If this istrue, or if the target list is empty, the policy contains the statementinspect compartments in tenancy. Set it tofalseand list target compartments to restrict inspection to the scanner compartment and those targets.- Scanner compartment: A new compartment is always created directly under the tenancy root and cannot be nested under another compartment. To use a different location, create the compartment yourself and pass
existing_compartment_id. - Dynamic group scope: The dynamic group's matching rule is fixed to the scanner compartment (
instance.compartment.id = '<scanner compartment OCID>') and is not configurable. - Artifacts bucket: There is no bucket variable. The dynamic group policy allows
manage objectsin the scanner compartment for any bucket whose name matchesqualys-qscanner-artifacts-*. FlexScan creates one such bucket for each onboarded region. - Resource names: The FlexScan resource names are fixed and use the
qualysprefix: the default compartment name (qualys-flexscan), the dynamic group (qualys-flexscan-scanner-dg), the service group (qualys-flexscan-service-group), and their policies. You can change only the scanner compartment name, usingcompartment_name. The audit user, group, and policy names come only fromaudit_user_nameandaudit_group_name. Change those only if you must avoid a collision with resources that already exist in the tenancy.
Annotated Example Values
The following terraform.tfvars example has a comment on every value. Lines that start with # followed by a variable name are optional and shown at their defaults.
# ---- Required ----
tenancy_ocid = "ocid1.tenancy.oc1..xxxxxxxx" # Your tenancy OCID (OCI Console: Profile > Tenancy)
region = "us-ashburn-1" # Must be the tenancy HOME region. The plan fails otherwise.
# Not the scanning region: scanner regions are onboarded via Qualys.
# ---- What to deploy (optional, but required for FlexScan) ----
deploy_flexscan = true # false = CSPM only (audit user, group, read policy, API key)
is_first_region_apply = true # Leave true. false on existing state destroys the FlexScan IAM resources
# ---- Scanner compartment ----
create_scanner_compartment = true # true = create it directly under the tenancy root
# existing_compartment_id = "ocid1.compartment.oc1..yyyy" # only with create_scanner_compartment = false;
# must start with ocid1.compartment.
# compartment_name = "" # empty = qualys-flexscan (default)
# ---- Scope: what the service group may scan (optional, but required to limit the target scope) ----
target_compartment_ids = [
"ocid1.compartment.oc1..aaaa", # One entry per compartment holding workloads to scan.
"ocid1.compartment.oc1..bbbb" # Child compartments are covered through policy inheritance.
] # [] (empty) means the WHOLE TENANCY. Set it unless that is intended.
# ---- Other optional settings (usually leave at defaults) ----
# existing_network_compartment_ids = [] # Compartments holding a customer-supplied VCN. Each adds
# "use virtual-network-family". Empty = no network policy.
# enable_tenancy_compartment_inspection = true # true = "inspect compartments in tenancy".
# false narrows inspection only when target_compartment_ids is set.
# oci_config_profile = "DEFAULT" # Profile name in ~/.oci/config
# audit_user_name = "qualys-audit-user" # Change only to avoid a name collision
# audit_group_name = "qualys-audit-group" # The audit policy is named <audit_group_name>-policy
# audit_user_email = null # Set it if the Identity Domain requires a primary email
Deployment Scenarios
CSPM Only
tenancy_ocid = "ocid1.tenancy.oc1..xxxxxxxx"
region = "us-ashburn-1" # tenancy home region
deploy_flexscan = false
Creates the audit user, group, membership, tenancy-wide read policy, API key, and private key file. No compartment, dynamic group, or FlexScan policy is created.
CSPM and FlexScan, Scoped to Target Compartments (Recommended)
tenancy_ocid = "ocid1.tenancy.oc1..xxxxxxxx"
region = "us-ashburn-1"
deploy_flexscan = true
target_compartment_ids = [
"ocid1.compartment.oc1..aaaa",
"ocid1.compartment.oc1..bbbb"
]
Creates everything in the CSPM-only scenario, plus a new scanner compartment (qualys-flexscan), the dynamic group and its policy, and the FlexScan service group (with the audit user as its member), service policy, and target policy for the listed compartments.
CSPM and FlexScan, Tenancy-wide Defaults
Same as the previous scenario, without target_compartment_ids. The target policy is written for the whole tenancy. Use this only if tenancy-wide scanning is intended.
Reuse an Existing Scanner Compartment
create_scanner_compartment = false
existing_compartment_id = "ocid1.compartment.oc1..yyyyyyyy"
No compartment is created. The dynamic group and the policies use the compartment that you supply.
Customer-supplied Networking
existing_network_compartment_ids = ["ocid1.compartment.oc1..nnnn"]
Adds a use virtual-network-family grant in that compartment so that the service group can use the VCN and subnets in it.
Deploy the Configuration
# 1. Initialize
terraform init
# 2. Copy and fill in your values
cp terraform.tfvars.example terraform.tfvars
# 3. Preview
terraform plan -var-file=terraform.tfvars
# 4. Apply
terraform apply -var-file=terraform.tfvars
Review the plan before applying. Check the target scope, the statements in the policies, and that local_file.private_key is created. Keep terraform.tfvars out of version control because it contains real OCIDs.
To adopt resources that already exist in the tenancy, run sync_terraform_state.sh before the first apply. Refer to State Migration.
Created Resources
Root Module
| Resource | Purpose |
|---|---|
data.oci_identity_region_subscriptions.this |
Reads the tenancy's region subscriptions. |
terraform_data.home_region_guard |
Fails the plan if region is not the tenancy home region. |
CSPM Module (./cspm) – Always
| Resource | Purpose |
|---|---|
tls_private_key.audit_user_key |
RSA 2048 key pair generated locally. |
local_file.private_key |
Writes the PEM to cspm/oci_api_key.pem (file 0600, directory 0700). |
oci_identity_user.audit_user |
The Qualys access user. |
oci_identity_group.audit_group |
The Qualys access group. |
oci_identity_user_group_membership.audit_user_membership |
Adds the user to the group. |
oci_identity_policy.audit_policy |
Allow group <audit group> to read all-resources in tenancy |
oci_identity_api_key.audit_user_api_key |
API signing key for the audit user. |
FlexScan Module (./flexscan) – When deploy_flexscan = true
All the following resources, except the guard, also require is_first_region_apply = true.
| Resource | Purpose |
|---|---|
oci_identity_compartment.scanner |
Scanner compartment. Created only when create_scanner_compartment = true. |
oci_identity_dynamic_group.scanner |
Matches instances in the scanner compartment. |
oci_identity_policy.dynamic_group |
Object Storage access for the scanner instances. |
oci_identity_group.service |
FlexScan service group (separate from the audit group). |
oci_identity_user_group_membership.service |
Adds the existing audit user to the service group. |
oci_identity_policy.service |
Scanner compartment and tenancy permissions for the service group. |
oci_identity_policy.target |
Discovery and volume and backup permissions on the target scope. |
oci_identity_policy.network |
use virtual-network-family. Created only when existing_network_compartment_ids is set. |
terraform_data.existing_compartment_guard |
Fails the plan if a valid existing_compartment_id is required and missing. Created whenever deploy_flexscan = true, regardless of is_first_region_apply. |
IAM Permissions Reference
Service Group Policy (qualys-flexscan-service-group-policy, Tenancy Root)
Scanner compartment (from flexscan/policies/accountPermissions.json):
manage instance-familymanage volume-familymanage volume-attachmentsmanage virtual-network-familymanage functions-familymanage object-familymanage boot-volumes
Tenancy:
inspect dynamic-groups,inspect policies,inspect users,inspect groupsread instance-imagesread objectstorage-namespacesuse key-delegateinspect compartments(tenancy, or the scanner compartment plus targets, depending onenable_tenancy_compartment_inspection)
Dynamic Group Policy (qualys-flexscan-scanner-dg-policy, Tenancy Root)
manage objectsin the scanner compartment wheretarget.bucket.name=/qualys-qscanner-artifacts-*/read objectstorage-namespacesin the tenancy
Target Policy (qualys-flexscan-service-group-target-policy, Tenancy Root)
For each target scope (the tenancy when the list is empty, otherwise compartment id <ocid>), the policy contains these 11 statements: read instances, read vnics, inspect vnic-attachments, inspect volume-attachments, inspect volumes, use volumes, use boot-volumes, manage volume-groups, manage volume-group-backups, manage boot-volume-backups, and manage volume-backups.
Network Policy (qualys-flexscan-service-group-network-policy, Tenancy Root)
One use virtual-network-family statement for each entry in existing_network_compartment_ids. Not created when the list is empty.
Audit Policy (<audit_group_name>-policy, Tenancy Root)
read all-resources in tenancy, granted to the audit group.
The scanner instances do not receive Run Command or instance agent permissions from this configuration.
Outputs
| Output | Value |
|---|---|
tenancy_ocid |
The tenancy OCID. |
region |
The home region that you supplied. |
user_ocid |
OCID of the audit user. |
private_key_path |
Path to the generated PEM (cspm/oci_api_key.pem). |
api_key_fingerprint |
Fingerprint of the API key. |
compartment_id |
Scanner compartment OCID. |
compartment_name |
Scanner compartment name. When an existing compartment is used, this reports the configured or default name, which can differ from the real name. Rely on compartment_id. |
dynamic_group_name |
Scanner dynamic group name. |
dynamic_group_ocid |
Scanner dynamic group OCID. |
effective_target_scope |
tenancy, or the comma-separated target compartment OCIDs. |
The tenancy OCID, user OCID, API key fingerprint, private key file, and scanner compartment OCID are the values that the Qualys connector needs when you register the OCI credentials.
The five FlexScan outputs (compartment_id, compartment_name, dynamic_group_name, dynamic_group_ocid, and effective_target_scope) are empty strings when deploy_flexscan = false. No output is marked sensitive. The private key itself is not an output, but it is stored in the Terraform state.
Update Permissions
- The seven scanner compartment statements are defined in
flexscan/policies/accountPermissions.json. Edit that file and runterraform apply. Policies are updated in place, so nothing is destroyed or recreated. - The tenancy, target, network, and dynamic group statements are defined in
flexscan/main.tf. - After any change, run
./check_terraform_policy.sh. This static check (it does not call Terraform) confirms that the artifacts bucket prefix and wildcard pattern and the five tenancy grants are intact. It does not check the target statements oraccountPermissions.json, so review those in the plan. The script printsPASSorFAILlines and exits with a non-zero code on failure. - Do not edit the
cspm/module directly.
State Migration
Use sync_terraform_state.sh when Qualys IAM resources already exist in the tenancy and you want Terraform to adopt them instead of failing on a name collision. Run it from the module root, after terraform init and before the first apply. The script reads terraform.tfvars in the current directory and uses the OCI CLI.
chmod +x sync_terraform_state.sh
./sync_terraform_state.sh
terraform plan -var-file=terraform.tfvars # should show minimal or no changes for adopted resources
The script imports, when found, the audit user, group, membership, and policy. When FlexScan is enabled, it also imports the scanner compartment, the scanner dynamic group, the dynamic group policy, the service group, its membership, and the service policy. Resources that are not found, or that the script is not allowed to read, are skipped and created by the next apply.
Manual imports
- The script does not import
oci_identity_policy.targetoroci_identity_policy.network. If those policies already exist, import them manually before applying. Otherwise, the apply fails on a duplicate name:oci iam policy list --compartment-id <tenancy-ocid> --all --query "data[?name=='qualys-flexscan-service-group-target-policy'].id" terraform import 'module.flexscan[0].oci_identity_policy.target[0]' <policy-ocid> terraform import 'module.flexscan[0].oci_identity_policy.network[0]' <policy-ocid> # only if you use existing_network_compartment_ids - The scanner compartment lookup in the script might be skipped. If the scanner compartment already exists and
create_scanner_compartment = true, import it manually:terraform import 'module.flexscan[0].oci_identity_compartment.scanner[0]' <compartment-ocid>
The API key is never imported. OCI shows a private key only once, when it is created, so an existing key cannot be adopted. After the sync, terraform apply adds a new API key to the adopted audit user. The original key is untouched and keeps working. If FlexScan should use the new key, register it where the connector's OCI credentials are configured. OCI allows a limited number of API keys per user (three), so do not repeat adopt-and-apply cycles without removing keys you no longer need.
Membership lookups use oci raw-request, so your OCI CLI version must support it. jq is not required. The script changes the Terraform state, so review its logic and, if possible, run it against a test tenancy before you use it on a production tenancy.
Security Notes
- One credential, two roles: The audit user's single API key has
read all-resources in tenancy(CSPM). When FlexScan is enabled, the same user also belongs to the service group, which canmanageinstances, volumes, functions, objects, and networking in the scanner compartment, and canuseandmanagevolume, boot volume, and backup resources on the target scope. With an emptytarget_compartment_ids, that scope is the whole tenancy. Scope the target list, and handle the key accordingly. Enabling FlexScan later on an existing CSPM deployment increases what the existing user can do, even though the user and key are unchanged. - State is as sensitive as the PEM: The generated private key is stored in the Terraform state in plain text, and is also written to
cspm/oci_api_key.pem. Use an encrypted remote backend, restrict access to the state, and delete local copies that you do not need. - Keep local files out of version control and packages: Never commit or share
terraform.tfstate*,*.pem,terraform.tfvars, saved plan files (*.plan,tfplan), or the.terraform/directory. - Provider note: The
cspm/module resolves to thehashicorp/ociprovider, while the rest of the configuration usesoracle/oci. This is expected. Do not add arequired_providersblock tocspm/.
Troubleshooting
| Symptom | Cause | Resolution |
|---|---|---|
429 TooManyRequests or toomanyrequests on admin/v1/Users, Groups, DynamicResourceGroups, or GroupMembers |
Identity Domain API rate limiting. Free-tier domains have a low per-minute limit. | The FlexScan resources use the root provider, which retries for up to an hour. The CSPM resources use the module's own provider without that extended retry, so they are more likely to fail. Wait and run the apply again, using terraform apply -parallelism=1 to lower the request rate. If the issue persists, open an Oracle Support case. |
circuit breaker is open |
The OCI SDK's client-side circuit breaker opened after repeated 429 errors. This is a symptom of the same throttling. | Same as the previous row. |
A resource is tainted after a partly successful apply |
The create operation succeeded in OCI, but the confirming read was throttled. | Confirm that the resource exists with a direct oci iam ... get call using the OCID from the error, then run terraform untaint '<address>' instead of letting Terraform recreate it. |
Plan fails: region (...) is not the tenancy home region |
region is not the tenancy home region. |
Set region to the home region. To find it, run oci iam region-subscription list --tenancy-id <tenancy-ocid>. |
| Plan fails: a compartment with the configured name already exists in the tenancy | create_scanner_compartment = true and a compartment with that name already exists. |
Set create_scanner_compartment = false and pass the existing compartment's OCID in existing_compartment_id, or choose a different compartment_name. |
Plan fails: existing_compartment_id must be a valid compartment OCID |
create_scanner_compartment = false (or is_first_region_apply = false) without a valid compartment OCID. |
Provide an ocid1.compartment... value in existing_compartment_id. |
409 / DynamicResourceGroup with the same displayName already exists |
A dynamic group with that name already exists in the tenancy, for example, from a manual setup. | Delete or rename the existing dynamic group, or import it with sync_terraform_state.sh. |
Apply fails with a duplicate name error on audit_user, audit_group, or a policy |
The resource already exists and is not in the Terraform state. | Run sync_terraform_state.sh (and the manual imports in State Migration), or change the names. |
Warning: Value for undeclared variable |
terraform.tfvars contains keys from an older version of the configuration, such as vcn_cidr or subnet_cidr. |
Remove the stale keys. |
terraform init inside cspm/ pulls hashicorp/oci |
The cspm/ module has no required_providers block. |
Informational. Run Terraform from the root module. |
Useful Commands
terraform validate # syntax check
terraform plan -var-file=terraform.tfvars # preview
terraform show # inspect state
terraform state list # list managed resources
terraform state rm <address> # remove from state without deleting in OCI
terraform untaint <address> # clear a false tainted flag
oci iam region-subscription list --tenancy-id <tenancy-ocid> # find the home region
Frequently Asked Questions
Do I need a compartment OCID?
No. Only tenancy_ocid and region are required. Supply existing_compartment_id only if you want to reuse a compartment. Otherwise, the configuration creates qualys-flexscan under the tenancy root.
Why is CSPM mandatory?
The identity that the cspm module creates is the one that FlexScan builds on. There is no variable to reference a pre-existing user. If a user with the default name already exists, the apply fails on the name collision unless you import it first. Refer to State Migration.
Can I enable FlexScan later?
Yes. Set deploy_flexscan = true and apply the configuration again. The audit user, group, and policy are not modified, but the audit user gains the FlexScan permissions through the new service group.
Why doesn't Terraform create the VCN, subnet, bucket, or Functions?
FlexScan creates those when a region is onboarded, and checks for existing ones before creating them. Terraform manages only the identity resources.
Which region do I set?
The tenancy home region. Scanner regions are onboarded through Qualys and are not set in this configuration.
What if I want to scan in another region?
The IAM resources are tenancy-wide and already exist, so there is nothing more to apply here. Onboard the region through Qualys. Do not set is_first_region_apply = false on an existing state, because it plans to destroy the FlexScan IAM resources.
How do I remove everything?
Run terraform destroy to remove the IAM resources that this configuration manages. Resources that FlexScan created at runtime inside the scanner compartment (networking, bucket, and Functions) are not in the Terraform state, and they prevent the compartment from being deleted until they are removed.