Linode Terraform Provider

repository·dev·Indexed 42 days ago

https://github.com/linode/terraform-provider-linode

A Terraform provider that allows users to manage Linode Cloud infrastructure using a declarative configuration language. It enables automated provisioning and management of resources including Linodes, volumes, networking, Linode Kubernetes Engine (LKE) clusters, NodeBalancers, and Object Storage.

Tokens
121.1K
Snippets
330
Records
658
Agent score
49%

What's inside Linode Terraform Provider

  1. Manage Linode Images with linode_image

    dev

    The linode_image resource allows you to create, modify, and delete Linode Images. These images are snapshots of a Linode Instance Disk that can be used to provision new Linode Instances across different regions.

    Common Use Cases

    1. Creating an image from an existing Linode Instance: Requires providing the disk_id and linode_id of the source instance.
    2. Uploading an image from a local file: Requires a file_path and a region. This feature is currently in beta and requires the LINODE_API_VERSION environment variable to be set to v4beta.
    3. Replicating images: You can specify replica_regions to distribute the image across multiple core regions. Note that providing a new list of regions will remove the image from any existing regions not included in the list.
    resource "linode_image" "bar" {
        label = "foo-sda-image"
        description = "Image taken from foo"
        disk_id = linode_instance.foo.disk.0.id
        linode_id = linode_instance.foo.id
        tags = ["image-tag", "test"]
    }
  2. Manage Linode MySQL Databases with linode_database_mysql_v2

    dev

    The linode_database_mysql_v2 resource allows you to create, modify, and delete Linode Managed MySQL Databases.

    Important Note: Managed Databases can take up to 30 minutes to provision. The default database name in the returned cluster is defaultdb.

    resource "linode_database_mysql_v2" "foobar" {
      label = "mydatabase"
      engine_id = "mysql/8"
      region = "us-mia"
      type = "g6-nanode-1"
    }
  3. Manage Linode Instance Configurations with linode_instance_config

    dev

    The linode_instance_config resource manages a Linode Instance Configuration Profile. This profile defines how a Linode boots, including its devices (disks/volumes), network interfaces (Public, VLAN, VPC), and boot helpers.

    Important Lifecycle Notes:

    • VPC Updates: If a VPC interface is defined and the config is currently booted, the Linode must be powered off during the update. The provider attempts an implicit shutdown/restart unless booted is explicitly configured or skip_implicit_reboots is set to true in the provider configuration.
    • Reboots: Changes to a configuration that is currently booted will trigger a reboot.
    • Deletion: Deleting a configuration will shut down the attached instance if the configuration is currently in use.
    resource "linode_instance_config" "my-config" {
      linode_id = linode_instance.my-instance.id
      label = "my-config"
    
      device {
        device_name = "sda"
        disk_id = linode_instance_disk.boot.id
      }
    
      booted = true
    }
  4. Manage Linode network interfaces with linode_interface

    dev

    The linode_interface resource allows you to create, modify, and delete network interfaces for Linode instances. You can use it to configure Public, VLAN, VPC, or RDMA VPC networking.

    Important Note: This resource is designed to work with explicitly defined disk and config resources. When using it with a linode_instance_config, you must use depends_on to ensure the interface is created before the configuration is booted.

    resource "linode_interface" "public" {
      linode_id = linode_instance.my-instance.id
    
      public = {
        ipv4 = {
          addresses = [
            {
              address = "auto",
              primary = true,
            }
          ]
        }
        ipv6 = {
          ranges = [
            {
              range = "/64"
            }
          ]
        }
      }
    }
  5. Manage Linode PostgreSQL Databases with linode_database_postgresql_v2

    dev

    The linode_database_postgresql_v2 resource allows you to create, modify, and delete Linode Managed PostgreSQL Databases.

    Important Note: Managed Databases can take up to 30 minutes to provision. The default database name in the resulting cluster is defaultdb.

    Common configuration patterns include:

    • Network Access: Use allow_list to specify IPv4 addresses/ranges allowed to connect, or use the private_network block to place the database behind a VPC.
    • High Availability: Use cluster_size to define the number of nodes.
    • Maintenance: Use the updates block to schedule maintenance windows.
    • Forking: Use fork_source to create a new database from an existing one.
    resource "linode_database_postgresql_v2" "foobar" {
      label = "mydatabase"
      engine_id = "postgresql/16"
      region = "us-mia"
      type = "g6-nanode-1"
    }
  6. Manage Linode Monitor Logs Destinations

    dev

    The linode_monitor_logs_destination resource allows you to manage destinations for Linode Monitor logs. This feature is currently in v4beta.

    You must choose exactly one of two destination types:

    1. akamai_object_storage: Sends logs to an Akamai Object Storage bucket.
    2. custom_https: Sends logs to a custom HTTPS endpoint.

    Note: Changing the type argument will force the destruction and recreation of the resource.

    resource "linode_monitor_logs_destination" "example" {
      label = "my-logs-destination"
      type  = "akamai_object_storage"
    
      akamai_object_storage_details = {
        access_key_id     = "ACCESS_KEY"
        access_key_secret = "SECRET_KEY"
        bucket_name       = "my-bucket"
        host              = "my-host"
      }
    }
  7. Manage Linode Instance Disks with linode_instance_disk

    dev

    The linode_instance_disk resource allows you to create, modify, and delete Linode Instance Disks.

    Warning: Deleting a disk will shut down the attached instance if the instance is booted. If the disk was not in use by the booted configuration profile, the instance will be automatically rebooted.

    Warning: Resizing a disk will trigger a Linode reboot.

    resource "linode_instance_disk" "boot" {
      label = "boot"
      linode_id = linode_instance.my-instance.id
      size = 512
      filesystem = "ext4"
    }
    
    resource "linode_instance" "my-instance" {
      label = "my-instance"
      type = "g6-standard-1"
      region = "us-southeast"
    }
  8. Inspect pending database updates

    dev

    The pending_updates attribute is a set of upcoming mandatory maintenance tasks. Because it is a set, you must use a for expression or tolist() to access specific elements.

    Each entry in pending_updates contains:

    • deadline - The timestamp when the update must be applied.
    • description - A description of the update.
    • planned_for - The scheduled date and time for the maintenance.
  9. Use the linode_database_engines data source

    dev

    The linode_database_engines data source allows you to retrieve information about available Linode Managed Database engines. You can use it to discover engine IDs and versions, which is useful for dynamically configuring database resources like linode_database_mysql_v2.

    data "linode_database_engines" "all" {}
    
    output "engine_ids" {
      value = data.linode_database_engines.all.engines.*.id
    }
  10. Inspect pending updates in linode_database_postgresql_v2

    dev

    The pending_updates attribute is a Nested Attribute Set containing information about mandatory maintenance. Because it is a set, you cannot access elements by index; you must use a for expression or tolist() to iterate through them.

    Each entry in pending_updates contains:

    • deadline: The time when the update must be applied.
    • description: A description of the update.
    • planned_for: The scheduled date and time for the maintenance.
    # Example of accessing pending updates
    output "update_deadlines" {
      value = [for u in linode_database_postgresql_v2.example.pending_updates : u.deadline]
    }
  11. Manage Linode Personal Access Tokens with linode_token

    dev

    The linode_token resource allows you to create, modify, and delete Linode API Personal Access Tokens. These tokens proxy user credentials for Linode API access, enabling tools like Terraform or the Linode CLI to interact with Linode services on your behalf.

    To follow the principle of least privilege, use this resource to create tokens with specific scopes that narrow the access of the parent token, rather than using a broadly scoped token for every task.

    resource "linode_token" "foo" {
      label  = "token"
      scopes = "linodes:read_only"
      expiry = "2100-01-02T03:04:05Z"
    }
  12. Manage Linode Locks with linode_lock

    dev

    The linode_lock resource manages a Linode Lock, which prevents accidental deletion, rebuilding, or service transfers of resources.

    Important Permissions Note: Only unrestricted users can create and delete locks. Restricted users cannot manage locks, even if they have read/write permissions for the resource being locked.

    Constraint: Only one lock can exist per resource at a time. You cannot use both cannot_delete and cannot_delete_with_subresources on the same resource simultaneously.

    resource "linode_lock" "my-lock" {
      entity_id   = linode_instance.my-inst.id
      entity_type = "linode"
      lock_type   = "cannot_delete"
    }
    
    resource "linode_instance" "my-inst" {
      label  = "my-inst"
      region = "us-east"
      type   = "g6-nanode-1"
    }