# Infrastructure

Infrastructure blocks are responsible for defining and provisioning the underlying infrastructure resources required by your services. This includes networks, compute instances, storage, and other foundational components.

## Syntax

```hcl
service "name" {
  infrastructure {
    resource_type "resource_name" {
      attribute = value
    }
  }
}
```

## Resource Types

* **network**: Defines networking components like VPCs, subnets, internet gateways, etc.
* **compute**: Specifies compute resources such as virtual machines, clusters, node pools, etc.
* **iam**: Manages Identity and Access Management resources.
* **storage**: Configures storage accounts and related resources.
* **cluster**: To define Kubernetes clusters.

(Note: the above resource types are generally recommended, but changing the resource type has no effect on conversion of functionality and it is only to make code more intuitive/cleaner. So if a database is assigned the resource type "compute", it won't change anything. In fact users can name their own resource types like "database" or "kubernetes" without any issues.)

## Defining Resources

Each resource within the **Infrastructure** block is defined by specifying its type, name, and relevant attributes. Attributes vary based on the resource type.

**Common Attributes:**

* **name**: The identifier for the resource.
* **resource\_type**: The specific type of resource to be provisioned.
* **tags**: Key-value pairs for resource tagging.
* **dependencies**: Specifies dependencies on other resources.

## Dependencies

Dependencies ensure that resources are provisioned in the correct order. Use the `depends_on` attribute to declare dependencies explicitly.

## Example

```hcl
service "name" {
  infrastructure {
    ...
    
    network "vpc" {
      cidr_block           = "10.0.0.0/16"
      enable_dns_hostnames = true
      enable_dns_support   = true
      tags = {
        Name = "main-vpc"
      }
      resource_type = "aws_vpc"
    }
    
    compute "web_server" {
      instance_type = "t2.micro"
      ami           = "ami-005fc0f236362e99f"
      subnet_id     = "${infrastructure.network.vpc.id}"
      tags = {
        Name = "main_web_server"
      }
      key_name      = "cloud-cli-key"
      depends_on    = ["infrastructure.network.vpc"]
      resource_type = "aws_instance"
    }
  }
  ...
}
```
