In the first part of this series, we looked at the challenges of traditional configuration and secret management: manual updates, scattered secrets and security gaps.
In this part, we look at how Infrastructure as Code (IaC) handles these challenges. It creates and fills in configuration and secrets for each environment, and it connects the infrastructure to the applications that use it.
Why Secrets Management Matters
Secrets are sensitive values that applications need to work.
They fall into two categories:
- External secrets: credentials and keys for outside services, such as third-party API keys or an observability system.
- Internal secrets: sensitive values inside the application's own system, such as database passwords and tokens between services.
When these secrets are mismanaged, the result is security gaps, wasted effort and deployments that behave differently in each environment.
How IaC Addresses Secret Management Challenges
Full context awareness
IaC tools define and manage infrastructure resources, so they create most internal secret values themselves.
When secret management is part of the IaC workflow:
- Secrets stay in context. Secrets are created and used inside the infrastructure's context, so they are less likely to be misused elsewhere.
- Secrets are filled in for you. IaC hands each application the secrets it needs, with no manual handover.
This matters most for secrets that IaC creates itself, such as database passwords and IAM roles.
Consistent secret provisioning
Because IaC defines the infrastructure and its dependencies, it can handle secrets the same way in every environment:
- Automated provisioning. Secrets such as database passwords and IAM roles are created and filled in automatically.
- No manual handover. Nobody copies a secret from one system to another during a deployment.
Integration with secret stores
IaC works with secret management systems such as AWS Secrets Manager, HashiCorp Vault and Kubernetes Secrets to store and read sensitive values. This gives you one secure place for all secrets.
Central external secrets
IaC also helps with external secrets:
- One source of truth. Secrets are defined and managed in one place, so they are easier to maintain and audit.
- Values per environment. One definition can hold a different value for each environment, such as separate API keys for development, staging and production.
- Scoped access. IaC can limit each secret to the applications and environments that need it, so one environment does not read another's secrets.
Decoupling Secrets from Applications
In traditional setups, applications fetch secrets directly. That adds risk and complexity, because each application needs access to a central secret store and code to read from it.
With secrets managed through IaC, you can separate secrets from application code:
- Inject secrets at deployment time. The deployment gives the application its secrets, so the application does not fetch or manage them.
- Use standard access methods. Applications read secrets from environment variables or mounted files, and IaC fills in the right value from the secret store.
- Let the module create the credential. The module that creates a database also creates its credential and publishes it as an output. The deployment hands that credential to the service that uses the database. Nobody shares a password with a developer in a chat message or a ticket.
Templated Configuration Files with IaC
Challenges with traditional configuration management
Applications often use a separate configuration file for each environment. This:
- Increases the risk of errors. Manual configuration across environments leads to inconsistencies and mistakes.
- Needs coordination between teams. Keeping the right values in every team and every environment is complex and error-prone.
IaC solution: templated configurations
IaC lets you write one configuration template that works in every environment, and fill in the real values during deployment.
The benefits:
- Simpler management. One template serves every environment.
- Consistent environments. One template, filled in the same way each time, keeps environments consistent.
Refer to services by name, not by address
A service should refer to the things it uses by name, such as "orders-db" or "payments-queue", and not by address. Each environment then resolves the name to its own address. A new environment needs no new configuration file and no change to a central map of endpoints. The template stays the same, and the environment fills in the rest.
IaC's role in template fulfillment
During deployment, IaC processes the templates:
- Resolving placeholders. IaC replaces each placeholder with the secret or configuration value for the target environment.
- Checking values. Because IaC controls the template processing, it can check that only valid, authorized values are filled in.
- Wiring the result. The configuration reaches each service as environment variables, or as config maps and Kubernetes Secrets.
Enhancing developer experience with IaC
- Secret key catalogs. IaC can keep a catalog of the available secret keys and what each one is for, as a reference for developers.
- Validation. Before deployment, IaC can check that every placeholder in a template has a value, so a missing value does not fail at runtime.
- Developer tools. Integration with development tools can give autocomplete and syntax checks, which saves time and prevents mistakes.
Before and after: an example
Before templating (one file per environment)
123456789# dev-config.yamlapi_key: dev-12345host: dev.example.com# prod-config.yamlapi_key: prod-67890host: prod.example.com
After templating
1234# config-template.yamlapi_key: "<API_KEY>"host: "<HOST>"
After wiring
The last step removes the placeholders for values that come from infrastructure. The service refers to its database's outputs, and each release fills in that environment's host, username and password. In this service spec.env, each line becomes an environment variable:
123"POSTGRES_URL": "jdbc:postgresql://${postgres.default-db.out.interfaces.writer.host}/postgres","POSTGRES_USER": "${postgres.default-db.out.interfaces.writer.username}","POSTGRES_PASS": "${postgres.default-db.out.interfaces.writer.password}"
The same lines work in development, staging and production. Nobody copies a host or a password into a file.
Benefits of Adopting IaC for Configuration and Secrets Management
Better security
- Less exposure of secrets. No hard-coded secrets in configuration files and no manual handovers mean fewer chances of a leak.
- Central access control. IaC gives fine-grained control over who can read and change external secrets, which helps with compliance and audits.
- Easier rotation. IaC can make it easier to rotate secrets, such as database passwords, on a schedule, without extra work for developers.
More efficient operations
- Less repetitive work. Provisioning resources and injecting secrets happen automatically.
- Fewer errors. Automated steps reduce human error, so deployments are more reliable and environments stay consistent.
- Faster deployments. Fewer manual steps mean each deployment finishes sooner.
Easier scaling
- New environments without new files. New infrastructure and environments are created from code, with their configuration and secrets filled in by IaC. You do not update many configuration files to launch a feature environment, even with many microservices.
- Many environments, one process. Configuration and secrets are filled in the same way in every environment.
- Less cloud lock-in. IaC can hide some details of each cloud provider, which makes a later move between clouds easier.
Better collaboration
- Version control. IaC lives in version control, with a history of every change, so teams can review and collaborate.
- Clear separation of concerns. Developers focus on application logic, and IaC handles the infrastructure and its configuration. Teams depend less on each other for each change.
Why wiring matters more when agents make the change
AI assistants and infrastructure agents now add services and environments too. An agent that copies a host by hand makes exactly the kind of guess that breaks a deployment. With wiring, the agent declares what it needs, such as "the orders service uses orders-db", and the release fills in the values for each environment. The agent does not need to know the password at all.
Conclusion
When you manage configuration and secrets with Infrastructure as Code, you avoid most of the problems of traditional methods.
IaC gives you a framework for:
- Central secrets management. Secrets are handled the same way, securely, in every environment.
- Automated configuration. Less manual effort, fewer errors and faster deployments.
- Security and compliance. Good practice for handling secrets, controlling access and auditing changes.
- Scale. New services and environments without new configuration files.
In Facets, a service refers to its database's outputs, and to project variables and secrets, in the blueprint. Each release fills in that environment's values, so there is no separate pipeline or values file to keep in sync. Secret values stay out of Git: the control plane keeps them per environment, and release logs hide them. See secrets and variables and managing secrets and variables. Facets' Terraform module catalog is open source.
In the next part of this series, we look at why the application deployment belongs in the same IaC model as the infrastructure and its configuration.
Read Part 3: Why You Should Use IaC to Deploy Your Applications.
