Infrastructure as Code and the Provider Model
Infrastructure as code tools talk to clouds through providers. Understanding what a provider is, and where it leaks, explains most of the frustration teams hit.
Most infrastructure as code tooling shares one architectural idea. The tool itself knows nothing about clouds. It knows how to read a configuration, build a dependency graph, compare desired state to recorded state, and call out to a plugin. The plugin, usually called a provider, is the thing that knows that a virtual machine on one platform is created with a particular API call and a different set of required fields than on another.
That separation is why the same tool can manage compute on one platform, DNS on a registrar and a monitoring dashboard on a third service. It is also the source of nearly every confusing error message you will hit. This guide is about what sits on each side of that boundary and what it means for how you write and maintain your configurations.
Why the provider is the interesting part
When you write a resource block, you are not describing infrastructure in some neutral language. You are describing arguments to a specific provider’s schema, which is itself generated from a specific cloud’s API. The resource for a managed database on one platform will have fields the equivalent on another platform does not have, because the underlying services genuinely differ.
This has a consequence people often discover late. Infrastructure as code gives you a consistent workflow across providers. It does not give you portable configurations. Moving a stack from one cloud to another is a rewrite of nearly every resource block, even though the tool and the plan and apply cycle stay identical. If portability is a goal, read how to think about vendor lock-in before you assume the tool solves it.
State is the thing you are really managing
The configuration says what you want. The provider knows how to talk to the cloud. State is the record that connects a block in your code to an actual object with an actual identifier in an actual account. Lose the state and the tool no longer knows that your load balancer is yours; it will propose creating a second one.
Three practical rules follow. Store state remotely, in object storage or a dedicated backend, not on a laptop. Enable locking so two people cannot apply at once. Treat the state file as sensitive, because it frequently contains resource attributes that are effectively secrets, including generated passwords and connection strings. Encrypt it at rest and restrict who can read the bucket.
One state file or many
A single state file for the whole company is simple right up until it is not. Every apply locks everyone out, every plan takes minutes, and the blast radius of a bad apply is total. Split state along boundaries that match ownership and change frequency: networking separately from applications, each environment separately. This pairs naturally with keeping environments in separate provider accounts, where the account boundary and the state boundary line up.
Modules, resources and the mapping to provider APIs
A module is a grouping of resources with inputs and outputs. It is organisation, not abstraction, and confusing the two produces modules with forty variables that exist only to pass values through to the resources inside. If a module’s variable list is a flattened copy of the underlying resource schema, the module is adding indirection without adding meaning.
Good modules encode a decision. A module called “public web service” that creates a load balancer, a target group, a security group with one open port and a DNS record is useful because it bakes in a policy about how your organisation exposes services. A module called “instance” that wraps one resource is not.
Credentials and the provider block
Providers authenticate the same way the cloud’s own CLI does, and they usually look in the same places: environment variables, a shared credentials file, an instance role. Avoid writing credentials into the provider block itself. Beyond the obvious problem of committing secrets, hardcoded credentials make the configuration unusable by anyone who does not hold that exact key.
Where you run the tool matters as much as what the configuration says. Running an apply from a laptop with an administrator key is the most common way accounts get changed in ways nobody can explain afterwards. Push applies into automation and follow the credential design in pipelines that deploy to cloud infrastructure, where the identity is short lived and scoped to one environment.
When provider coverage lags the console
Cloud providers ship features through their own console and API first. The infrastructure as code provider catches up afterwards, sometimes in days and sometimes considerably later. You will eventually want a feature that exists in the console and has no corresponding field in the provider schema.
You have three options, in order of preference. Wait, if the feature is not urgent. Use the provider’s generic escape hatch, if it has one that lets you make raw API calls. Or configure that one thing by hand and document it loudly, accepting that it will not appear in any plan output. The third option is legitimate but it needs a comment in the code saying what was done manually and why, otherwise the next person will spend an afternoon wondering why reality does not match the configuration.
Coverage depth varies a lot by platform. Large platforms have large, actively maintained providers. Smaller platforms such as Hetzner or Vultr have smaller providers covering a smaller service surface, which is sometimes an advantage: there is less to get out of date. The Hetzner and Vultr comparison gets into how those two platforms differ in practice.
Multiple providers in one configuration
Real configurations are rarely single cloud, even when the compute is. DNS lives at a registrar, certificates come from somewhere, monitoring lives in a SaaS tool, and the identity platform may be Google Workspace. Each of those is a separate provider, each with its own credentials and its own rate limits.
Dependencies across providers are where ordering bugs appear. The tool builds its graph from references between resources, so if resource B needs A to exist but never references A’s output, the tool will happily create them in parallel and one will fail. Make the dependency explicit by referencing a real attribute rather than hardcoding a value you know will match.
Drift, imports and taking over an existing account
Drift is the gap between what the configuration says and what the account actually contains, created by someone clicking in the console. Detecting it is straightforward: run a plan on a schedule and alert when it is not empty. Deciding what to do about it is the harder part, because a drift sometimes represents an emergency fix that was genuinely correct and needs to be written back into the code.
Bringing existing infrastructure under management is the import problem. This comes up constantly when you inherit an environment, whether from a departing contractor or because you took over an account from elsewhere. The process is slow and unglamorous: write the resource block, import the existing object into state, run a plan, and iterate until the plan is empty. Expect the first plan to want to destroy things, and never apply until it stops wanting to. If you are in this position, pair the import work with the checks in securing an inherited cloud account, since the two inventories you need are nearly the same inventory.
What to write down for whoever inherits the code
Configurations outlive the people who write them. A short README in the repository root saves the next person a week. It should name the state backend and where to get access to it, list every environment and which account it maps to, name the resources that are managed by hand and why, and record the provider versions the configuration is known to work with.
Pin your provider versions. Providers introduce breaking schema changes between major releases, and an unpinned provider means a routine plan on a Tuesday can suddenly propose replacing your network. Upgrade deliberately, one provider at a time, with a plan you read carefully. If the configuration manages anything with a quota attached, the behaviour described in cloud service limits and quotas explains why some applies fail only at scale.
Infrastructure as code is not complicated as a concept. The complexity lives in the provider layer, in state, and in the gap between what you wrote months ago and what the account looks like today. Spend your attention there.