### Parallelstore Instance Basic Example Source: https://github.com/hashicorp/terraform-provider-google/blob/main/website/docs/r/parallelstore_instance.html.markdown Creates a basic Parallelstore instance. This example includes network configuration and private service connection setup, similar to the beta example but without explicitly setting the provider. ```hcl resource "google_parallelstore_instance" "instance" { instance_id = "instance" location = "us-central1-a" description = "test instance" capacity_gib = 12000 network = google_compute_network.network.name file_stripe_level = "FILE_STRIPE_LEVEL_MIN" directory_stripe_level = "DIRECTORY_STRIPE_LEVEL_MIN" deployment_type = "SCRATCH" labels = { test = "value" } depends_on = [google_service_networking_connection.default] } resource "google_compute_network" "network" { name = "network" auto_create_subnetworks = true mtu = 8896 } # Create an IP address resource "google_compute_global_address" "private_ip_alloc" { name = "address" purpose = "VPC_PEERING" address_type = "INTERNAL" prefix_length = 24 network = google_compute_network.network.id } # Create a private connection resource "google_service_networking_connection" "default" { network = google_compute_network.network.id service = "servicenetworking.googleapis.com" reserved_peering_ranges = [google_compute_global_address.private_ip_alloc.name] } ``` -------------------------------- ### Parallelstore Instance Basic Beta Example Source: https://github.com/hashicorp/terraform-provider-google/blob/main/website/docs/r/parallelstore_instance.html.markdown Creates a basic Parallelstore instance using the beta provider. This example includes network configuration and private service connection setup. ```hcl resource "google_parallelstore_instance" "instance" { provider = google-beta instance_id = "instance" location = "us-central1-a" description = "test instance" capacity_gib = 12000 network = google_compute_network.network.name file_stripe_level = "FILE_STRIPE_LEVEL_MIN" directory_stripe_level = "DIRECTORY_STRIPE_LEVEL_MIN" deployment_type = "SCRATCH" labels = { test = "value" } depends_on = [google_service_networking_connection.default] } resource "google_compute_network" "network" { provider = google-beta name = "network" auto_create_subnetworks = true mtu = 8896 } # Create an IP address resource "google_compute_global_address" "private_ip_alloc" { provider = google-beta name = "address" purpose = "VPC_PEERING" address_type = "INTERNAL" prefix_length = 24 network = google_compute_network.network.id } # Create a private connection resource "google_service_networking_connection" "default" { provider = google-beta network = google_compute_network.network.id service = "servicenetworking.googleapis.com" reserved_peering_ranges = [google_compute_global_address.private_ip_alloc.name] } ``` -------------------------------- ### Full Apigee Instance Example Source: https://github.com/hashicorp/terraform-provider-google/blob/main/website/docs/r/apigee_instance.html.markdown This example demonstrates the full configuration for creating an Apigee organization and an Apigee instance, including network setup, KMS encryption, and service identity configuration. ```hcl data "google_client_config" "current" {} resource "google_compute_network" "apigee_network" { name = "apigee-network" } resource "google_compute_global_address" "apigee_range" { name = "apigee-range" purpose = "VPC_PEERING" address_type = "INTERNAL" prefix_length = 16 network = google_compute_network.apigee_network.id } resource "google_service_networking_connection" "apigee_vpc_connection" { network = google_compute_network.apigee_network.id service = "servicenetworking.googleapis.com" reserved_peering_ranges = [google_compute_global_address.apigee_range.name] } resource "google_kms_key_ring" "apigee_keyring" { name = "apigee-keyring" location = "us-central1" } resource "google_kms_crypto_key" "apigee_key" { name = "apigee-key" key_ring = google_kms_key_ring.apigee_keyring.id lifecycle { prevent_destroy = true } } resource "google_project_service_identity" "apigee_sa" { provider = google-beta project = google_project.project.project_id service = google_project_service.apigee.service } resource "google_kms_crypto_key_iam_member" "apigee_sa_keyuser" { crypto_key_id = google_kms_crypto_key.apigee_key.id role = "roles/cloudkms.cryptoKeyEncrypterDecrypter" member = google_project_service_identity.apigee_sa.member } resource "google_apigee_organization" "apigee_org" { analytics_region = "us-central1" display_name = "apigee-org" description = "Terraform-provisioned Apigee Org." project_id = data.google_client_config.current.project authorized_network = google_compute_network.apigee_network.id runtime_database_encryption_key_name = google_kms_crypto_key.apigee_key.id depends_on = [ google_service_networking_connection.apigee_vpc_connection, google_kms_crypto_key_iam_member.apigee_sa_keyuser, ] } resource "google_apigee_instance" "apigee_instance" { name = "my-instance-name" location = "us-central1" description = "Terraform-managed Apigee Runtime Instance" display_name = "my-instance-name" org_id = google_apigee_organization.apigee_org.id disk_encryption_key_name = google_kms_crypto_key.apigee_key.id } ``` -------------------------------- ### Apigee Target Server Test Basic Source: https://github.com/hashicorp/terraform-provider-google/blob/main/website/docs/r/apigee_target_server.html.markdown This example shows how to set up a basic Apigee Target Server. It includes the necessary project and service configurations, network setup, and the creation of the target server resource itself. ```hcl resource "google_project" "project" { project_id = "my-project" name = "my-project" org_id = "123456789" billing_account = "000000-0000000-0000000-000000" deletion_policy = "DELETE" } resource "google_project_service" "apigee" { project = google_project.project.project_id service = "apigee.googleapis.com" } resource "google_project_service" "servicenetworking" { project = google_project.project.project_id service = "servicenetworking.googleapis.com" depends_on = [google_project_service.apigee] } resource "google_project_service" "compute" { project = google_project.project.project_id service = "compute.googleapis.com" depends_on = [google_project_service.servicenetworking] } resource "google_compute_network" "apigee_network" { name = "apigee-network" project = google_project.project.project_id depends_on = [google_project_service.compute] } resource "google_compute_global_address" "apigee_range" { name = "apigee-range" purpose = "VPC_PEERING" address_type = "INTERNAL" prefix_length = 16 network = google_compute_network.apigee_network.id project = google_project.project.project_id } resource "google_service_networking_connection" "apigee_vpc_connection" { network = google_compute_network.apigee_network.id service = "servicenetworking.googleapis.com" reserved_peering_ranges = [google_compute_global_address.apigee_range.name] depends_on = [google_project_service.servicenetworking] } resource "google_apigee_organization" "apigee_org" { analytics_region = "us-central1" project_id = google_project.project.project_id authorized_network = google_compute_network.apigee_network.id depends_on = [ google_service_networking_connection.apigee_vpc_connection, google_project_service.apigee, ] } resource "google_apigee_environment" "apigee_environment" { org_id = google_apigee_organization.apigee_org.id name = "my-environment-name" description = "Apigee Environment" display_name = "environment-1" } resource "google_apigee_target_server" "apigee_target_server" { name = "my-target-server" description = "Apigee Target Server" protocol = "HTTP" host = "abc.foo.com" port = 8080 env_id = google_apigee_environment.apigee_environment.id } ``` -------------------------------- ### Instance Settings Basic Source: https://github.com/hashicorp/terraform-provider-google/blob/main/website/docs/r/compute_instance_settings.html.markdown This example shows how to create a basic instance settings resource, specifying the zone and metadata items. ```hcl resource "google_compute_instance_settings" "gce_instance_settings" { zone = "us-east7-b" metadata { items = { foo = "baz" } } } ``` -------------------------------- ### Output Next Steps for Connection Setup Source: https://github.com/hashicorp/terraform-provider-google/blob/main/website/docs/r/firebase_app_hosting_backend.html.markdown Outputs the installation state for the Developer Connect connection, which may include an action URI to guide the user through the remaining setup steps. ```hcl output "next_steps" { description = "Follow the action_uri if present to continue setup" value = google_developer_connect_connection.my-connection.installation_state } ``` -------------------------------- ### Dialogflow CX Version Full Example Source: https://github.com/hashicorp/terraform-provider-google/blob/main/website/docs/r/dialogflow_cx_version.html.markdown Creates a Dialogflow CX agent and then a version for its start flow. This snippet demonstrates the basic setup for managing agent versions. ```hcl resource "google_dialogflow_cx_agent" "agent" { display_name = "dialogflowcx-agent" location = "global" default_language_code = "en" supported_language_codes = ["fr","de","es"] time_zone = "America/New_York" description = "Example description." avatar_uri = "https://cloud.google.com/_static/images/cloud/icons/favicons/onecloud/super_cloud.png" enable_stackdriver_logging = true enable_spell_correction = true speech_to_text_settings { enable_speech_adaptation = true } } resource "google_dialogflow_cx_version" "version_1" { parent = google_dialogflow_cx_agent.agent.start_flow display_name = "1.0.0" description = "version 1.0.0" } ``` -------------------------------- ### Create a Full Workbench Instance with GPU and Network Configuration Source: https://github.com/hashicorp/terraform-provider-google/blob/main/website/docs/r/workbench_instance.html.markdown This comprehensive example demonstrates creating a Workbench instance with a GPU, custom network configuration, boot and data disks with CMEK encryption, and reservation affinity. It also includes IAM bindings and tags. ```hcl resource "google_compute_network" "my_network" { name = "wbi-test-default" auto_create_subnetworks = false } resource "google_compute_subnetwork" "my_subnetwork" { name = "wbi-test-default" network = google_compute_network.my_network.id region = "us-central1" ip_cidr_range = "10.0.1.0/24" } resource "google_compute_address" "static" { name = "wbi-test-default" } resource "google_service_account_iam_binding" "act_as_permission" { service_account_id = "projects/my-project-name/serviceAccounts/my@service-account.com" role = "roles/iam.serviceAccountUser" members = [ "user:example@example.com", ] } resource "google_compute_reservation" "gpu_reservation" { name = "wbi-reservation" zone = "us-central1-a" specific_reservation { count = 1 instance_properties { machine_type = "n1-standard-4" guest_accelerators { accelerator_type = "nvidia-tesla-t4" accelerator_count = 1 } } } specific_reservation_required = true } resource "google_workbench_instance" "instance" { name = "workbench-instance" location = "us-central1-a" gce_setup { machine_type = "n1-standard-4" // cant be e2 because of accelerator accelerator_configs { type = "NVIDIA_TESLA_T4" core_count = 1 } shielded_instance_config { enable_secure_boot = true enable_vtpm = true enable_integrity_monitoring = true } disable_public_ip = false service_accounts { email = "my@service-account.com" } boot_disk { disk_size_gb = 310 disk_type = "PD_SSD" disk_encryption = "CMEK" kms_key = "my-crypto-key" } data_disks { disk_size_gb = 330 disk_type = "PD_SSD" disk_encryption = "CMEK" kms_key = "my-crypto-key" } network_interfaces { network = google_compute_network.my_network.id subnet = google_compute_subnetwork.my_subnetwork.id nic_type = "GVNIC" access_configs { external_ip = google_compute_address.static.address } } metadata = { terraform = "true", serial-port-logging-enable = "false" "enable-jupyterlab4" = "false" } reservation_affinity { consume_reservation_type = "RESERVATION_SPECIFIC" key = "compute.googleapis.com/reservation-name" values = [google_compute_reservation.gpu_reservation.name] } enable_ip_forwarding = true tags = ["abc", "def"] } disable_proxy_access = "true" instance_owners = ["example@example.com"] labels = { k = "val" } desired_state = "ACTIVE" enable_third_party_identity = "true" depends_on = [ google_compute_network.my_network, google_compute_subnetwork.my_subnetwork, google_compute_address.static, google_service_account_iam_binding.act_as_permission, google_compute_reservation.gpu_reservation ] } ``` -------------------------------- ### Cloud Run v2 Job Run Job Example Source: https://github.com/hashicorp/terraform-provider-google/blob/main/website/docs/r/cloud_run_v2_job.html.markdown This example shows a basic Cloud Run v2 Job configuration that can be started once created. It uses the 'google-beta' provider and sets a specific token for starting the execution. ```hcl resource "google_cloud_run_v2_job" "default" { provider = google-beta name = "cloudrun-job" location = "us-central1" deletion_protection = false start_execution_token = "start-once-created" template { template { containers { image = "us-docker.pkg.dev/cloudrun/container/job" } } } } ``` -------------------------------- ### Saas Runtime Unit Basic Example Source: https://github.com/hashicorp/terraform-provider-google/blob/main/website/docs/r/saas_runtime_unit.html.markdown This example demonstrates the basic creation of a SaaS Runtime Unit, including its associated SaaS and Unit Kind resources. Ensure the 'google-beta' provider is configured. ```hcl resource "google_saas_runtime_saas" "example_saas_regional" { provider = google-beta saas_id = "example-saas" location = "us-central1" locations { name = "us-central1" } } resource "google_saas_runtime_unit_kind" "example_unit_kind" { provider = google-beta location = "us-central1" unit_kind_id = "example-unitkind" saas = google_saas_runtime_saas.example_saas_regional.id } resource "google_saas_runtime_unit" "example" { provider = google-beta location = "us-central1" unit_id = "example-unit" unit_kind = google_saas_runtime_unit_kind.example_unit_kind.id management_mode = "MANAGEMENT_MODE_USER" } ``` -------------------------------- ### Target Vpn Gateway Basic Source: https://github.com/hashicorp/terraform-provider-google/blob/main/website/docs/r/compute_vpn_gateway.html.markdown This example demonstrates how to set up a basic VPN gateway, including a network, a static IP address, forwarding rules for ESP, UDP 500, and UDP 4500, a VPN tunnel, and a static route. It requires the `google_compute_network`, `google_compute_address`, and `google_compute_forwarding_rule` resources to be defined. ```hcl resource "google_compute_vpn_gateway" "target_gateway" { name = "vpn-1" network = google_compute_network.network1.id } resource "google_compute_network" "network1" { name = "network-1" } resource "google_compute_address" "vpn_static_ip" { name = "vpn-static-ip" } resource "google_compute_forwarding_rule" "fr_esp" { name = "fr-esp" ip_protocol = "ESP" ip_address = google_compute_address.vpn_static_ip.address target = google_compute_vpn_gateway.target_gateway.id } resource "google_compute_forwarding_rule" "fr_udp500" { name = "fr-udp500" ip_protocol = "UDP" port_range = "500" ip_address = google_compute_address.vpn_static_ip.address target = google_compute_vpn_gateway.target_gateway.id } resource "google_compute_forwarding_rule" "fr_udp4500" { name = "fr-udp4500" ip_protocol = "UDP" port_range = "4500" ip_address = google_compute_address.vpn_static_ip.address target = google_compute_vpn_gateway.target_gateway.id } resource "google_compute_vpn_tunnel" "tunnel1" { name = "tunnel1" peer_ip = "15.0.0.120" shared_secret = "a secret message" target_vpn_gateway = google_compute_vpn_gateway.target_gateway.id depends_on = [ google_compute_forwarding_rule.fr_esp, google_compute_forwarding_rule.fr_udp500, google_compute_forwarding_rule.fr_udp4500, ] } resource "google_compute_route" "route1" { name = "route1" network = google_compute_network.network1.name dest_range = "15.0.0.0/24" priority = 1000 next_hop_vpn_tunnel = google_compute_vpn_tunnel.tunnel1.id } ``` -------------------------------- ### Snapshot Creation with Beta Provider and Guest Flush Source: https://github.com/hashicorp/terraform-provider-google/blob/main/website/docs/r/compute_snapshot.html.markdown This example shows how to create a snapshot using the google-beta provider, enabling the `guest_flush` option for a more consistent snapshot. It also includes specifying the provider for data sources and resources. ```hcl resource "google_compute_snapshot" "snapshot" { provider = google-beta name = "my-snapshot" source_disk = google_compute_disk.persistent.id zone = "us-central1-a" labels = { my_label = "value" } storage_locations = ["us-central1"] guest_flush = true } data "google_compute_image" "debian" { provider = google-beta family = "debian-11" project = "debian-cloud" } resource "google_compute_disk" "persistent" { provider = google-beta name = "debian-disk" image = data.google_compute_image.debian.self_link size = 10 type = "pd-ssd" zone = "us-central1-a" } ``` -------------------------------- ### Bigquery Job Copy Example Source: https://github.com/hashicorp/terraform-provider-google/blob/main/website/docs/r/bigquery_job.html.markdown This example demonstrates how to create a BigQuery job to copy data between tables. It includes the setup for source and destination datasets and tables, along with encryption configurations. ```APIDOC ## google_bigquery_job Resource This resource is used to manage BigQuery jobs, including copy, extract, load, and query jobs. ### Example Usage: Copy Job This example shows how to configure a copy job to copy data from multiple source tables to a single destination table. #### Resource: google_bigquery_job ##### Arguments: * `job_id` - (Required) The ID of the job. * `copy` - (Optional) Configuration block for copy jobs. See below for details. ##### `copy` Block: * `source_tables` - (Required) A list of tables to copy from. Each element is a block with: * `project_id` - (Optional) The project ID of the source table. * `dataset_id` - (Required) The dataset ID of the source table. * `table_id` - (Required) The table ID of the source table. * `destination_table` - (Required) The destination table block with: * `project_id` - (Optional) The project ID of the destination table. * `dataset_id` - (Required) The dataset ID of the destination table. * `table_id` - (Required) The table ID of the destination table. * `destination_encryption_configuration` - (Optional) Configuration block for encryption of the destination table. See below for details. ##### `destination_encryption_configuration` Block: * `kms_key_name` - (Required) The KMS key name to use for encryption. #### Example Configuration: ```hcl resource "google_bigquery_job" "job" { job_id = "job_copy" copy { source_tables { project_id = google_bigquery_table.source.0.project dataset_id = google_bigquery_table.source.0.dataset_id table_id = google_bigquery_table.source.0.table_id } source_tables { project_id = google_bigquery_table.source.1.project dataset_id = google_bigquery_table.source.1.dataset_id table_id = google_bigquery_table.source.1.table_id } destination_table { project_id = google_bigquery_table.dest.project dataset_id = google_bigquery_table.dest.dataset_id table_id = google_bigquery_table.dest.table_id } destination_encryption_configuration { kms_key_name = "example-key" } } depends_on = ["google_kms_crypto_key_iam_member.encrypt_role"] } ``` ``` -------------------------------- ### Example Usage with resource policies (`google` provider) Source: https://github.com/hashicorp/terraform-provider-google/blob/main/website/docs/r/compute_instance_group_manager.html.markdown Creates an Instance Group Manager with a workload resource policy applied. This example also includes the necessary data source for an image and the instance template resource. ```hcl data "google_compute_image" "my_image" { family = "debian-11" project = "debian-cloud" } resource "google_compute_resource_policy" "workload_policy" { name = "tf-test-gce-policy" region = "us-central1" workload_policy { type = "HIGH_THROUGHPUT" } } resource "google_compute_instance_template" "igm-basic" { name = "igm-instance-template" machine_type = "a4-highgpu-8g" can_ip_forward = false tags = ["foo", "bar"] disk { source_image = data.google_compute_image.my_image.self_link auto_delete = true boot = true disk_type = "hyperdisk-balanced" } network_interface { network = "default" } service_account { scopes = ["userinfo-email", "compute-ro", "storage-ro"] } } resource "google_compute_instance_group_manager" "igm-workload-policy" { description = "Terraform test instance group manager" name = "igm-basic-workload-policy" version { name = "prod" instance_template = google_compute_instance_template.igm-basic.self_link } base_instance_name = "tf-test-igm-no-tp" zone = "us-central1-b" target_size = 0 resource_policies { workload_policy = google_compute_resource_policy.workload_policy.self_link } } ``` -------------------------------- ### Install and Remove Packages with Repositories Source: https://github.com/hashicorp/terraform-provider-google/blob/main/website/docs/r/os_config_guest_policies.html.markdown This snippet demonstrates how to configure guest policies to install a package, remove another, and manage APT and YUM package repositories. It includes examples for both Debian/Ubuntu (APT) and RHEL/CentOS (YUM) based systems. ```hcl 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 - Saas Runtime Unit Operation Basic Source: https://github.com/hashicorp/terraform-provider-google/blob/main/website/docs/r/saas_runtime_unit_operation.html.markdown This example demonstrates the creation of a SaaS Runtime Unit Operation for provisioning a unit. It includes setting up necessary resources like SaaS, Unit Kind, Release, Unit, Tenant Project, Service Accounts, and IAM bindings, and then defines the provision operation with input variables. ```hcl locals { location = "us-east1" tenant_project_id = "tenant" } resource "google_saas_runtime_saas" "example_saas" { provider = google-beta saas_id = "example-saas" location = local.location locations { name = local.location } } resource "google_saas_runtime_unit_kind" "cluster_unit_kind" { provider = google-beta location = local.location unit_kind_id = "vm-unitkind" saas = google_saas_runtime_saas.example_saas.id default_release = "projects/my-project-name/locations/${local.location}/releases/example-release" } resource "google_saas_runtime_release" "example_release" { provider = google-beta location = local.location release_id = "example-release" unit_kind = google_saas_runtime_unit_kind.cluster_unit_kind.id blueprint { package = "us-central1-docker.pkg.dev/ci-test-project-188019/test-repo/tf-test-easysaas-alpha-image@sha256:7992fdbaeaf998ecd31a7f937bb26e38a781ecf49b24857a6176c1e9bfc299ee" } } resource "google_saas_runtime_unit" "example_unit" { provider = google-beta location = local.location unit_id = "example-unit" unit_kind = google_saas_runtime_unit_kind.cluster_unit_kind.id } resource "google_project" "tenant_project" { provider = google-beta project_id = local.tenant_project_id name = local.tenant_project_id billing_account = "000000-000000-000000-000000" org_id = "123456789" deletion_policy = "DELETE" } resource "google_project_service" "saas_services" { provider = google-beta project = google_project.tenant_project.project_id service = "compute.googleapis.com" disable_dependent_services = true } resource "google_service_account" "actuation_service_account" { provider = google-beta account_id = "actuator" display_name = "SaaS Actuation Service Account" } resource "google_project_iam_member" "tenant_config_admin" { provider = google-beta project = google_project.tenant_project.project_id role = "roles/config.admin" member = "serviceAccount:${google_service_account.actuation_service_account.email}" } resource "google_project_iam_member" "tenant_storage_admin" { provider = google-beta project = google_project.tenant_project.project_id role = "roles/storage.admin" member = "serviceAccount:${google_service_account.actuation_service_account.email}" } resource "google_project_iam_member" "tenant_compute_admin" { provider = google-beta project = google_project.tenant_project.project_id role = "roles/compute.admin" member = "serviceAccount:${google_service_account.actuation_service_account.email}" } resource "google_service_account_iam_member" "actuation_token_creator" { provider = google-beta service_account_id = google_service_account.actuation_service_account.name role = "roles/iam.serviceAccountTokenCreator" member = "serviceAccount:service-1111111111111@gcp-sa-saasservicemgmt.iam.gserviceaccount.com" } resource "google_saas_runtime_unit_operation" "provision_unit_operation" { provider = google-beta depends_on = [google_project_iam_member.tenant_config_admin, google_project_iam_member.tenant_storage_admin, google_project_iam_member.tenant_compute_admin, google_service_account_iam_member.actuation_token_creator, google_project_service.saas_services] location = local.location unit_operation_id = "provision-unit-operation" unit = google_saas_runtime_unit.example_unit.id wait_for_completion = true provision { release = google_saas_runtime_release.example_release.id input_variables { variable = "tenant_project_id" value = google_project.tenant_project.project_id type = "STRING" } input_variables { variable = "tenant_project_number" value = google_project.tenant_project.number type = "INT" } input_variables { variable = "zone" value = "us-central1-a" type = "STRING" } input_variables { variable = "instance_name" value = "terraform-test-instance" type = "STRING" } input_variables { variable = "actuation_sa" value = google_service_account.actuation_service_account.email type = "STRING" } } labels = { "label-one" : "foo" } annotations = { "annotation-one" : "bar" } } ``` -------------------------------- ### Firestore Document Nested Document Example Source: https://github.com/hashicorp/terraform-provider-google/blob/main/website/docs/r/firestore_document.html.markdown Demonstrates creating nested Firestore documents. It shows how to reference the path of a parent document to create sub-documents and sub-sub-documents. This example also includes the prerequisite setup for project, service, and database. ```hcl resource "google_project" "project" { project_id = "project-id" name = "project-id" org_id = "123456789" deletion_policy = "DELETE" } resource "time_sleep" "wait_60_seconds" { depends_on = [google_project.project] create_duration = "60s" } resource "google_project_service" "firestore" { project = google_project.project.project_id service = "firestore.googleapis.com" # Needed for CI tests for permissions to propagate, should not be needed for actual usage depends_on = [time_sleep.wait_60_seconds] } resource "google_firestore_database" "database" { project = google_project.project.project_id name = "(default)" location_id = "nam5" type = "FIRESTORE_NATIVE" depends_on = [google_project_service.firestore] } resource "google_firestore_document" "mydoc" { project = google_project.project.project_id database = google_firestore_database.database.name collection = "somenewcollection" document_id = "my-doc-id" fields = "{\"something\":{\"mapValue\":{\"fields\":{\"akey\":{\"stringValue\":\"avalue\"}}}} " } resource "google_firestore_document" "sub_document" { project = google_project.project.project_id database = google_firestore_database.database.name collection = "${google_firestore_document.mydoc.path}/subdocs" document_id = "bitcoinkey" fields = "{\"something\":{\"mapValue\":{\"fields\":{\"ayo\":{\"stringValue\":\"val2\"}}}} " } resource "google_firestore_document" "sub_sub_document" { project = google_project.project.project_id database = google_firestore_database.database.name collection = "${google_firestore_document.sub_document.path}/subsubdocs" document_id = "asecret" fields = "{\"something\":{\"mapValue\":{\"fields\":{\"secret\":{\"stringValue\":\"hithere\"}}}} " } ``` -------------------------------- ### Full Apphub Service Example Source: https://github.com/hashicorp/terraform-provider-google/blob/main/website/docs/r/apphub_service.html.markdown This snippet demonstrates the complete setup for an App Hub Service, including creating an application, attaching a service project, and defining the service with its attributes. It also provisions the necessary Google Compute Engine resources like VPC network, subnet, forwarding rule, backend service, and health check. ```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 service block data "google_apphub_discovered_service" "catalog-service" { provider = google location = "us-central1" service_uri = "//compute.googleapis.com/${google_compute_forwarding_rule.forwarding_rule.id}" depends_on = [google_apphub_service_project_attachment.service_project_attachment, time_sleep.wait_120s_for_resource_ingestion] } resource "time_sleep" "wait_120s_for_resource_ingestion" { depends_on = [google_compute_forwarding_rule.forwarding_rule] create_duration = "120s" } resource "google_apphub_service" "example" { location = "us-central1" application_id = google_apphub_application.application.application_id service_id = google_compute_forwarding_rule.forwarding_rule.name discovered_service = data.google_apphub_discovered_service.catalog-service.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" } } } #creates service # 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 } # forwarding rule resource "google_compute_forwarding_rule" "forwarding_rule" { name ="l7-ilb-forwarding-rule" project = google_project.service_project.project_id region = "us-central1" ip_version = "IPV4" load_balancing_scheme = "INTERNAL" all_ports = true backend_service = google_compute_region_backend_service.backend.id network = google_compute_network.ilb_network.id subnetwork = google_compute_subnetwork.ilb_subnet.id } # backend service resource "google_compute_region_backend_service" "backend" { name = "l7-ilb-backend-subnet" project = google_project.service_project.project_id region = "us-central1" health_checks = [google_compute_health_check.default.id] } # health check resource "google_compute_health_check" "default" { name = "l7-ilb-hc" project = google_project.service_project.project_id check_interval_sec = 1 timeout_sec = 1 tcp_health_check { port = "80" } depends_on = [time_sleep.wait_120s] } ``` -------------------------------- ### Migration Center Discovery Client Basic Example Source: https://github.com/hashicorp/terraform-provider-google/blob/main/website/docs/r/migration_center_discovery_client.html.markdown This example shows how to create a basic Migration Center Discovery Client. It requires a Migration Center Source and a Service Account to be pre-configured. ```hcl resource "google_migration_center_source" "default" { location = "us-central1" source_id = "source-test" type = "SOURCE_TYPE_DISCOVERY_CLIENT" } resource "google_service_account" "default" { account_id = "sa-test" display_name = "Service Account for Discovery Client" } resource "google_service_account" "default_2" { account_id = "sa-test-two" display_name = "Second Service Account for Discovery Client" } resource "google_migration_center_discovery_client" "default" { location = "us-central1" discovery_client_id = "discovery-client-test" source = google_migration_center_source.default.id service_account = google_service_account.default.email display_name = "Terraform integration test display" description = "Terraform integration test description" ttl = "86400s" labels = { my_key = "value" second_key = "second_value" } } ``` -------------------------------- ### Firestore Document Basic Example Source: https://github.com/hashicorp/terraform-provider-google/blob/main/website/docs/r/firestore_document.html.markdown Creates a basic Firestore document with a specified collection, document ID, and fields. This example includes necessary setup for a Google Cloud project, enabling the Firestore API, and creating a Firestore database. ```hcl resource "google_project" "project" { project_id = "project-id" name = "project-id" org_id = "123456789" deletion_policy = "DELETE" } resource "time_sleep" "wait_60_seconds" { depends_on = [google_project.project] create_duration = "60s" } resource "google_project_service" "firestore" { project = google_project.project.project_id service = "firestore.googleapis.com" # Needed for CI tests for permissions to propagate, should not be needed for actual usage depends_on = [time_sleep.wait_60_seconds] } resource "google_firestore_database" "database" { project = google_project.project.project_id name = "(default)" location_id = "nam5" type = "FIRESTORE_NATIVE" depends_on = [google_project_service.firestore] } resource "google_firestore_document" "mydoc" { project = google_project.project.project_id database = google_firestore_database.database.name collection = "somenewcollection" document_id = "my-doc-id" fields = "{\"something\":{\"mapValue\":{\"fields\":{\"akey\":{\"stringValue\":\"avalue\"}}}} " } ``` -------------------------------- ### Apphub Service Basic Example Source: https://github.com/hashicorp/terraform-provider-google/blob/main/website/docs/r/apphub_service.html.markdown This example demonstrates how to create a basic App Hub Service. It requires setting up an application, a service project, attaching the service project, discovering a service, and then creating the service resource itself. Ensure necessary APIs are enabled and sufficient wait times are included for resource propagation. ```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 service block data "google_apphub_discovered_service" "catalog-service" { provider = google location = "us-central1" service_uri = "//compute.googleapis.com/${google_compute_forwarding_rule.forwarding_rule.id}" depends_on = [google_apphub_service_project_attachment.service_project_attachment, time_sleep.wait_120s_for_resource_ingestion] } resource "time_sleep" "wait_120s_for_resource_ingestion" { depends_on = [google_compute_forwarding_rule.forwarding_rule] create_duration = "120s" } resource "google_apphub_service" "example" { location = "us-central1" application_id = google_apphub_application.application.application_id service_id = google_compute_forwarding_rule.forwarding_rule.name discovered_service = data.google_apphub_discovered_service.catalog-service.name } #creates service # 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 } # forwarding rule resource "google_compute_forwarding_rule" "forwarding_rule" { name ="l7-ilb-forwarding-rule" project = google_project.service_project.project_id region = "us-central1" ip_version = "IPV4" load_balancing_scheme = "INTERNAL" all_ports = true backend_service = google_compute_region_backend_service.backend.id network = google_compute_network.ilb_network.id subnetwork = google_compute_subnetwork.ilb_subnet.id } # backend service resource "google_compute_region_backend_service" "backend" { name = "l7-ilb-backend-subnet" project = google_project.service_project.project_id region = "us-central1" health_checks = [google_compute_health_check.default.id] } # health check resource "google_compute_health_check" "default" { name = "l7-ilb-hc" project = google_project.service_project.project_id check_interval_sec = 1 timeout_sec = 1 tcp_health_check { port = "80" } depends_on = [time_sleep.wait_120s] } ```