google_os_config_guest_policies

An OS Config resource representing a guest configuration policy. These policies represent the desired state for VM instance guest environments including packages to install or remove, package repository configurations, and software to install.

To get more information about GuestPolicies, see:

Open in Cloud Shell

Example Usage - Os Config Guest Policies Basic

data "google_compute_image" "my_image" {
  provider = google-beta
  family  = "debian-11"
  project = "debian-cloud"
}

resource "google_compute_instance" "foobar" {
  provider = google-beta
  name           = "guest-policy-inst"
  machine_type   = "e2-medium"
  zone           = "us-central1-a"
  can_ip_forward = false
  tags           = ["foo", "bar"]

  boot_disk {
    initialize_params {
      image = data.google_compute_image.my_image.self_link
    }
  }

  network_interface {
    network = "default"
  }

  metadata = {
    foo = "bar"
  }
}

resource "google_os_config_guest_policies" "guest_policies" {
  provider = google-beta
  guest_policy_id = "guest-policy"

  assignment {
    instances = [google_compute_instance.foobar.id]
  }

  packages {
    name = "my-package"
    desired_state = "UPDATED"
  }
}
Open in Cloud Shell

Example Usage - Os Config Guest Policies Packages

resource "google_os_config_guest_policies" "guest_policies" {
  provider = google-beta
  guest_policy_id = "guest-policy"

  assignment {
    group_labels {
      labels = {
        color = "red",
        env = "test"
      }
    }

    group_labels {
      labels = {
        color = "blue",
        env = "test"
      }
    }
  }

  packages {
    name          = "my-package"
    desired_state = "INSTALLED"
  }

  packages {
    name          = "bad-package-1"
    desired_state = "REMOVED"
  }

  packages {
    name          = "bad-package-2"
    desired_state = "REMOVED"
    manager       = "APT"
  }

  package_repositories {
    apt {
      uri          = "https://packages.cloud.google.com/apt"
      archive_type = "DEB"
      distribution = "cloud-sdk-stretch"
      components   = ["main"]
    }
  }

  package_repositories {
    yum {
      id           = "google-cloud-sdk"
      display_name = "Google Cloud SDK"
      base_url     = "https://packages.cloud.google.com/yum/repos/cloud-sdk-el7-x86_64"
      gpg_keys     = ["https://packages.cloud.google.com/yum/doc/yum-key.gpg", "https://packages.cloud.google.com/yum/doc/rpm-package-key.gpg"]
    }
  }
}
Open in Cloud Shell

Example Usage - Os Config Guest Policies Recipes

resource "google_os_config_guest_policies" "guest_policies" {
  provider = google-beta
  guest_policy_id = "guest-policy"

  assignment {
    zones = ["us-east1-b", "us-east1-d"]
  }

  recipes {
    name          = "guest-policy-recipe"
    desired_state = "INSTALLED"

    artifacts {
      id = "guest-policy-artifact-id"

      gcs {
        bucket     = "my-bucket"
        object     = "executable.msi"
        generation = 1546030865175603
      }
    }

    install_steps {
      msi_installation {
        artifact_id = "guest-policy-artifact-id"
      }
    }
  }
}

Argument Reference

The following arguments are supported:

The assignment block supports:

The group_labels block supports:

The os_types block supports:


The packages block supports:

The package_repositories block supports:

The apt block supports:

The yum block supports:

The zypper block supports:

The goo block supports:

The recipes block supports:

The artifacts block supports:

The remote block supports:

The gcs block supports:

The install_steps block supports:

The file_copy block supports:

The archive_extraction block supports:

The msi_installation block supports:

The dpkg_installation block supports:

The rpm_installation block supports:

The file_exec block supports:

The script_run block supports:

The update_steps block supports:

The file_copy block supports:

The archive_extraction block supports:

The msi_installation block supports:

The dpkg_installation block supports:

The rpm_installation block supports:

The file_exec block supports:

The script_run block supports:

Attributes Reference

In addition to the arguments listed above, the following computed attributes are exported:

Timeouts

This resource provides the following Timeouts configuration options:

Import

GuestPolicies can be imported using any of these accepted formats:

In Terraform v1.5.0 and later, use an import block to import GuestPolicies using one of the formats above. For example:

import {
  id = "projects/{{project}}/guestPolicies/{{guest_policy_id}}"
  to = google_os_config_guest_policies.default
}

When using the terraform import command, GuestPolicies can be imported using one of the formats above. For example:

$ terraform import google_os_config_guest_policies.default projects/{{project}}/guestPolicies/{{guest_policy_id}}
$ terraform import google_os_config_guest_policies.default {{project}}/{{guest_policy_id}}
$ terraform import google_os_config_guest_policies.default {{guest_policy_id}}

User Project Overrides

This resource supports User Project Overrides.