{
  "id": "infrastructure-as-code",
  "title": "Infrastructure as Code",
  "lang": "en",
  "source_lang": "en",
  "summary": "Infrastructure as Code manages computing infrastructure through machine-readable definitions, enabling automated provisioning, reproducible change, and software-based operational controls.",
  "category": "computer-science",
  "subcategory": "software",
  "type": "concept",
  "aliases": [
    "IaC",
    "Infrastructure-as-code"
  ],
  "generated_at": "2026-11-05",
  "model": "pro/gpt-6.1-sol",
  "url": "https://aiwiki.page/en/infrastructure-as-code/",
  "translations": {
    "zh-Hans": {
      "url": "https://aiwiki.page/zh/infrastructure-as-code/",
      "json": "https://aiwiki.page/zh/infrastructure-as-code.json"
    }
  },
  "sections": [
    {
      "heading": "",
      "text": "Infrastructure as Code (IaC) is the practice of defining and managing computing infrastructure through machine-readable configuration or programs rather than primarily through manual administrative procedures. These definitions describe resources such as networks, servers, storage, identities, and managed services, together with their configuration and relationships. Software interprets the definitions and performs operations against physical systems, virtualization platforms, or service interfaces. IaC is widely associated with cloud computing, but it also applies to private data centers, network devices, and hybrid environments.\n\nIts importance lies in bringing infrastructure changes into the working methods of software engineering: definitions can be stored in version control, reviewed, tested, and deployed through automated processes. Infrastructure consequently becomes an inspectable, repeatable engineering artifact rather than a collection of undocumented actions. This does not make infrastructure perfectly reproducible or eliminate operational risk. Remote services, persistent data, permissions, software versions, and partial failures all affect the relationship between a definition and the system that actually exists."
    },
    {
      "heading": "Scope and conceptual boundaries",
      "text": "IaC covers several related activities that operate at different layers. Provisioning creates or removes infrastructure resources: for example, a virtual network, a subnet, a virtual machine, and an attached storage volume. Configuration management establishes properties inside an existing environment, such as installed packages, service settings, or user accounts. Deployment places application components into that environment. A single system may address several of these activities, but the distinction matters because their failure modes and lifecycles differ.\n\nA typical infrastructure definition specifies both objects and relationships. A web service might require a network segment, two application instances, a load balancer, a certificate, and a database. Its description can express which instances receive traffic, which identity may read a secret, and which network paths are permitted. The resulting artifact therefore represents more than an inventory. It captures part of the operational structure of a system, including dependencies that determine the order in which resources can be created or changed.\n\nIaC is broader than a particular file format. YAML, JSON, domain-specific languages, and general-purpose programming languages can all serve as input. Conversely, a configuration file is not necessarily an infrastructure definition: a file containing a few application preferences may not manage any resource lifecycle. A shell script that creates infrastructure can fall within the broad meaning of IaC, although a script without change detection, dependency handling, or repeatable execution provides fewer guarantees than a dedicated management system.\n\nThe boundary with Infrastructure as a Service is also important. IaaS describes a service delivery model in which computing resources are supplied through a provider. IaC describes how resources are defined and managed. An organization can use IaaS manually through a web console, or use IaC to control resources in its own facilities. Similarly, Platform as a Service and serverless computing do not remove infrastructure definitions: deployments still involve permissions, endpoints, scaling settings, execution environments, and service relationships.\n\nIaC is not an authoritative description of every aspect of a running system. Application data, transient connections, dynamically selected addresses, and platform-controlled replicas may exist outside its intended scope. Effective implementations distinguish properties under direct management from properties delegated to other controllers. Without that boundary, two automation systems can repeatedly overwrite each other’s changes even when each is behaving correctly according to its own configuration."
    },
    {
      "heading": "Historical development and major tool families",
      "text": "IaC developed from earlier efforts to automate system administration. Installation scripts, batch jobs, and machine configuration files long predate public cloud services. Their limitations became especially visible as organizations operated larger fleets of networked computers: administrators needed ways to express recurring policy, detect departures from it, and apply changes without manually logging into every machine. CFEngine, first released in 1993 and developed by Mark Burgess, was an important early system for policy-driven configuration management.\n\nThe next generation expanded these ideas into widely used frameworks. Puppet, initially released in 2005, described resources such as packages, files, and services through a declarative language. Chef, released in 2009, used a Ruby-based framework for expressing configuration. Both became associated with managing large server fleets and with the emerging DevOps movement, which emphasized cooperation between software development and operations. These tools helped make infrastructure definitions, reusable modules, and automated convergence established operational practices.\n\nPublic cloud platforms changed the object being managed. Instead of configuring only already-existing computers, organizations could request networks, instances, storage, and other services through an application programming interface. Amazon Web Services introduced AWS CloudFormation in 2011, allowing related AWS resources to be described and managed as stacks. Ansible, first released in 2012, offered an automation model commonly based on remote execution over existing communication mechanisms rather than requiring a dedicated management agent on each target.\n\nTerraform, first released by HashiCorp in 2014, popularized a provider-based approach to infrastructure provisioning across multiple services. Providers translate a common resource-management framework into operations supported by particular platforms. Pulumi, launched publicly in 2018, offered infrastructure definitions written using general-purpose languages, with a deployment engine managing resources and state. These approaches differ in language design and execution details, but both illustrate the separation between authoring infrastructure intent and carrying out remote operations.\n\nA related development was the rise of container orchestration. Kubernetes, publicly announced in 2014, made declarative resource objects and continuously running controllers central to managing containerized workloads. IaC increasingly encompassed both the provisioning of a cluster and definitions applied inside it. In 2023, following Terraform’s license change, the OpenTofu project was established as an open-source fork. This history illustrates that IaC is a family of practices and architectures rather than a single product lineage."
    },
    {
      "heading": "Declarative descriptions, procedural programs, and convergence",
      "text": "The most familiar distinction in IaC is between declarative and imperative approaches. An imperative procedure specifies actions: create a network, create a server, attach the server, and then start a service. A declarative description specifies an intended condition, such as a server with a particular image and network attachment. An execution engine determines which actions are needed to approach that condition. In practice, the categories overlap: declarative systems may invoke scripts, while programs written in general-purpose languages may construct a declarative resource graph.\n\nA central concept is idempotence. An operation is idempotent if repeating it has the same relevant effect as performing it once. If \\(f\\) represents a configuration operation over state \\(s\\), the idealized property is\n\n\\[f(f(s)) = f(s).\\]\n\nFor example, ensuring that a directory exists can be idempotent; appending an identical line to a file on every run generally is not. Idempotence helps make retries safer, but it is a property of particular operations and implementations, not an automatic consequence of storing instructions in text files.\n\nConvergence is related but distinct. A convergent controller repeatedly observes a system and applies corrections until the observed condition satisfies its specification. If \\(D\\) is a desired configuration and \\(R_t\\) is observed reality at time \\(t\\), a simplified model is\n\n\\[R_{t+1} = F(R_t, D).\\]\n\nA satisfactory fixed point has no remaining managed differences requiring action. Real controllers operate with incomplete observations, delayed responses, and concurrent external changes, so convergence depends on assumptions about the environment. A controller cannot establish a resource if the account lacks permission or a provider has exhausted its available capacity.\n\nDeclarative descriptions also differ in how much procedural logic they permit. Templates may allow only expressions and references, while other systems support loops, functions, classes, and package libraries. More expressive languages can reduce duplication and encode complex abstractions. They also introduce execution dependencies, less obvious behavior, and opportunities for infrastructure declarations to depend on external services or local machine state. A program that queries a changing endpoint while generating resources may produce different results from the same source revision.\n\nThe practical objective is therefore controlled repeatability, not mathematical determinism in all circumstances. Pinning tool versions, provider versions, machine images, and module dependencies narrows variation. Explicit inputs make differences between environments visible. Even with these controls, a provider may retire an instance type or change a service constraint. A complete infrastructure definition specifies intent within the capabilities and semantics of the platforms on which it depends."
    },
    {
      "heading": "Resource graphs, planning, and execution",
      "text": "Most provisioning engines internally represent infrastructure as a dependency graph. A resource is a node, and a dependency is an edge constraining execution order. If a virtual machine must reference a subnet identifier, the subnet normally has to exist before that machine can be created. Dependencies may be inferred from expressions or declared explicitly when the relationship is operational rather than directly represented in a property. A hidden dependency, such as a service requiring a newly assigned permission to become effective, can cause failures even when the visible graph is valid.\n\nFor an acyclic graph, a suitable ordering can be obtained through a topological traversal. Independent branches can execute concurrently, reducing deployment time. This is not unlimited parallelism: providers impose request quotas, resources compete for shared limits, and some operations must be serialized. Dependency cycles require special handling. For example, two security objects that refer to each other may need to be created first and connected through separate rule resources afterward.\n\nMany tools separate planning from application. Planning evaluates definitions, obtains relevant information about existing resources, and proposes actions such as creation, in-place modification, replacement, or deletion. A plan makes potentially disruptive changes visible before execution. Replacing a database instance is materially different from changing a label, even if both originate in a one-line edit. Whether a property can change in place is determined by the provider’s resource model and the remote service’s capabilities.\n\nA plan is not a reservation of future conditions. Between planning and application, another operator may change a resource, a quota may be consumed, or an external dependency may disappear. Some values remain unknown until a resource exists. Saved plans can bind execution more closely to a reviewed proposal, but they do not freeze the outside world. Tools therefore need checks for stale state, changed inputs, and execution prerequisites.\n\nInfrastructure deployment also rarely behaves like a single database transaction. A successful network creation may be followed by a failed instance launch, leaving a partially completed environment. An engine may attempt cleanup or rollback, but compensating operations can fail too, and deletion does not necessarily reverse every side effect. Reliable execution therefore depends on recording progress, classifying retryable errors, respecting dependency order during destruction, and exposing incomplete work for subsequent reconciliation. The graph helps organize operations; it does not turn a distributed collection of services into an atomic system."
    },
    {
      "heading": "State, resource identity, and configuration drift",
      "text": "IaC systems must distinguish three forms of information: the desired configuration, records maintained by the management tool, and the resources actually present in the environment. These can disagree. A configuration may request three servers, the tool may record three remote identifiers, and a provider may report that one server has been deleted manually. Correct behavior depends on reconciling these views rather than assuming any one is always current.\n\nSome provisioning systems maintain an explicit state snapshot linking logical resource addresses to remote identifiers. A logical name such as an application server resource is not necessarily its cloud-assigned identifier. This mapping lets the engine update the intended object instead of creating a duplicate. State may also contain computed attributes, dependency information, and sensitive values returned by a provider. Other systems keep corresponding management information in a hosted service or derive more of it from resource objects; they do not necessarily expose a local state file.\n\nResource identity makes refactoring operationally significant. Renaming a variable is usually a source-level change, but renaming a managed resource address can appear to the engine as deletion of one object and creation of another. Tools may support explicit move declarations or state-migration commands to preserve the mapping. Similarly, importing an existing resource establishes management of something created elsewhere. Import does not always generate a complete, maintainable declaration, and the imported configuration still has to match the attributes that should remain under management.\n\nConfiguration drift is divergence between intended and actual managed settings. It can arise from emergency manual edits, another automation system, provider-side defaults, or changes made through a console. Drift detection typically compares refreshed observations with the declared configuration. Resolution may mean restoring the declaration, changing the declaration to accept the new condition, or transferring ownership. Blindly overwriting every difference is inappropriate when some attributes are intentionally controlled by autoscaling services or external operators.\n\nShared state introduces coordination requirements. If two executions modify the same management record concurrently, they can overwrite information or act on incompatible assumptions. Remote backends commonly provide locking or related concurrency controls, but a lock for one state scope does not automatically protect every resource across an organization. State also requires backup, access restrictions, and recovery procedures. Losing the record does not necessarily destroy the infrastructure, but reconstructing correct ownership and resource mappings can be difficult, especially when several deployments manage similar objects."
    },
    {
      "heading": "Modules, environment design, and ownership",
      "text": "Infrastructure definitions become difficult to maintain when every deployment independently repeats networks, identities, logging settings, and service configurations. Modules address this by packaging related resources behind defined inputs and outputs. A module might create a private application service and expose its endpoint while accepting parameters for capacity, network placement, and identity. The module is an abstraction boundary: consumers work with its interface rather than every internal resource.\n\nGood module design follows operational boundaries as well as syntactic convenience. A network foundation may change infrequently and be owned by a central platform team, while an application service changes daily and belongs to a product team. Combining them into one deployment couples permissions, release timing, and failure scope. Separating every small resource, however, creates excessive cross-deployment dependencies. The appropriate unit is usually a coherent lifecycle and ownership domain rather than either a single resource or an entire enterprise.\n\nEnvironments introduce another dimension. Development, testing, and production often share structural definitions but differ in capacity, data retention, isolation, and access permissions. Parameterization can express these differences, but too many conditionals make a nominally shared module behave like several unrelated systems. Separate accounts, projects, or subscriptions can establish stronger isolation than names or labels alone. A tool’s workspace feature may isolate variables and state, but its security properties depend on the backend, credentials, and surrounding platform controls.\n\nVersioning modules makes changes explicit. A consumer pinned to a release can evaluate an update before adopting it. Compatibility is not limited to input names: changing a default from retaining storage to deleting it is a significant behavioral change even if the interface remains syntactically valid. Provider upgrades can likewise alter validation, attribute handling, or replacement decisions. Dependency lock files, release notes, and migration tests help distinguish intentional evolution from unexpected behavior.\n\nReuse does not automatically create portability. A module that wraps several cloud platforms may offer a common interface, but differences in networking, identity, consistency, and managed services remain. Hiding all differences behind the lowest common denominator can remove useful platform capabilities; exposing every difference can defeat the abstraction. IaC portability is consequently a spectrum. Shared workflows and design conventions may transfer readily, while resource definitions and operational assumptions remain provider-specific. Clear ownership and explicit interfaces are often more valuable than an appearance of universal interchangeability."
    },
    {
      "heading": "Review, testing, delivery, and GitOps",
      "text": "IaC allows infrastructure changes to pass through many of the same controls as application changes. Definitions stored in Git can be associated with an author, reviewed as a change set, and connected to an approval record. Code review can assess network exposure, resource replacement, permission changes, and expected expenditure before execution. The source difference alone is not sufficient: a small edit to a shared module or input can affect hundreds of resources, making the generated plan an important companion to the code.\n\nTesting occurs at several levels. Formatting and syntax checks detect malformed definitions. Static validation checks types, references, and some provider constraints without building a complete environment. Unit-style tests can examine generated resource properties, such as whether storage encryption is enabled or public access is disabled. Integration tests create real resources and verify interactions, including connectivity, identity permissions, and service behavior. Each level answers a different question, and passing static checks does not establish that a deployment will succeed.\n\nA continuous integration pipeline can perform these checks when a proposed change is submitted. A continuous delivery process then prepares or executes an approved deployment. Depending on the organization, low-risk changes may proceed automatically while sensitive changes require explicit authorization. The execution identity should be separate from ordinary developer identities where stronger control is needed. Logs can connect a source revision, plan, approval, and execution result, although that chain remains incomplete if operators can modify resources through unrecorded paths.\n\nGitOps is a related operating model in which versioned declarative definitions represent desired state and software agents automatically pull and reconcile that state. It is especially associated with Kubernetes, but its defining feature is not a particular file format or platform. A pipeline that runs an infrastructure command after a commit is not necessarily a continuous pull-based reconciler. GitOps also needs a strategy for dependencies, failed reconciliation, and bootstrap components that establish access to the repository itself.\n\nTesting and delivery are complicated by cost and persistent effects. A complete production-scale test environment may be expensive or unavailable because of quotas. Shared test resources reduce cost but introduce interference. Temporary environments require reliable destruction, including handling failures that occur before cleanup. Test data must also be distinguished from production data. Infrastructure automation can create a database service successfully while leaving its schema, contents, or migration sequence unsuitable for the application. These concerns connect infrastructure delivery to application release engineering without making the two identical."
    },
    {
      "heading": "Security, policy, and software supply chains",
      "text": "Infrastructure definitions are security-relevant programs. They can create privileged identities, expose services to the Internet, change encryption settings, or delete storage. A compromised deployment process may therefore have effects extending far beyond a single application. Least privilege applies both to the resources being created and to the automation identity that creates them. A pipeline authorized to manage one application does not inherently need permission to alter every identity or network in an account.\n\nSecrets present a particular challenge because infrastructure tools frequently observe sensitive attributes. Passwords, private keys, and service tokens can appear in variables, generated plans, state snapshots, or logs. Marking a value as sensitive may suppress its display without removing it from stored data. Encryption at rest and in transit, restricted backend access, careful log handling, and limited retention address different parts of this problem. Secret-management services can reduce the need to store long-lived credentials in a repository, but the deployment process still needs an authenticated way to access them.\n\nPolicy as code expresses organizational constraints in machine-evaluable form. Policies may require particular regions, prohibit unrestricted inbound access, constrain instance sizes, or require ownership labels. They can inspect source definitions, generated plans, or live resources. These locations provide different visibility: source inspection may miss generated values, while plan inspection may encounter unknown values that will exist only during execution. Preventive platform controls can enforce restrictions even when infrastructure is changed outside the IaC workflow.\n\nThe toolchain itself is part of the software supply chain. Providers, modules, container images, language packages, and pipeline extensions may execute code with deployment privileges. A malicious dependency can exfiltrate credentials or modify resources while appearing to be a routine infrastructure operation. Version constraints, trusted distribution channels, checksum verification, and digital signatures can support integrity controls, but they do not establish that the code’s behavior is safe. Dependencies require both provenance controls and appropriate evaluation.\n\nIaC also improves the availability of evidence without guaranteeing compliance. Version history can show that a definition changed; execution records can show which operations were attempted; provider audit logs can show which remote requests occurred. These are related but distinct records. A complete account of a security-relevant change may require correlating all three. Security analysis must also consider runtime conditions, application behavior, and manual access paths, because a compliant declaration is not proof that the live system remains continuously compliant."
    },
    {
      "heading": "Reliability, recovery, and practical limits",
      "text": "IaC can make recovery more systematic by preserving the instructions needed to reconstruct infrastructure. In disaster recovery, definitions can recreate networks, compute resources, and service settings in a replacement environment. They do not by themselves restore application data, external dependencies, or operational knowledge. Recovery still depends on usable backups, encryption keys, domain control, capacity availability, and an ordering that brings dependent services back safely. A reproducible empty database is not a recovered application.\n\nChanging infrastructure also differs from reverting application source. Returning to an earlier commit does not guarantee restoration of the earlier world. Deleted data may be gone; an old machine image may no longer be available; a provider may reject a previously accepted configuration. Database migrations can make old application versions incompatible with current data. Consequently, rollback may require restoration from backups, forward repair, or a separately designed replacement procedure rather than simply applying an older declaration.\n\nReplacement strategies trade availability against resource requirements. Creating a new resource before destroying an old one can reduce interruption, but it may require spare quota, compatible naming, and a way to move traffic. Some resource names must be unique, and some relationships prevent simultaneous old and new instances. Load balancing can support staged traffic migration for application servers, while stateful systems need additional attention to synchronization and consistency. Automation exposes these constraints; it cannot remove them.\n\nOperational risk also depends on deployment scope. A change applied to one service has a different potential impact from a change to a shared network module used by hundreds of services. Separate deployment units, staged rollouts, explicit approvals for destructive operations, and protected resource settings can limit the consequences of mistakes. Such controls may slow some changes, but infrastructure automation makes both correct and incorrect actions repeatable at scale. Speed alone is therefore an incomplete measure of success.\n\nSeveral limitations remain difficult to eliminate. Provider APIs may exhibit eventual consistency, making a resource visible to one operation before it is usable by another. Remote errors can leave an uncertain outcome: a request may time out after the service has already created the object. Two independent controllers can compete over the same setting. Cost estimates may omit usage-dependent charges, and successful provisioning does not establish performance under real workloads. Evaluating an IaC system consequently requires observing deployment success, recovery behavior, drift, service health, and operational effort, not merely whether its definitions parse correctly."
    }
  ],
  "links": [
    "cloud-computing",
    "software-engineering",
    "version-control",
    "virtual-machine",
    "programming-language",
    "infrastructure-as-a-service",
    "platform-as-a-service",
    "serverless-computing",
    "application-programming-interface",
    "open-source-software",
    "declarative-programming",
    "imperative-programming",
    "idempotence",
    "parallel-computing",
    "database-transaction",
    "data-backup",
    "code-review",
    "internet",
    "least-privilege",
    "encryption",
    "digital-signature",
    "disaster-recovery",
    "load-balancing",
    "eventual-consistency"
  ],
  "sources": [],
  "license": "https://creativecommons.org/licenses/by/4.0/"
}