### Example Usage of Incus Network Data Source Source: https://github.com/lxc/terraform-provider-incus/blob/main/docs/data-sources/network.md Use this data source to retrieve details of an existing Incus network by its name. The `name` argument is required. This example also shows how to output the retrieved network name. ```hcl data "incus_network" "this" { name = "default" } output "network_name" { value = data.incus_network.this.name } ``` -------------------------------- ### Terraform Import Command Example Source: https://github.com/lxc/terraform-provider-incus/blob/main/docs/resources/storage_volume.md Demonstrates how to import an existing Incus storage volume into Terraform state using the `terraform import` command. ```shell terraform import incus_storage_volume.myvol proj/pool1/vol1 ``` -------------------------------- ### Terraform Import Block Example Source: https://github.com/lxc/terraform-provider-incus/blob/main/docs/resources/storage_volume.md Shows how to use the `import` block in Terraform configuration (v1.5.0+) to import an Incus storage volume. ```hcl resource "incus_storage_volume" "myvol" { name = "vol1" pool = "pool1" project = "proj" } import { to = incus_storage_volume.myvol id = "proj/pool1/vol1" } ``` -------------------------------- ### Create an Incus storage bucket from a backup file Source: https://github.com/lxc/terraform-provider-incus/blob/main/docs/resources/storage_bucket.md This example demonstrates creating a storage bucket by restoring it from a tar.gz backup file. Specify the path to the backup file using `source_file`. ```hcl resource "incus_storage_bucket" "bucket_from_backup" { name = "restored-bucket" pool = "default" source_file = "/path/to/backup.tar.gz" } ``` -------------------------------- ### Import Incus Network Forward (Terraform CLI) Source: https://github.com/lxc/terraform-provider-incus/blob/main/docs/resources/network_forward.md Example of how to import an existing Incus network forward resource using the Terraform command line. ```shell terraform import incus_network_forward.forward1 proj/my-network/10.150.19.10 ``` -------------------------------- ### Run Exec Commands on Incus Instance Source: https://github.com/lxc/terraform-provider-incus/blob/main/docs/resources/instance.md Defines commands to be executed within the Incus instance after it's created. Supports multiple commands with triggers and timeouts, useful for initial setup like installing packages. ```hcl resource "incus_instance" "instance1" { name = "instance1" image = "images:debian/12" file { content = var.ssh_pubkey target_path = "/root/.ssh/authorized_keys" uid = 0 gid = 0 mode = "0600" create_directories = true } exec = { "00-install-ssh" = { command = ["apt-get", "update"] trigger = "once" } "01-install-ssh" = { command = ["apt-get", "install", "-y", "openssh-server"] timeout = "5m" trigger = "once" } "10-restart-ssh" = { command = ["systemctl", "restart", "ssh"] } } } ``` -------------------------------- ### Wait for Cloud-Init to Complete Source: https://github.com/lxc/terraform-provider-incus/blob/main/docs/resources/instance.md Configures the instance to wait until cloud-init has finished its execution. This is crucial for instances that rely on cloud-init for initial setup. ```hcl resource "incus_instance" "instance1" { project = "default" name = "instance1" image = "images:ubuntu/24.04/cloud" wait_for { type = "cloud-init" } } ``` -------------------------------- ### Example Usage of Incus Instance Data Source Source: https://github.com/lxc/terraform-provider-incus/blob/main/docs/data-sources/instance.md Use this data source to retrieve details of an Incus instance by its name. The instance must exist in the specified project or the default project. ```hcl data "incus_instance" "this" { name = "default" } output "instance_name" { value = data.incus_instance.this.name } ``` -------------------------------- ### Example Usage of Incus Profile Data Source Source: https://github.com/lxc/terraform-provider-incus/blob/main/docs/data-sources/profile.md Demonstrates how to use the `incus_profile` data source to retrieve profile details and output the profile name. Ensure the profile 'default' exists in your Incus instance. ```hcl data "incus_profile" "this" { name = "default" } output "profile_name" { value = data.incus_profile.this.name } ``` -------------------------------- ### Example Usage of Incus Image Data Source Source: https://github.com/lxc/terraform-provider-incus/blob/main/docs/data-sources/image.md Use this data source to fetch image details, such as its fingerprint, which can then be used to create an Incus instance. ```hcl data "incus_image" "debian_custom" { name = "debian_custom" } resource "incus_instance" "d1" { image = data.incus_image.debian_custom.fingerprint name = "d1" } ``` -------------------------------- ### Data Source: incus_instance Source: https://github.com/lxc/terraform-provider-incus/blob/main/docs/data-sources/instance.md Use the `incus_instance` data source to get information about an existing Incus instance. ```APIDOC ## Data Source: incus_instance Provides information about an Incus instance. See Incus instance [configuration reference](https://linuxcontainers.org/incus/docs/main/explanation/instance_config/) for more details. ### Example Usage ```hcl data "incus_instance" "this" { name = "default" } output "instance_name" { value = data.incus_instance.this.name } ``` ### Argument Reference * `name` - **Required** - Name of the instance. * `project` - *Optional* - Name of the project where the instance is be stored. * `remote` - *Optional* - The remote in which the resource was created. If not provided, the provider's default remote will be used. ### Attribute Reference * `description` - Description of the instance. * `config` - Map of key/value pairs of config settings. [instance config settings](https://linuxcontainers.org/incus/docs/main/reference/instance_options/) * `status` - Status of the instance. * `location` - Location of the instance. * `device` - Device definitions. See reference below. * `type` - Instance type. * `architecture` - Architecture name. * `ephemeral` - Whether the instance is ephemeral (deleted on shutdown). * `profiles` - List of profiles applied to the instance. * `stateful` - Whether the instance is stateful. The `device` blocks support: * `name` - Name of the device. * `type` - Type of the device Must be one of none, disk, nic, unix-char, unix-block, usb, gpu, infiniband, proxy, unix-hotplug, tpm, pci. * `properties` - Map of key/value pairs of [device properties](https://linuxcontainers.org/incus/docs/main/reference/devices/). ``` -------------------------------- ### Import Incus Instance with Terraform CLI Source: https://github.com/lxc/terraform-provider-incus/blob/main/docs/resources/instance.md Example of how to import an existing Incus instance into Terraform state using the `terraform import` command. Ensure the ID syntax matches the required format. ```shell terraform import incus_instance.myinst proj/c1,image=images:alpine/edge/amd64 ``` -------------------------------- ### Create Resource for Each Cluster Member Source: https://github.com/lxc/terraform-provider-incus/blob/main/docs/data-sources/cluster.md This example iterates over each cluster member obtained from the `incus_cluster` data source to create an `incus_server` resource for each. It conditionally sets the `target` based on whether the cluster is clustered. ```hcl data "incus_cluster" "this" {} resource "incus_server" "nodes" { for_each = data.incus_cluster.this.members target = data.incus_cluster.this.is_clustered ? each.key : null config = { "core.bgp_address" = ":179" } } ``` -------------------------------- ### Data Source: incus_storage_bucket Source: https://github.com/lxc/terraform-provider-incus/blob/main/docs/data-sources/storage_bucket.md Use the `incus_storage_bucket` data source to get information about an existing Incus storage bucket. ```APIDOC ## Data Source: incus_storage_bucket Provides information about an Incus storage bucket. See Incus storage bucket [configuration reference](https://linuxcontainers.org/incus/docs/main/howto/storage_buckets/) for more details. ### Example Usage ```hcl data "incus_storage_bucket" "this" { name = "default" storage_pool = "parent" } output "storage_bucket_name" { value = data.incus_storage_bucket.this.name } ``` ### Argument Reference * `name` - **Required** - Name of the storage bucket. * `storage_pool` - **Required** - Name of the parent storage pool. * `project` - *Optional* - Name of the project where the storage bucket is be stored. * `remote` - *Optional* - The remote in which the resource was created. If not provided, the provider's default remote will be used. * `target` - *Optional* - Specify a target node in a cluster. ### Attribute Reference * `description` - Description of the storage bucket. * `config` - Map of key/value pairs of config settings. [storage bucket config settings](https://linuxcontainers.org/incus/docs/main/reference/storage_drivers/) * `location` - Location of the storage bucket. * `s3_url` - Storage Bucket S3 URL. ``` -------------------------------- ### Importing Incus Storage Pool (CLI) Source: https://github.com/lxc/terraform-provider-incus/blob/main/docs/resources/storage_pool.md Example of how to import an existing Incus storage pool using the Terraform CLI. Ensure the import ID format matches your remote and project structure. ```shell terraform import incus_storage_pool.mypool proj/pool1 ``` -------------------------------- ### Configure Local and Global Incus Server Settings Source: https://github.com/lxc/terraform-provider-incus/blob/main/docs/resources/server.md This example shows how to configure both local node-specific and global server settings using multiple incus_server resources. It utilizes Terraform locals and `for_each` for dynamic configuration and `depends_on` to manage dependencies between local and global configurations. ```hcl locals { remote = "cluster" bgp_routerids = { "node1" = "192.0.2.100" "node2" = "192.0.2.101" "node3" = "192.0.2.102" } } resource "incus_server" "local" { for_each = tomap(local.bgp_routerids) remote = local.remote target = each.key config = { "core.bgp_address" = ":179" "core.bgp_routerid" = each.value } } resource "incus_server" "global" { remote = local.remote config = { "core.bgp_asn" = "65500" } depends_on = [ incus_server.local ] } ``` -------------------------------- ### Example Usage of Incus Storage Volume Data Source Source: https://github.com/lxc/terraform-provider-incus/blob/main/docs/data-sources/storage_volume.md Use this data source to fetch information about a specific Incus storage volume. Ensure the storage volume, type, and storage pool are correctly specified. ```hcl data "incus_storage_volume" "this" { name = "default" type = "custom" storage_pool = "parent" } output "storage_volume_name" { value = data.incus_storage_volume.this.name } ``` -------------------------------- ### Create a restricted Incus certificate for a project Source: https://github.com/lxc/terraform-provider-incus/blob/main/docs/resources/certificate.md This example demonstrates creating a certificate restricted to specific projects. It requires defining the project resource first. The certificate type can be specified, defaulting to 'client' if omitted. ```hcl resource "incus_project" "project1" { name = "project1" } resource "incus_certificate" "prometheus" { name = "prometheus" description = "Prometheus Node Exporter Access" restricted = true projects = [incus_project.project1.name] type = "metrics" certificate = file("${path.module}/metrics.crt") } ``` -------------------------------- ### Get Incus Project Information Source: https://github.com/lxc/terraform-provider-incus/blob/main/docs/data-sources/project.md Use this data source to fetch details about a specific Incus project by its name. Requires the project name as an argument. ```hcl data "incus_project" "this" { name = "default" } output "project_name" { value = data.incus_project.this.name } ``` -------------------------------- ### Import Incus Network Resource Source: https://github.com/lxc/terraform-provider-incus/blob/main/docs/resources/network.md Example of importing an Incus network resource using the terraform import command. This is useful for bringing existing Incus networks under Terraform management. ```shell terraform import incus_network.mynet proj/net1 ``` -------------------------------- ### Example Usage of Incus Storage Pool Data Source Source: https://github.com/lxc/terraform-provider-incus/blob/main/docs/data-sources/storage_pool.md Use this data source to fetch information about a specific Incus storage pool by its name. The retrieved name can then be used in outputs or other resources. ```hcl data "incus_storage_pool" "this" { name = "default" } output "storage_pool_name" { value = data.incus_storage_pool.this.name } ``` -------------------------------- ### Example Usage of Incus Storage Bucket Data Source Source: https://github.com/lxc/terraform-provider-incus/blob/main/docs/data-sources/storage_bucket.md Use this data source to retrieve information about an existing Incus storage bucket. Specify the bucket's name and its parent storage pool. The output can then be used to access bucket properties like its name. ```hcl data "incus_storage_bucket" "this" { name = "default" storage_pool = "parent" } output "storage_bucket_name" { value = data.incus_storage_bucket.this.name } ``` -------------------------------- ### Import Incus Network Forward (Terraform Import Block) Source: https://github.com/lxc/terraform-provider-incus/blob/main/docs/resources/network_forward.md Example of how to import an existing Incus network forward resource using the Terraform import block, available in Terraform v1.5.0 and later. ```hcl resource "incus_network_forward" "forward1" { network_name = "my-network" listen_address = "10.150.19.10" project = "proj" } import { to = incus_network_forward.forward1 id = "proj/my-network/10.150.19.10" } ``` -------------------------------- ### Import an Incus storage bucket using Terraform import command Source: https://github.com/lxc/terraform-provider-incus/blob/main/docs/resources/storage_bucket.md This is an example of how to import an existing Incus storage bucket into Terraform state using the `terraform import` command. The ID format is `://`. ```shell terraform import incus_storage_bucket.bucket1 proj/pool1/bucket1 ``` -------------------------------- ### Example Usage of Incus Network Load Balancer Data Source Source: https://github.com/lxc/terraform-provider-incus/blob/main/docs/data-sources/network_load_balancer.md Use this data source to fetch details of an Incus network load balancer. Specify the listen address and parent network to identify the load balancer. The output can then be used to access attributes like the listen address. ```hcl data "incus_network_load_balancer" "this" { listen_address = "127.0.0.1" network = "parent" } output "network_load_balancer_listen_address" { value = data.incus_network_load_balancer.this.listen_address } ``` -------------------------------- ### Prevent Execution if Cluster Members are Offline Source: https://github.com/lxc/terraform-provider-incus/blob/main/docs/data-sources/cluster.md This example uses a `postcondition` to ensure all cluster members are 'Online' before proceeding. If any member is not 'Online', the execution will fail with the specified error message. ```hcl data "incus_cluster" "this" { remote = "cluster" lifecycle { postcondition { condition = alltrue(self.is_clustered ? [for i, v in self.members : v.status == "Online"] : []) error_message = "All servers must be online." } } } ``` -------------------------------- ### Specifying Multiple Incus Remotes Source: https://github.com/lxc/terraform-provider-incus/blob/main/docs/index.md Configure the Incus provider with multiple remotes, certificate generation, and acceptance, and a default remote. Useful when running Terraform from a system without Incus installed. ```hcl provider "incus" { generate_client_certificates = true accept_remote_certificate = true default_remote = "local" remote { name = "local" address = "unix://" } remote { name = "incus-server-2" address = "https://10.1.2.8,https://10.1.2.9" token = "token" } } ``` -------------------------------- ### Import Incus Network Zone Record Source: https://github.com/lxc/terraform-provider-incus/blob/main/docs/resources/network_zone_record.md Example of importing an existing Incus network zone record using the terraform import command. The ID format is '[remote]:[project]//'. ```shell terraform import incus_network_zone_record.myrecord proj/zone1/record1 ``` -------------------------------- ### Import Cluster Incus Network Resource Source: https://github.com/lxc/terraform-provider-incus/blob/main/docs/resources/network.md Example of importing Incus network resources for a cluster node using the terraform import command. This allows managing networks on specific cluster members. ```shell terraform import incus_network.my_network_node1 proj/net1,target=node1 terraform import incus_network.my_network_node2 proj/net1,target=node2 terraform import incus_network.my_network proj/net1 ``` -------------------------------- ### Import Incus Network Zone Record with Import Block Source: https://github.com/lxc/terraform-provider-incus/blob/main/docs/resources/network_zone_record.md Example of importing an Incus network zone record using the Terraform import block, available in Terraform v1.5.0 and later. This requires defining the resource with its expected attributes. ```hcl resource "incus_network_zone_record" "myrecord" { name = "record1" zone = "zone1" project = "proj" } import { to = incus_network_zone_record.myrecord id = "proj/zone1/record1" } ``` -------------------------------- ### Import an Incus Profile using Terraform Import Block Source: https://github.com/lxc/terraform-provider-incus/blob/main/docs/resources/profile.md Example of importing an Incus profile using the `import` block, available in Terraform v1.5.0 and later. This requires defining the resource and then specifying the ID to import. ```hcl resource "incus_profile" "myprofile" { name = "profile1" project = "proj" } import { to = incus_profile.myprofile id = "proj/profile1" } ``` -------------------------------- ### Get Incus Network Zone Details Source: https://github.com/lxc/terraform-provider-incus/blob/main/docs/data-sources/network_zone.md Use this data source to fetch information about a specific Incus network zone by its name. The `name` argument is required. You can optionally specify the `project` and `remote`. ```hcl data "incus_network_zone" "this" { name = "default" } output "network_zone_name" { value = data.incus_network_zone.this.name } ``` -------------------------------- ### Import Cluster Incus Network Resource with Import Block Source: https://github.com/lxc/terraform-provider-incus/blob/main/docs/resources/network.md Example of importing Incus network resources for cluster nodes using Terraform's import block. This demonstrates how to import networks targeting specific nodes and general cluster networks. ```hcl resource "incus_network" "my_network_node1" { name = "net1" project = "proj" target = "node1" } import { to = incus_network.my_network_node1 id = "proj/net1,target=node1" } resource "incus_network" "my_network_node2" { name = "net1" project = "proj" target = "node2" } import { to = incus_network.my_network_node2 id = "proj/net1,target=node2" } resource "incus_network" "my_network" { name = "net1" project = "proj" } import { to = incus_network.my_network id = "proj/net1" } ``` -------------------------------- ### Import Incus Network Resource with Import Block Source: https://github.com/lxc/terraform-provider-incus/blob/main/docs/resources/network.md Example of importing an Incus network resource using Terraform's import block, available in v1.5.0 and later. This method allows defining the resource configuration alongside the import ID. ```hcl resource "incus_network" "mynet" { name = "net1" project = "proj" } import { to = incus_network.mynet id = "proj/net1" } ``` -------------------------------- ### Get Incus Network Forward Information Source: https://github.com/lxc/terraform-provider-incus/blob/main/docs/data-sources/network_forward.md Use this data source to fetch details of an existing Incus network forward. Specify the `listen_address` and `network` to identify the forward. The `project` and `remote` can be used for more specific lookups. ```hcl data "incus_network_forward" "this" { listen_address = "127.0.0.1" network = "parent" } output "network_forward_listen_address" { value = data.incus_network_forward.this.listen_address } ``` -------------------------------- ### Data Source: incus_profile Source: https://github.com/lxc/terraform-provider-incus/blob/main/docs/data-sources/profile.md Use the incus_profile data source to get information about an Incus profile. ```APIDOC ## Data Source: incus_profile Provides information about an Incus profile. See Incus profile [configuration reference](https://linuxcontainers.org/incus/docs/main/profiles/) for more details. ### Example Usage ```hcl data "incus_profile" "this" { name = "default" } output "profile_name" { value = data.incus_profile.this.name } ``` ### Argument Reference * `name` - **Required** - Name of the profile. * `project` - *Optional* - Name of the project where the profile is be stored. * `remote` - *Optional* - The remote in which the resource was created. If not provided, the provider's default remote will be used. ### Attribute Reference * `description` - Description of the profile. * `config` - Map of key/value pairs of config settings. [instance config settings](https://linuxcontainers.org/incus/docs/main/reference/instance_options/) * `device` - Device definitions. See reference below. The `device` blocks support: * `name` - Name of the device. * `type` - Type of the device Must be one of none, disk, nic, unix-char, unix-block, usb, gpu, infiniband, proxy, unix-hotplug, tpm, pci. * `properties` - Map of key/value pairs of [device properties](https://linuxcontainers.org/incus/docs/main/reference/devices/). ``` -------------------------------- ### Create an Incus Profile and Instance Source: https://github.com/lxc/terraform-provider-incus/blob/main/docs/resources/profile.md Defines an Incus profile with CPU limits and disk devices, and then creates an Incus instance using that profile. Ensure the 'ubuntu' image is available in your Incus instance. ```hcl resource "incus_profile" "profile1" { name = "profile1" config = { "limits.cpu" = 2 } device { name = "shared" type = "disk" properties = { source = "/tmp" path = "/tmp" } } device { type = "disk" name = "root" properties = { pool = "default" path = "/" } } } resource "incus_instance" "test1" { name = "test1" image = "ubuntu" ephemeral = false profiles = [incus_profile.profile1.name] } ``` -------------------------------- ### Create an Incus instance using a custom profile Source: https://github.com/lxc/terraform-provider-incus/blob/main/docs/resources/network.md Launches an Incus instance named 'test1' using the 'ubuntu' image and applying the custom profile 'profile1'. ```hcl resource "incus_instance" "test1" { name = "test1" image = "ubuntu" ephemeral = false profiles = ["${incus_profile.profile1.name}"] } ``` -------------------------------- ### Compile Terraform Provider from Source Source: https://github.com/lxc/terraform-provider-incus/blob/main/README.md Compile the provider from source code to create a development binary. Ensure you have a Golang development environment set up. ```shell cd terraform-provider-incus go build -v ``` -------------------------------- ### Data Source: incus_network_address_set Source: https://github.com/lxc/terraform-provider-incus/blob/main/docs/data-sources/network_address_set.md Use the `incus_network_address_set` data source to get information about an existing Incus network address set. ```APIDOC ## Data Source: incus_network_address_set ### Description Use the `incus_network_address_set` data source to get information about an existing Incus network address set. ### Method Data Source ### Endpoint N/A (Data Source) ### Parameters #### Query Parameters - **name** (String) - Required - Name of the network address set. - **project** (String) - Optional - Name of the project where the network address set is be stored. - **remote** (String) - Optional - The remote in which the resource was created. If not provided, the provider's default remote will be used. ### Response #### Success Response (200) - **description** (String) - Description of the network address set. - **config** (Map) - Map of key/value pairs of config settings. - **addresses** (List) - List of network addresses. ### Request Example ```hcl data "incus_network_address_set" "this" { name = "default" } output "network_address_set_name" { value = data.incus_network_address_set.this.name } ``` ### Response Example ```json { "description": "A sample network address set description", "config": { "key1": "value1", "key2": "value2" }, "addresses": [ "192.168.1.100", "192.168.1.101" ] } ``` ``` -------------------------------- ### Basic Incus Instance Creation Source: https://github.com/lxc/terraform-provider-incus/blob/main/docs/resources/instance.md Creates a basic Incus instance with a specified name and image. Configuration options like autostart and CPU limits can be set. ```hcl resource "incus_instance" "instance1" { name = "instance1" image = "images:ubuntu/22.04" config = { "boot.autostart" = true "limits.cpu" = 2 } } ``` -------------------------------- ### Run Static Code Analysis Source: https://github.com/lxc/terraform-provider-incus/blob/main/README.md Execute static code analysis and linting using `golangci-lint` and `terraform fmt` by running the `make static-analysis` command. ```shell make static-analysis ``` -------------------------------- ### Configure Terraform to Use Development Binary Source: https://github.com/lxc/terraform-provider-incus/blob/main/README.md Configure Terraform using `~/.terraformrc` to point to a local development binary of the provider. Replace the placeholder path with your actual local path. ```shell $ cat ~/.terraformrc provider_installation { dev_overrides { "lxc/incus" = "/home//git/terraform-provider-incus" } } ``` -------------------------------- ### Data Source: incus_network_peer Source: https://github.com/lxc/terraform-provider-incus/blob/main/docs/data-sources/network_peer.md Use the `incus_network_peer` data source to get information about an existing Incus network peer. This is useful for referencing peer details in your Terraform configuration. ```APIDOC ## Data Source: incus_network_peer Provides information about an Incus network peer. ### Description Use the `incus_network_peer` data source to get information about an existing Incus network peer. This is useful for referencing peer details in your Terraform configuration. ### Example Usage ```hcl data "incus_network_peer" "this" { name = "default" network = "parent" } output "network_peer_name" { value = data.incus_network_peer.this.name } ``` ### Argument Reference * `name` - **Required** - Name of the network peer. * `network` - **Required** - Name of the parent network. * `project` - *Optional* - Name of the project where the network peer is be stored. * `remote` - *Optional* - The remote in which the resource was created. If not provided, the provider's default remote will be used. ### Attribute Reference The following attributes are exported: * `description` - Description of the network peer. * `config` - Map of key/value pairs of config settings. * `status` - Status of the network peer. * `target_project` - Target project for the network peer. * `target_network` - Target network for the network peer. * `target_integration` - Target integration for the network peer. * `type` - Network peer type. ``` -------------------------------- ### Create an Incus instance with multiple network interfaces Source: https://github.com/lxc/terraform-provider-incus/blob/main/docs/resources/network.md Launches an Incus instance 'test1' with two network interfaces. 'eth1' is connected to the custom 'internal' network, and the default network is also available. Includes a local-exec provisioner to run 'dhclient' on 'eth1'. ```hcl resource "incus_instance" "test1" { name = "test1" image = "ubuntu" ephemeral = false profiles = ["default", "${incus_profile.profile1.name}"] provisioner "local-exec" { command = "lxc exec local:${self.name} dhclient eth1" } } ``` -------------------------------- ### Create an Incus Instance Snapshot Source: https://github.com/lxc/terraform-provider-incus/blob/main/docs/resources/instance_snapshot.md Use this resource to create a snapshot of an existing Incus instance. Ensure the `incus_instance` resource is defined first. The snapshot name and the instance name are required. ```hcl resource "incus_instance" "instance" { name = "my-instance" image = "ubuntu" ephemeral = false } resource "incus_instance_snapshot" "snap1" { name = "my-snapshot-1" instance = incus_instance.instance.name } ``` -------------------------------- ### Get Incus Network ACL Information Source: https://github.com/lxc/terraform-provider-incus/blob/main/docs/data-sources/network_acl.md Use this data source to fetch details of an existing Incus network ACL by its name. The 'default' ACL is commonly used. ```hcl data "incus_network_acl" "this" { name = "default" } output "network_acl_name" { value = data.incus_network_acl.this.name } ``` -------------------------------- ### Create Incus Instance from Backup with Storage Source: https://github.com/lxc/terraform-provider-incus/blob/main/docs/resources/instance.md Creates a new Incus instance from a backup file and specifies storage details. A `device` of type `disk` with `path = "/"` and a `pool` name is required to define the storage. ```hcl resource "incus_instance" "instance1" { project = "default" name = "instance1" source_file = "/path/to/backup.tar.gz" device { name = "storage" type = "disk" properties = { path = "/" pool = "pool-name" } } } ``` -------------------------------- ### Get Incus Network Peer Information Source: https://github.com/lxc/terraform-provider-incus/blob/main/docs/data-sources/network_peer.md Use this data source to retrieve details about an existing Incus network peer. Specify the name of the peer and its parent network. ```hcl data "incus_network_peer" "this" { name = "default" network = "parent" } output "network_peer_name" { value = data.incus_network_peer.this.name } ``` -------------------------------- ### Data Source: incus_network_forward Source: https://github.com/lxc/terraform-provider-incus/blob/main/docs/data-sources/network_forward.md Use the `incus_network_forward` data source to get information about an existing Incus network forward. This is useful for referencing network forward details in your Terraform configuration. ```APIDOC ## Data Source: incus_network_forward Provides information about an Incus network forward. See Incus network forward [configuration reference](https://linuxcontainers.org/incus/docs/main/howto/network_forwards/) for more details. ### Example Usage ```hcl data "incus_network_forward" "this" { listen_address = "127.0.0.1" network = "parent" } output "network_forward_listen_address" { value = data.incus_network_forward.this.listen_address } ``` ### Argument Reference * `listen_address` - **Required** - Listen Address of the network forward. * `network` - **Required** - Name of the parent network. * `project` - *Optional* - Name of the project where the network forward is be stored. * `remote` - *Optional* - The remote in which the resource was created. If not provided, the provider's default remote will be used. * `target` - *Optional* - Specify a target node in a cluster. ### Attribute Reference * `description` - Description of the network forward. * `config` - Map of key/value pairs of config settings. * `location` - Location of the network forward. * `ports` - List of ports to forward. The network forward ports supports: * `description` - Description of the forward port. * `protocol` - Protocol for port forward (either tcp or udp). * `listen_port` - ListenPort(s) to forward (comma delimited ranges). * `target_port` - Target port(s) to forward ListenPorts to (allows for many-to-one). * `target_address` - Target address to forward ListenPorts to. * `snat` - SNAT controls whether to apply a matching SNAT rule to new outgoing traffic from the target. ``` -------------------------------- ### Run Unit Tests Source: https://github.com/lxc/terraform-provider-incus/blob/main/README.md Execute the unit test suite for the Terraform provider by running the `make test` command. ```shell make test ``` -------------------------------- ### Get Incus Network Address Set Source: https://github.com/lxc/terraform-provider-incus/blob/main/docs/data-sources/network_address_set.md Use this data source to retrieve information about an Incus network address set by its name. Specify the project if it's not in the default project. ```hcl data "incus_network_address_set" "this" { name = "default" } output "network_address_set_name" { value = data.incus_network_address_set.this.name } ``` -------------------------------- ### Run Acceptance Tests with Default Remote Source: https://github.com/lxc/terraform-provider-incus/blob/main/TESTING.md Execute acceptance tests using the Go test runner. Ensure TF_ACC is set to run acceptance tests. ```bash TF_ACC=1 go test ./... -v ``` -------------------------------- ### Data Source: incus_network_acl Source: https://github.com/lxc/terraform-provider-incus/blob/main/docs/data-sources/network_acl.md Use the `incus_network_acl` data source to get information about an existing Incus network ACL. This is useful for referencing ACL details in other resources or for outputting specific information. ```APIDOC ## Data Source: incus_network_acl Provides information about an Incus network ACL. ### Example Usage ```hcl data "incus_network_acl" "this" { name = "default" } output "network_acl_name" { value = data.incus_network_acl.this.name } ``` ### Argument Reference * `name` - **Required** - Name of the network ACL. * `project` - *Optional* - Name of the project where the network ACL is be stored. * `remote` - *Optional* - The remote in which the resource was created. If not provided, the provider's default remote will be used. ### Attribute Reference * `description` - Description of the network ACL. * `config` - Map of key/value pairs of config settings. * `egress` - List of egress rules. * `action` - Action to perform on rule match. * `source` - Source address. * `destination` - Destination address. * `protocol` - Protocol (e.g., tcp, udp). * `source_port` - Source port. * `destination_port` - Destination port. * `icmp_type` - Type of ICMP message. * `icmp_code` - ICMP message code (for ICMP protocol). * `description` - Description of the rule. * `state` - State of the rule. * `ingress` - List of ingress rules. * `action` - Action to perform on rule match. * `source` - Source address. * `destination` - Destination address. * `protocol` - Protocol (e.g., tcp, udp). * `source_port` - Source port. * `destination_port` - Destination port. * `icmp_type` - Type of ICMP message. * `icmp_code` - ICMP message code (for ICMP protocol). * `description` - Description of the rule. * `state` - State of the rule. ``` -------------------------------- ### Create a basic Incus certificate Source: https://github.com/lxc/terraform-provider-incus/blob/main/docs/resources/certificate.md Use this snippet to create a standard Incus certificate. Ensure the certificate file path is correct. ```hcl resource "incus_certificate" "client1" { name = "client1" certificate = file("${path.module}/metrics.crt") } ``` -------------------------------- ### Run Acceptance Tests Source: https://github.com/lxc/terraform-provider-incus/blob/main/README.md Execute the acceptance test suite, which requires a functional Incus environment. Use `make testacc` to run all tests or specify individual tests with `TESTARGS`. ```shell make testacc ``` ```shell TESTARGS="-run TestAccImage_basicVM" make testacc ``` ```shell TF_LOG=info make testacc ``` -------------------------------- ### Create Incus Instance from Backup File Source: https://github.com/lxc/terraform-provider-incus/blob/main/docs/resources/instance.md Creates a new Incus instance from a backup file. The `source_file` attribute points to the backup archive. ```hcl resource "incus_instance" "instance1" { project = "default" name = "instance1" source_file = "/path/to/backup.tar.gz" } ``` -------------------------------- ### Create an Incus Project Source: https://github.com/lxc/terraform-provider-incus/blob/main/docs/resources/project.md Defines an Incus project resource with a name, description, and custom configuration settings. The configuration can include feature flags for images, profiles, and storage volumes/buckets. ```hcl resource "incus_project" "project" { name = "project1" description = "Terraform provider example project" config = { "features.storage.volumes" = false "features.images" = false "features.profiles" = false "features.storage.buckets" = false } } ``` -------------------------------- ### Run generate-datasources Tool Source: https://github.com/lxc/terraform-provider-incus/blob/main/cmd/generate-datasources/README.md Execute the `generate-datasources` tool to generate Terraform data sources. This command initiates the code generation process based on the configuration file. ```shell go run ./cmd/generate-datasources ``` -------------------------------- ### Import Incus Storage Bucket Key (CLI) Source: https://github.com/lxc/terraform-provider-incus/blob/main/docs/resources/storage_bucket_key.md Imports an existing Incus storage bucket key using the Terraform CLI. The ID format is `[:][]///`. ```shell terraform import incus_storage_bucket_key.key1 proj/pool1/bucket1/key1 ``` -------------------------------- ### Get Incus Network Integration Details Source: https://github.com/lxc/terraform-provider-incus/blob/main/docs/data-sources/network_integration.md Use this data source to fetch information about a specific Incus network integration by its name. Ensure the Incus provider is configured to access the correct remote if not using the default. ```hcl data "incus_network_integration" "this" { name = "default" } output "network_integration_name" { value = data.incus_network_integration.this.name } ``` -------------------------------- ### Wait for IPv4 and IPv6 Network Readiness on Specific Interface Source: https://github.com/lxc/terraform-provider-incus/blob/main/docs/resources/instance.md Configures the instance to wait for both IPv4 and IPv6 networking to be ready on a specific network interface. This ensures complete network connectivity. ```hcl resource "incus_instance" "instance1" { project = "default" name = "instance1" image = "images:debian/12" wait_for { type = "ipv4" nic = "eth0" } wait_for { type = "ipv6" nic = "eth0" } } ``` -------------------------------- ### Create a basic Incus storage bucket Source: https://github.com/lxc/terraform-provider-incus/blob/main/docs/resources/storage_bucket.md Use this snippet to create a new Incus storage bucket within a specified storage pool. Ensure the storage pool is defined first. ```hcl resource "incus_storage_pool" "pool1" { name = "mypool" driver = "zfs" } resource "incus_storage_bucket" "bucket1" { name = "mybucket" pool = incus_storage_pool.pool1.name } ``` -------------------------------- ### Import an Incus Project using Terraform CLI Source: https://github.com/lxc/terraform-provider-incus/blob/main/docs/resources/project.md Demonstrates how to import an existing Incus project into Terraform management using the `terraform import` command. Specify the resource address and the project ID. ```shell terraform import incus_project.myproj proj1 ``` -------------------------------- ### Basic Incus Provider Configuration Source: https://github.com/lxc/terraform-provider-incus/blob/main/docs/index.md This is the minimal configuration required for the Incus provider when Incus remotes are already defined using the `incus` client. ```hcl provider "incus" { } ``` -------------------------------- ### Creating Incus Storage Volume with File Upload Source: https://github.com/lxc/terraform-provider-incus/blob/main/docs/resources/storage_volume.md Creates a storage volume and uploads a file into it. The `file` block specifies the source and target paths, along with permissions. ```hcl resource "incus_storage_pool" "pool1" { name = "mypool" driver = "zfs" } resource "incus_storage_volume" "volume1" { name = "my-config-vol" pool = incus_storage_pool.pool1.name project = "default" file { source_path = "config.conf" target_path = "/etc/app/config.conf" uid = 1000 gid = 1000 mode = "0644" create_directories = true } } ``` -------------------------------- ### Import Incus Network Zone (Terraform CLI) Source: https://github.com/lxc/terraform-provider-incus/blob/main/docs/resources/network_zone.md Use this command to import an existing Incus network zone into Terraform management. Replace `myzone`, `proj`, and `zone1` with your specific resource name, project, and zone name. ```shell terraform import incus_network_zone.myzone proj/zone1 ``` -------------------------------- ### Run Acceptance Tests with Specified Remote Source: https://github.com/lxc/terraform-provider-incus/blob/main/TESTING.md Run acceptance tests and specify a non-default Incus remote by setting the INCUS_REMOTE environment variable. ```bash INCUS_REMOTE=your-remote TF_ACC=1 go test ./... -v ``` -------------------------------- ### Basic Incus Storage Pool Configuration Source: https://github.com/lxc/terraform-provider-incus/blob/main/docs/resources/storage_pool.md Defines a basic Incus storage pool using the 'dir' driver. Ensure the 'source' path is correctly configured for your environment. ```hcl resource "incus_storage_pool" "pool1" { name = "mypool" driver = "dir" config = { source = "/var/lib/incus/storage-pools/mypool" } } ``` -------------------------------- ### Configure Incus Server Logging Source: https://github.com/lxc/terraform-provider-incus/blob/main/docs/resources/server.md Use this snippet to configure logging settings for an Incus server. It demonstrates setting up a Loki target for logs. ```hcl resource "incus_server" "test" { config = { "logging.loki01.target.type" = "loki" "logging.loki01.target.address" = "https://loki01.int. Example.net" "logging.loki01.target.username" = "foo" "logging.loki01.target.password" = "bar" "logging.loki01.types" = "lifecycle,network-acl" "logging.loki01.lifecycle.types" = "instance" } } ``` -------------------------------- ### Wait for IPv4 Network Readiness Source: https://github.com/lxc/terraform-provider-incus/blob/main/docs/resources/instance.md Configures the instance to wait until IPv4 networking is ready. This ensures that the instance has a valid IPv4 address before proceeding. ```hcl resource "incus_instance" "instance1" { project = "default" name = "instance1" image = "images:debian/12" wait_for { type = "ipv4" } } ``` -------------------------------- ### Importing Incus Storage Pool (Terraform v1.5.0+) Source: https://github.com/lxc/terraform-provider-incus/blob/main/docs/resources/storage_pool.md Demonstrates importing an Incus storage pool using the `import` block, available in Terraform v1.5.0 and later. This method allows defining the import within your Terraform configuration. ```hcl resource "incus_storage_pool" "mypool" { name = "pool1" project = "proj" driver = "zfs" } import { to = incus_storage_pool.mypool id = "proj/pool1" } ``` -------------------------------- ### Import Incus Network Zone (Terraform Import Block) Source: https://github.com/lxc/terraform-provider-incus/blob/main/docs/resources/network_zone.md This HCL block demonstrates how to import an Incus network zone using Terraform's import block syntax, available in Terraform v1.5.0 and later. Ensure the `name` and `project` arguments match the zone you are importing. ```hcl resource "incus_network_zone" "myzone" { name = "zone1" project = "proj" } import { to = incus_network_zone.myzone id = "proj/zone1" } ``` -------------------------------- ### Create Incus Storage Bucket Key Source: https://github.com/lxc/terraform-provider-incus/blob/main/docs/resources/storage_bucket_key.md Defines a new Incus storage bucket key. Ensure the associated storage pool and bucket resources are defined. ```hcl resource "incus_storage_pool" "pool1" { name = "mypool" driver = "zfs" } resource "incus_storage_bucket" "bucket1" { name = "mybucket" pool = incus_storage_pool.pool1.name } resource "incus_storage_bucket_key" "key1" { name = "mykey" pool = incus_storage_bucket.bucket1.pool storage_bucket = incus_storage_bucket.bucket1.name } ``` -------------------------------- ### Create Incus Instance from Existing Instance Source: https://github.com/lxc/terraform-provider-incus/blob/main/docs/resources/instance.md Creates a new Incus instance by cloning an existing one. This is useful for creating identical environments quickly. Both source and target instances can be specified with their projects. ```hcl resource "incus_instance" "instance1" { project = "default" name = "instance1" image = "images:debian/12" } resource "incus_instance" "instance2" { project = "default" name = "instance2" source_instance = { project = "default" name = "instance1" } } ``` -------------------------------- ### Creating Incus Storage Volume from Backup File Source: https://github.com/lxc/terraform-provider-incus/blob/main/docs/resources/storage_volume.md Restores a storage volume from a backup file. The `source_file` argument points to the backup archive. ```hcl resource "incus_storage_volume" "volume_from_backup" { name = "restored-volume" pool = "default" source_file = "/path/to/volume.backup" } ``` -------------------------------- ### Basic Network Address Set Creation Source: https://github.com/lxc/terraform-provider-incus/blob/main/docs/resources/network_address_set.md Defines a basic network address set with a name, description, and a list of IP addresses. This is useful for simple IP grouping. ```hcl resource "incus_network_address_set" "this" { name = "Network Address Set" description = "Network Address Set description" addresses = ["10.0.0.2", "10.0.0.3"] } ``` -------------------------------- ### Basic Incus Storage Volume Creation Source: https://github.com/lxc/terraform-provider-incus/blob/main/docs/resources/storage_volume.md Defines a basic Incus storage volume resource. Ensure the storage pool is defined first. ```hcl resource "incus_storage_pool" "pool1" { name = "mypool" driver = "zfs" } resource "incus_storage_volume" "volume1" { name = "myvolume" pool = incus_storage_pool.pool1.name } ``` -------------------------------- ### Wait for IPv6 Network Readiness on Specific Interface Source: https://github.com/lxc/terraform-provider-incus/blob/main/docs/resources/instance.md Configures the instance to wait until IPv6 networking is ready on a specified network interface. The `nic` attribute identifies the network interface. ```hcl resource "incus_instance" "instance1" { project = "default" name = "instance1" image = "images:debian/12" wait_for { type = "ipv6" nic = "eth0" } } ``` -------------------------------- ### Configure VSCode for Local Tests Source: https://github.com/lxc/terraform-provider-incus/blob/main/TESTING.md Add this JSON configuration to your VSCode settings.json file to set test timeouts and environment variables for acceptance tests. ```json { "go.testTimeout": "300s", "go.testEnvVars": { "TF_ACC": "1" } } ``` -------------------------------- ### Import Incus Instance with Terraform Import Block Source: https://github.com/lxc/terraform-provider-incus/blob/main/docs/resources/instance.md Demonstrates importing an Incus instance using the import block, available in Terraform v1.5.0 and later. This method requires defining the resource block first. ```hcl resource "incus_instance" "myinst" { name = "c1" project = "proj" image = "images:alpine/edge/amd64" } import { to = incus_instance.myinst id = "proj/c1,image=images:alpine/edge/amd64" } ```