|  | --- | 
|  | # ---------------------------------------------------------------------------- | 
|  | # | 
|  | #     ***     AUTO GENERATED CODE    ***    Type: MMv1     *** | 
|  | # | 
|  | # ---------------------------------------------------------------------------- | 
|  | # | 
|  | #     This file is automatically generated by Magic Modules and manual | 
|  | #     changes will be clobbered when the file is regenerated. | 
|  | # | 
|  | #     Please read more about how to change this file in | 
|  | #     .github/CONTRIBUTING.md. | 
|  | # | 
|  | # ---------------------------------------------------------------------------- | 
|  | subcategory: "App Hub" | 
|  | description: |- | 
|  | Workload represents a binary deployment (such as Managed Instance Groups (MIGs), GKE deployments, etc. | 
|  | --- | 
|  |  | 
|  | # google_apphub_workload | 
|  |  | 
|  | Workload represents a binary deployment (such as Managed Instance Groups (MIGs), GKE deployments, etc.) that performs the smallest logical subset of business functionality. It registers identified workload to the Application. | 
|  |  | 
|  |  | 
|  |  | 
|  | ## Example Usage - Apphub Workload Basic | 
|  |  | 
|  |  | 
|  | ```hcl | 
|  | resource "google_apphub_application" "application" { | 
|  | location = "us-central1" | 
|  | application_id = "example-application-1" | 
|  | scope { | 
|  | type = "REGIONAL" | 
|  | } | 
|  | } | 
|  |  | 
|  | resource "google_project" "service_project" { | 
|  | project_id ="project-1" | 
|  | name = "Service Project" | 
|  | org_id = "123456789" | 
|  | billing_account = "000000-0000000-0000000-000000" | 
|  | deletion_policy = "DELETE" | 
|  | } | 
|  |  | 
|  | # Enable Compute API | 
|  | resource "google_project_service" "compute_service_project" { | 
|  | project = google_project.service_project.project_id | 
|  | service = "compute.googleapis.com" | 
|  | } | 
|  |  | 
|  | resource "time_sleep" "wait_120s" { | 
|  | depends_on = [google_project_service.compute_service_project] | 
|  |  | 
|  | create_duration = "120s" | 
|  | } | 
|  |  | 
|  | resource "google_apphub_service_project_attachment" "service_project_attachment" { | 
|  | service_project_attachment_id = google_project.service_project.project_id | 
|  | depends_on = [time_sleep.wait_120s] | 
|  | } | 
|  |  | 
|  |  | 
|  | # Discovered workload | 
|  | data "google_apphub_discovered_workload" "catalog-workload" { | 
|  | location = "us-central1" | 
|  | workload_uri = "${replace(google_compute_region_instance_group_manager.mig.instance_group, "https://www.googleapis.com/compute/v1", "//compute.googleapis.com")}" | 
|  | depends_on = [time_sleep.wait_120s_for_resource_ingestion] | 
|  | } | 
|  |  | 
|  | resource "time_sleep" "wait_120s_for_resource_ingestion" { | 
|  | depends_on = [google_compute_region_instance_group_manager.mig] | 
|  | create_duration = "120s" | 
|  | } | 
|  |  | 
|  | resource "google_apphub_workload" "example" { | 
|  | location = "us-central1" | 
|  | application_id = google_apphub_application.application.application_id | 
|  | workload_id = google_compute_region_instance_group_manager.mig.name | 
|  | discovered_workload = data.google_apphub_discovered_workload.catalog-workload.name | 
|  | } | 
|  |  | 
|  | #Workload creation | 
|  |  | 
|  |  | 
|  | # VPC network | 
|  | resource "google_compute_network" "ilb_network" { | 
|  | name                    = "l7-ilb-network" | 
|  | project                 = google_project.service_project.project_id | 
|  | auto_create_subnetworks = false | 
|  | depends_on = [time_sleep.wait_120s] | 
|  | } | 
|  |  | 
|  | # backend subnet | 
|  | resource "google_compute_subnetwork" "ilb_subnet" { | 
|  | name          = "l7-ilb-subnet" | 
|  | project       = google_project.service_project.project_id | 
|  | ip_cidr_range = "10.0.1.0/24" | 
|  | region        = "us-central1" | 
|  | network       = google_compute_network.ilb_network.id | 
|  | } | 
|  |  | 
|  | # instance template | 
|  | resource "google_compute_instance_template" "instance_template" { | 
|  | name         = "l7-ilb-mig-template" | 
|  | project      = google_project.service_project.project_id | 
|  | machine_type = "e2-small" | 
|  | tags         = ["http-server"] | 
|  | network_interface { | 
|  | network    = google_compute_network.ilb_network.id | 
|  | subnetwork = google_compute_subnetwork.ilb_subnet.id | 
|  | access_config { | 
|  | # add external ip to fetch packages | 
|  | } | 
|  | } | 
|  | disk { | 
|  | source_image = "debian-cloud/debian-12" | 
|  | auto_delete  = true | 
|  | boot         = true | 
|  | } | 
|  | # install nginx and serve a simple web page | 
|  | metadata = { | 
|  | startup-script = <<-EOF1 | 
|  | #! /bin/bash | 
|  | set -euo pipefail | 
|  | export DEBIAN_FRONTEND=noninteractive | 
|  | apt-get update | 
|  | apt-get install -y nginx-light jq | 
|  | NAME=$(curl -H "Metadata-Flavor: Google" "http://metadata.google.internal/computeMetadata/v1/instance/hostname") | 
|  | IP=$(curl -H "Metadata-Flavor: Google" "http://metadata.google.internal/computeMetadata/v1/instance/network-interfaces/0/ip") | 
|  | METADATA=$(curl -f -H "Metadata-Flavor: Google" "http://metadata.google.internal/computeMetadata/v1/instance/attributes/?recursive=True" | jq 'del(.["startup-script"])') | 
|  | cat <<EOF > /var/www/html/index.html | 
|  | <pre> | 
|  | Name: $NAME | 
|  | IP: $IP | 
|  | Metadata: $METADATA | 
|  | </pre> | 
|  | EOF | 
|  | EOF1 | 
|  | } | 
|  | lifecycle { | 
|  | create_before_destroy = true | 
|  | } | 
|  | } | 
|  |  | 
|  | resource "google_compute_region_instance_group_manager" "mig" { | 
|  | name     = "l7-ilb-mig1" | 
|  | project  = google_project.service_project.project_id | 
|  | region   = "us-central1" | 
|  | version { | 
|  | instance_template = google_compute_instance_template.instance_template.id | 
|  | name              = "primary" | 
|  | } | 
|  | base_instance_name = "vm" | 
|  | target_size        = 2 | 
|  | } | 
|  | ``` | 
|  | ## Example Usage - Apphub Workload Full | 
|  |  | 
|  |  | 
|  | ```hcl | 
|  | resource "google_apphub_application" "application" { | 
|  | location = "us-central1" | 
|  | application_id = "example-application-1" | 
|  | scope { | 
|  | type = "REGIONAL" | 
|  | } | 
|  | } | 
|  |  | 
|  | resource "google_project" "service_project" { | 
|  | project_id ="project-1" | 
|  | name = "Service Project" | 
|  | org_id = "123456789" | 
|  | billing_account = "000000-0000000-0000000-000000" | 
|  | deletion_policy = "DELETE" | 
|  | } | 
|  |  | 
|  | # Enable Compute API | 
|  | resource "google_project_service" "compute_service_project" { | 
|  | project = google_project.service_project.project_id | 
|  | service = "compute.googleapis.com" | 
|  | } | 
|  |  | 
|  | resource "time_sleep" "wait_120s" { | 
|  | depends_on = [google_project_service.compute_service_project] | 
|  |  | 
|  | create_duration = "120s" | 
|  | } | 
|  |  | 
|  | resource "google_apphub_service_project_attachment" "service_project_attachment" { | 
|  | service_project_attachment_id = google_project.service_project.project_id | 
|  | depends_on = [time_sleep.wait_120s] | 
|  | } | 
|  |  | 
|  | # Discovered workload | 
|  | data "google_apphub_discovered_workload" "catalog-workload" { | 
|  | location = "us-central1" | 
|  | workload_uri = "${replace(google_compute_region_instance_group_manager.mig.instance_group, "https://www.googleapis.com/compute/v1", "//compute.googleapis.com")}" | 
|  | depends_on = [time_sleep.wait_120s_for_resource_ingestion] | 
|  | } | 
|  |  | 
|  | resource "time_sleep" "wait_120s_for_resource_ingestion" { | 
|  | depends_on = [google_compute_region_instance_group_manager.mig] | 
|  | create_duration = "120s" | 
|  | } | 
|  |  | 
|  | resource "google_apphub_workload" "example" { | 
|  | location = "us-central1" | 
|  | application_id = google_apphub_application.application.application_id | 
|  | workload_id = google_compute_region_instance_group_manager.mig.name | 
|  | discovered_workload = data.google_apphub_discovered_workload.catalog-workload.name | 
|  | display_name = "Example Service Full" | 
|  | description = "Register service for testing" | 
|  | attributes { | 
|  | environment { | 
|  | type = "STAGING" | 
|  | } | 
|  | criticality { | 
|  | type = "MISSION_CRITICAL" | 
|  | } | 
|  | business_owners { | 
|  | display_name =  "Alice" | 
|  | email        =  "alice@google.com" | 
|  | } | 
|  | developer_owners { | 
|  | display_name =  "Bob" | 
|  | email        =  "bob@google.com" | 
|  | } | 
|  | operator_owners { | 
|  | display_name =  "Charlie" | 
|  | email        =  "charlie@google.com" | 
|  | } | 
|  | } | 
|  | } | 
|  |  | 
|  | #Workload creation | 
|  |  | 
|  |  | 
|  | # VPC network | 
|  | resource "google_compute_network" "ilb_network" { | 
|  | name                    = "l7-ilb-network" | 
|  | project                 = google_project.service_project.project_id | 
|  | auto_create_subnetworks = false | 
|  | depends_on = [time_sleep.wait_120s] | 
|  | } | 
|  |  | 
|  | # backend subnet | 
|  | resource "google_compute_subnetwork" "ilb_subnet" { | 
|  | name          = "l7-ilb-subnet" | 
|  | project       = google_project.service_project.project_id | 
|  | ip_cidr_range = "10.0.1.0/24" | 
|  | region        = "us-central1" | 
|  | network       = google_compute_network.ilb_network.id | 
|  | } | 
|  |  | 
|  | # instance template | 
|  | resource "google_compute_instance_template" "instance_template" { | 
|  | name         = "l7-ilb-mig-template" | 
|  | project      = google_project.service_project.project_id | 
|  | machine_type = "e2-small" | 
|  | tags         = ["http-server"] | 
|  | network_interface { | 
|  | network    = google_compute_network.ilb_network.id | 
|  | subnetwork = google_compute_subnetwork.ilb_subnet.id | 
|  | access_config { | 
|  | # add external ip to fetch packages | 
|  | } | 
|  | } | 
|  | disk { | 
|  | source_image = "debian-cloud/debian-12" | 
|  | auto_delete  = true | 
|  | boot         = true | 
|  | } | 
|  | # install nginx and serve a simple web page | 
|  | metadata = { | 
|  | startup-script = <<-EOF1 | 
|  | #! /bin/bash | 
|  | set -euo pipefail | 
|  | export DEBIAN_FRONTEND=noninteractive | 
|  | apt-get update | 
|  | apt-get install -y nginx-light jq | 
|  | NAME=$(curl -H "Metadata-Flavor: Google" "http://metadata.google.internal/computeMetadata/v1/instance/hostname") | 
|  | IP=$(curl -H "Metadata-Flavor: Google" "http://metadata.google.internal/computeMetadata/v1/instance/network-interfaces/0/ip") | 
|  | METADATA=$(curl -f -H "Metadata-Flavor: Google" "http://metadata.google.internal/computeMetadata/v1/instance/attributes/?recursive=True" | jq 'del(.["startup-script"])') | 
|  | cat <<EOF > /var/www/html/index.html | 
|  | <pre> | 
|  | Name: $NAME | 
|  | IP: $IP | 
|  | Metadata: $METADATA | 
|  | </pre> | 
|  | EOF | 
|  | EOF1 | 
|  | } | 
|  | lifecycle { | 
|  | create_before_destroy = true | 
|  | } | 
|  | } | 
|  |  | 
|  | resource "google_compute_region_instance_group_manager" "mig" { | 
|  | name     = "l7-ilb-mig1" | 
|  | project  = google_project.service_project.project_id | 
|  | region   = "us-central1" | 
|  | version { | 
|  | instance_template = google_compute_instance_template.instance_template.id | 
|  | name              = "primary" | 
|  | } | 
|  | base_instance_name = "vm" | 
|  | target_size        = 2 | 
|  | } | 
|  | ``` | 
|  |  | 
|  | ## Argument Reference | 
|  |  | 
|  | The following arguments are supported: | 
|  |  | 
|  |  | 
|  | * `discovered_workload` - | 
|  | (Required) | 
|  | Immutable. The resource name of the original discovered workload. | 
|  |  | 
|  | * `location` - | 
|  | (Required) | 
|  | Part of `parent`.  Full resource name of a parent Application. Example: projects/{HOST_PROJECT_ID}/locations/{LOCATION}/applications/{APPLICATION_ID} | 
|  |  | 
|  | * `application_id` - | 
|  | (Required) | 
|  | Part of `parent`.  Full resource name of a parent Application. Example: projects/{HOST_PROJECT_ID}/locations/{LOCATION}/applications/{APPLICATION_ID} | 
|  |  | 
|  | * `workload_id` - | 
|  | (Required) | 
|  | The Workload identifier. | 
|  |  | 
|  |  | 
|  | - - - | 
|  |  | 
|  |  | 
|  | * `display_name` - | 
|  | (Optional) | 
|  | User-defined name for the Workload. | 
|  |  | 
|  | * `description` - | 
|  | (Optional) | 
|  | User-defined description of a Workload. | 
|  |  | 
|  | * `attributes` - | 
|  | (Optional) | 
|  | Consumer provided attributes. | 
|  | Structure is [documented below](#nested_attributes). | 
|  |  | 
|  | * `project` - (Optional) The ID of the project in which the resource belongs. | 
|  | If it is not provided, the provider project is used. | 
|  |  | 
|  |  | 
|  | <a name="nested_attributes"></a>The `attributes` block supports: | 
|  |  | 
|  | * `criticality` - | 
|  | (Optional) | 
|  | Criticality of the Application, Service, or Workload | 
|  | Structure is [documented below](#nested_criticality). | 
|  |  | 
|  | * `environment` - | 
|  | (Optional) | 
|  | Environment of the Application, Service, or Workload | 
|  | Structure is [documented below](#nested_environment). | 
|  |  | 
|  | * `developer_owners` - | 
|  | (Optional) | 
|  | Developer team that owns development and coding. | 
|  | Structure is [documented below](#nested_developer_owners). | 
|  |  | 
|  | * `operator_owners` - | 
|  | (Optional) | 
|  | Operator team that ensures runtime and operations. | 
|  | Structure is [documented below](#nested_operator_owners). | 
|  |  | 
|  | * `business_owners` - | 
|  | (Optional) | 
|  | Business team that ensures user needs are met and value is delivered | 
|  | Structure is [documented below](#nested_business_owners). | 
|  |  | 
|  |  | 
|  | <a name="nested_criticality"></a>The `criticality` block supports: | 
|  |  | 
|  | * `type` - | 
|  | (Required) | 
|  | Criticality type. | 
|  | Possible values are: `MISSION_CRITICAL`, `HIGH`, `MEDIUM`, `LOW`. | 
|  |  | 
|  | <a name="nested_environment"></a>The `environment` block supports: | 
|  |  | 
|  | * `type` - | 
|  | (Required) | 
|  | Environment type. | 
|  | Possible values are: `PRODUCTION`, `STAGING`, `TEST`, `DEVELOPMENT`. | 
|  |  | 
|  | <a name="nested_developer_owners"></a>The `developer_owners` block supports: | 
|  |  | 
|  | * `display_name` - | 
|  | (Optional) | 
|  | Contact's name. | 
|  |  | 
|  | * `email` - | 
|  | (Required) | 
|  | Email address of the contacts. | 
|  |  | 
|  | <a name="nested_operator_owners"></a>The `operator_owners` block supports: | 
|  |  | 
|  | * `display_name` - | 
|  | (Optional) | 
|  | Contact's name. | 
|  |  | 
|  | * `email` - | 
|  | (Required) | 
|  | Email address of the contacts. | 
|  |  | 
|  | <a name="nested_business_owners"></a>The `business_owners` block supports: | 
|  |  | 
|  | * `display_name` - | 
|  | (Optional) | 
|  | Contact's name. | 
|  |  | 
|  | * `email` - | 
|  | (Required) | 
|  | Email address of the contacts. | 
|  |  | 
|  | ## Attributes Reference | 
|  |  | 
|  | In addition to the arguments listed above, the following computed attributes are exported: | 
|  |  | 
|  | * `id` - an identifier for the resource with format `projects/{{project}}/locations/{{location}}/applications/{{application_id}}/workloads/{{workload_id}}` | 
|  |  | 
|  | * `name` - | 
|  | Identifier. The resource name of the Workload. Format:"projects/{host-project-id}/locations/{location}/applications/{application-id}/workloads/{workload-id}" | 
|  |  | 
|  | * `workload_reference` - | 
|  | Reference of an underlying compute resource represented by the Workload. | 
|  | Structure is [documented below](#nested_workload_reference). | 
|  |  | 
|  | * `workload_properties` - | 
|  | Properties of an underlying compute resource represented by the Workload. | 
|  | Structure is [documented below](#nested_workload_properties). | 
|  |  | 
|  | * `create_time` - | 
|  | Output only. Create time. | 
|  |  | 
|  | * `update_time` - | 
|  | Output only. Update time. | 
|  |  | 
|  | * `uid` - | 
|  | Output only. A universally unique identifier (UUID) for the `Workload` in the UUID4 format. | 
|  |  | 
|  | * `state` - | 
|  | Output only. Workload state. Possible values:  STATE_UNSPECIFIED CREATING ACTIVE DELETING DETACHED | 
|  |  | 
|  |  | 
|  | <a name="nested_workload_reference"></a>The `workload_reference` block contains: | 
|  |  | 
|  | * `uri` - | 
|  | (Output) | 
|  | Output only. The underlying compute resource uri. | 
|  |  | 
|  | <a name="nested_workload_properties"></a>The `workload_properties` block contains: | 
|  |  | 
|  | * `gcp_project` - | 
|  | (Output) | 
|  | Output only. The service project identifier that the underlying cloud resource resides in. Empty for non cloud resources. | 
|  |  | 
|  | * `location` - | 
|  | (Output) | 
|  | Output only. The location that the underlying compute resource resides in (e.g us-west1). | 
|  |  | 
|  | * `zone` - | 
|  | (Output) | 
|  | Output only. The location that the underlying compute resource resides in if it is zonal (e.g us-west1-a). | 
|  |  | 
|  | ## Timeouts | 
|  |  | 
|  | This resource provides the following | 
|  | [Timeouts](https://developer.hashicorp.com/terraform/plugin/sdkv2/resources/retries-and-customizable-timeouts) configuration options: | 
|  |  | 
|  | - `create` - Default is 20 minutes. | 
|  | - `update` - Default is 20 minutes. | 
|  | - `delete` - Default is 20 minutes. | 
|  |  | 
|  | ## Import | 
|  |  | 
|  |  | 
|  | Workload can be imported using any of these accepted formats: | 
|  |  | 
|  | * `projects/{{project}}/locations/{{location}}/applications/{{application_id}}/workloads/{{workload_id}}` | 
|  | * `{{project}}/{{location}}/{{application_id}}/{{workload_id}}` | 
|  | * `{{location}}/{{application_id}}/{{workload_id}}` | 
|  |  | 
|  |  | 
|  | In Terraform v1.5.0 and later, use an [`import` block](https://developer.hashicorp.com/terraform/language/import) to import Workload using one of the formats above. For example: | 
|  |  | 
|  | ```tf | 
|  | import { | 
|  | id = "projects/{{project}}/locations/{{location}}/applications/{{application_id}}/workloads/{{workload_id}}" | 
|  | to = google_apphub_workload.default | 
|  | } | 
|  | ``` | 
|  |  | 
|  | When using the [`terraform import` command](https://developer.hashicorp.com/terraform/cli/commands/import), Workload can be imported using one of the formats above. For example: | 
|  |  | 
|  | ``` | 
|  | $ terraform import google_apphub_workload.default projects/{{project}}/locations/{{location}}/applications/{{application_id}}/workloads/{{workload_id}} | 
|  | $ terraform import google_apphub_workload.default {{project}}/{{location}}/{{application_id}}/{{workload_id}} | 
|  | $ terraform import google_apphub_workload.default {{location}}/{{application_id}}/{{workload_id}} | 
|  | ``` | 
|  |  | 
|  | ## User Project Overrides | 
|  |  | 
|  | This resource supports [User Project Overrides](https://registry.terraform.io/providers/hashicorp/google/latest/docs/guides/provider_reference#user_project_override). |