» 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:

» Example Usage - Os Config Guest Policies Basic

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

resource "google_compute_instance" "foobar" {
  provider = google-beta
  name           = "guest-policy-inst"
  machine_type   = "n1-standard-1"
  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"
  }
}

» 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"]
    }
  }
}

» 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:

  • assignment - (Required) Specifies the VM instances that are assigned to this policy. This allows you to target sets or groups of VM instances by different parameters such as labels, names, OS, or zones. If left empty, all VM instances underneath this policy are targeted. At the same level in the resource hierarchy (that is within a project), the service prevents the creation of multiple policies that conflict with each other. For more information, see how the service handles assignment conflicts. Structure is documented below.

  • guest_policy_id - (Required) The logical name of the guest policy in the project with the following restrictions:

    • Must contain only lowercase letters, numbers, and hyphens.
    • Must start with a letter.
    • Must be between 1-63 characters.
    • Must end with a number or a letter.
    • Must be unique within the project.

The assignment block supports:

  • group_labels - (Optional) Targets instances matching at least one of these label sets. This allows an assignment to target disparate groups, for example "env=prod or env=staging". Structure is documented below.

  • zones - (Optional) Targets instances in any of these zones. Leave empty to target instances in any zone. Zonal targeting is uncommon and is supported to facilitate the management of changes by zone.

  • instances - (Optional) Targets any of the instances specified. Instances are specified by their URI in the form zones/[ZONE]/instances/[INSTANCE_NAME]. Instance targeting is uncommon and is supported to facilitate the management of changes by the instance or to target specific VM instances for development and testing. Only supported for project-level policies and must reference instances within this project.

  • instance_name_prefixes - (Optional) Targets VM instances whose name starts with one of these prefixes. Like labels, this is another way to group VM instances when targeting configs, for example prefix="prod-". Only supported for project-level policies.

  • os_types - (Optional) Targets VM instances matching at least one of the following OS types. VM instances must match all supplied criteria for a given OsType to be included. Structure is documented below.

The group_labels block supports:

  • labels - (Required) Google Compute Engine instance labels that must be present for an instance to be included in this assignment group.

The os_types block supports:

  • os_short_name - (Optional) Targets VM instances with OS Inventory enabled and having the following OS short name, for example "debian" or "windows".

  • os_version - (Optional) Targets VM instances with OS Inventory enabled and having the following following OS version.

  • os_architecture - (Optional) Targets VM instances with OS Inventory enabled and having the following OS architecture.


  • description - (Optional) Description of the guest policy. Length of the description is limited to 1024 characters.

  • packages - (Optional) The software packages to be managed by this policy. Structure is documented below.

  • package_repositories - (Optional) A list of package repositories to configure on the VM instance. This is done before any other configs are applied so they can use these repos. Package repositories are only configured if the corresponding package manager(s) are available. Structure is documented below.

  • recipes - (Optional) A list of Recipes to install on the VM instance. Structure is documented below.

  • etag - (Optional) The etag for this guest policy. If this is provided on update, it must match the server's etag.

  • project - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used.

The packages block supports:

  • name - (Required) The name of the package. A package is uniquely identified for conflict validation by checking the package name and the manager(s) that the package targets.

  • desired_state - (Optional) The desiredState the agent should maintain for this package. The default is to ensure the package is installed. Possible values are INSTALLED, UPDATED, and REMOVED.

  • manager - (Optional) Type of package manager that can be used to install this package. If a system does not have the package manager, the package is not installed or removed no error message is returned. By default, or if you specify ANY, the agent attempts to install and remove this package using the default package manager. This is useful when creating a policy that applies to different types of systems. The default behavior is ANY. Default value is ANY. Possible values are ANY, APT, YUM, ZYPPER, and GOO.

The package_repositories block supports:

  • apt - (Optional) An Apt Repository. Structure is documented below.

  • yum - (Optional) A Yum Repository. Structure is documented below.

  • zypper - (Optional) A Zypper Repository. Structure is documented below.

  • goo - (Optional) A Goo Repository. Structure is documented below.

The apt block supports:

  • archive_type - (Optional) Type of archive files in this repository. The default behavior is DEB. Default value is DEB. Possible values are DEB and DEB_SRC.

  • uri - (Required) URI for this repository.

  • distribution - (Required) Distribution of this repository.

  • components - (Required) List of components for this repository. Must contain at least one item.

  • gpg_key - (Optional) URI of the key file for this repository. The agent maintains a keyring at /etc/apt/trusted.gpg.d/osconfig_agent_managed.gpg containing all the keys in any applied guest policy.

The yum block supports:

  • id - (Required) A one word, unique name for this repository. This is the repo id in the Yum config file and also the displayName if displayName is omitted. This id is also used as the unique identifier when checking for guest policy conflicts.

  • display_name - (Optional) The display name of the repository.

  • base_url - (Required) The location of the repository directory.

  • gpg_keys - (Optional) URIs of GPG keys.

The zypper block supports:

  • id - (Required) A one word, unique name for this repository. This is the repo id in the zypper config file and also the displayName if displayName is omitted. This id is also used as the unique identifier when checking for guest policy conflicts.

  • display_name - (Optional) The display name of the repository.

  • base_url - (Required) The location of the repository directory.

  • gpg_keys - (Optional) URIs of GPG keys.

The goo block supports:

  • name - (Required) The name of the repository.

  • url - (Required) The url of the repository.

The recipes block supports:

  • name - (Required) Unique identifier for the recipe. Only one recipe with a given name is installed on an instance. Names are also used to identify resources which helps to determine whether guest policies have conflicts. This means that requests to create multiple recipes with the same name and version are rejected since they could potentially have conflicting assignments.

  • version - (Optional) The version of this software recipe. Version can be up to 4 period separated numbers (e.g. 12.34.56.78).

  • artifacts - (Optional) Resources available to be used in the steps in the recipe. Structure is documented below.

  • install_steps - (Optional) Actions to be taken for installing this recipe. On failure it stops executing steps and does not attempt another installation. Any steps taken (including partially completed steps) are not rolled back. Structure is documented below.

  • update_steps - (Optional) Actions to be taken for updating this recipe. On failure it stops executing steps and does not attempt another update for this recipe. Any steps taken (including partially completed steps) are not rolled back. Structure is documented below.

  • desired_state - (Optional) Default is INSTALLED. The desired state the agent should maintain for this recipe. INSTALLED: The software recipe is installed on the instance but won't be updated to new versions. INSTALLED_KEEP_UPDATED: The software recipe is installed on the instance. The recipe is updated to a higher version, if a higher version of the recipe is assigned to this instance. REMOVE: Remove is unsupported for software recipes and attempts to create or update a recipe to the REMOVE state is rejected. Default value is INSTALLED. Possible values are INSTALLED, UPDATED, and REMOVED.

The artifacts block supports:

  • id - (Required) Id of the artifact, which the installation and update steps of this recipe can reference. Artifacts in a recipe cannot have the same id.

  • allow_insecure - (Optional) Defaults to false. When false, recipes are subject to validations based on the artifact type: Remote: A checksum must be specified, and only protocols with transport-layer security are permitted. GCS: An object generation number must be specified.

  • remote - (Optional) A generic remote artifact. Structure is documented below.

  • gcs - (Optional) A Google Cloud Storage artifact. Structure is documented below.

The remote block supports:

  • uri - (Optional) URI from which to fetch the object. It should contain both the protocol and path following the format {protocol}://{location}.

  • check_sum - (Optional) Must be provided if allowInsecure is false. SHA256 checksum in hex format, to compare to the checksum of the artifact. If the checksum is not empty and it doesn't match the artifact then the recipe installation fails before running any of the steps.

The gcs block supports:

The install_steps block supports:

  • file_copy - (Optional) Copies a file onto the instance. Structure is documented below.

  • archive_extraction - (Optional) Extracts an archive into the specified directory. Structure is documented below.

  • msi_installation - (Optional) Installs an MSI file. Structure is documented below.

  • dpkg_installation - (Optional) Installs a deb file via dpkg. Structure is documented below.

  • rpm_installation - (Optional) Installs an rpm file via the rpm utility. Structure is documented below.

  • file_exec - (Optional) Executes an artifact or local file. Structure is documented below.

  • script_run - (Optional) Runs commands in a shell. Structure is documented below.

The file_copy block supports:

  • artifact_id - (Required) The id of the relevant artifact in the recipe.

  • destination - (Required) The absolute path on the instance to put the file.

  • overwrite - (Optional) Whether to allow this step to overwrite existing files.If this is false and the file already exists the file is not overwritten and the step is considered a success. Defaults to false.

  • permissions - (Optional) Consists of three octal digits which represent, in order, the permissions of the owner, group, and other users for the file (similarly to the numeric mode used in the linux chmod utility). Each digit represents a three bit number with the 4 bit corresponding to the read permissions, the 2 bit corresponds to the write bit, and the one bit corresponds to the execute permission. Default behavior is 755. Below are some examples of permissions and their associated values: read, write, and execute: 7 read and execute: 5 read and write: 6 read only: 4

The archive_extraction block supports:

  • artifact_id - (Required) The id of the relevant artifact in the recipe.

  • destination - (Optional) Directory to extract archive to. Defaults to / on Linux or C:\ on Windows.

  • type - (Required) The type of the archive to extract. Possible values are TAR, TAR_GZIP, TAR_BZIP, TAR_LZMA, TAR_XZ, and ZIP.

The msi_installation block supports:

  • artifact_id - (Required) The id of the relevant artifact in the recipe.

  • flags - (Optional) The flags to use when installing the MSI. Defaults to the install flag.

  • allowed_exit_codes - (Optional) Return codes that indicate that the software installed or updated successfully. Behaviour defaults to [0]

The dpkg_installation block supports:

  • artifact_id - (Required) The id of the relevant artifact in the recipe.

The rpm_installation block supports:

  • artifact_id - (Required) The id of the relevant artifact in the recipe.

The file_exec block supports:

  • args - (Optional) Arguments to be passed to the provided executable.

  • allowed_exit_codes - (Optional) A list of possible return values that the program can return to indicate a success. Defaults to [0].

  • artifact_id - (Optional) The id of the relevant artifact in the recipe.

  • local_path - (Optional) The absolute path of the file on the local filesystem.

The script_run block supports:

  • script - (Required) The shell script to be executed.

  • allowed_exit_codes - (Optional) Return codes that indicate that the software installed or updated successfully. Behaviour defaults to [0]

  • interpreter - (Optional) The script interpreter to use to run the script. If no interpreter is specified the script is executed directly, which likely only succeed for scripts with shebang lines. Possible values are SHELL and POWERSHELL.

The update_steps block supports:

  • file_copy - (Optional) Copies a file onto the instance. Structure is documented below.

  • archive_extraction - (Optional) Extracts an archive into the specified directory. Structure is documented below.

  • msi_installation - (Optional) Installs an MSI file. Structure is documented below.

  • dpkg_installation - (Optional) Installs a deb file via dpkg. Structure is documented below.

  • rpm_installation - (Optional) Installs an rpm file via the rpm utility. Structure is documented below.

  • file_exec - (Optional) Executes an artifact or local file. Structure is documented below.

  • script_run - (Optional) Runs commands in a shell. Structure is documented below.

The file_copy block supports:

  • artifact_id - (Required) The id of the relevant artifact in the recipe.

  • destination - (Required) The absolute path on the instance to put the file.

  • overwrite - (Optional) Whether to allow this step to overwrite existing files.If this is false and the file already exists the file is not overwritten and the step is considered a success. Defaults to false.

  • permissions - (Optional) Consists of three octal digits which represent, in order, the permissions of the owner, group, and other users for the file (similarly to the numeric mode used in the linux chmod utility). Each digit represents a three bit number with the 4 bit corresponding to the read permissions, the 2 bit corresponds to the write bit, and the one bit corresponds to the execute permission. Default behavior is 755. Below are some examples of permissions and their associated values: read, write, and execute: 7 read and execute: 5 read and write: 6 read only: 4

The archive_extraction block supports:

  • artifact_id - (Required) The id of the relevant artifact in the recipe.

  • destination - (Optional) Directory to extract archive to. Defaults to / on Linux or C:\ on Windows.

  • type - (Required) The type of the archive to extract. Possible values are TAR, TAR_GZIP, TAR_BZIP, TAR_LZMA, TAR_XZ, and ZIP.

The msi_installation block supports:

  • artifact_id - (Required) The id of the relevant artifact in the recipe.

  • flags - (Optional) The flags to use when installing the MSI. Defaults to the install flag.

  • allowed_exit_codes - (Optional) Return codes that indicate that the software installed or updated successfully. Behaviour defaults to [0]

The dpkg_installation block supports:

  • artifact_id - (Required) The id of the relevant artifact in the recipe.

The rpm_installation block supports:

  • artifact_id - (Required) The id of the relevant artifact in the recipe.

The file_exec block supports:

  • args - (Optional) Arguments to be passed to the provided executable.

  • allowed_exit_codes - (Optional) A list of possible return values that the program can return to indicate a success. Defaults to [0].

  • artifact_id - (Optional) The id of the relevant artifact in the recipe.

  • local_path - (Optional) The absolute path of the file on the local filesystem.

The script_run block supports:

  • script - (Required) The shell script to be executed.

  • allowed_exit_codes - (Optional) Return codes that indicate that the software installed or updated successfully. Behaviour defaults to [0]

  • interpreter - (Optional) The script interpreter to use to run the script. If no interpreter is specified the script is executed directly, which likely only succeed for scripts with shebang lines. Possible values are SHELL and POWERSHELL.

» Attributes Reference

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

  • id - an identifier for the resource with format {{name}}

  • name - Unique name of the resource in this project using one of the following forms: projects/{project_number}/guestPolicies/{guestPolicyId}.

  • create_time - Time this guest policy was created. A timestamp in RFC3339 UTC "Zulu" format, accurate to nanoseconds. Example: "2014-10-02T15:01:23.045123456Z".

  • update_time - Last time this guest policy was updated. A timestamp in RFC3339 UTC "Zulu" format, accurate to nanoseconds. Example: "2014-10-02T15:01:23.045123456Z".

» Timeouts

This resource provides the following Timeouts configuration options:

  • create - Default is 4 minutes.
  • update - Default is 4 minutes.
  • delete - Default is 4 minutes.

» Import

GuestPolicies can be imported using any of these accepted formats:

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

» User Project Overrides

This resource supports User Project Overrides.