Service is a network/api interface that exposes some functionality to clients for consumption over the network. Service typically has one or more Workloads behind it. It registers identified service to the Application.
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"
}
# 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]
}
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"
}
# 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]
}
The following arguments are supported:
discovered_service
-
(Required)
Immutable. The resource name of the original discovered service.
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}
service_id
-
(Required)
The Service identifier.
display_name
-
(Optional)
User-defined name for the Service.
description
-
(Optional)
User-defined description of a Service.
attributes
-
(Optional)
Consumer provided attributes.
Structure is documented below.
project
- (Optional) The ID of the project in which the resource belongs.
If it is not provided, the provider project is used.
The attributes
block supports:
criticality
-
(Optional)
Criticality of the Application, Service, or Workload
Structure is documented below.
environment
-
(Optional)
Environment of the Application, Service, or Workload
Structure is documented below.
developer_owners
-
(Optional)
Developer team that owns development and coding.
Structure is documented below.
operator_owners
-
(Optional)
Operator team that ensures runtime and operations.
Structure is documented below.
business_owners
-
(Optional)
Business team that ensures user needs are met and value is delivered
Structure is documented below.
The criticality
block supports:
type
-
(Required)
Criticality type.
Possible values are: MISSION_CRITICAL
, HIGH
, MEDIUM
, LOW
.The environment
block supports:
type
-
(Required)
Environment type.
Possible values are: PRODUCTION
, STAGING
, TEST
, DEVELOPMENT
.The developer_owners
block supports:
display_name
-
(Optional)
Contact's name.
email
-
(Required)
Required. Email address of the contacts.
The operator_owners
block supports:
display_name
-
(Optional)
Contact's name.
email
-
(Required)
Required. Email address of the contacts.
The business_owners
block supports:
display_name
-
(Optional)
Contact's name.
email
-
(Required)
Required. Email address of the contacts.
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}}/services/{{service_id}}
name
-
Identifier. The resource name of a Service. Format:
"projects/{host-project-id}/locations/{location}/applications/{application-id}/services/{service-id}"
service_reference
-
Reference to an underlying networking resource that can comprise a Service.
Structure is documented below.
service_properties
-
Properties of an underlying cloud resource that can comprise a Service.
Structure is documented below.
create_time
-
Output only. Create time.
update_time
-
Output only. Update time.
uid
-
Output only. A universally unique identifier (UUID) for the Service
in the UUID4
format.
state
-
Output only. Service state. Possible values: STATE_UNSPECIFIED CREATING ACTIVE DELETING DETACHED
The service_reference
block contains:
uri
-
(Output)
Output only. The underlying resource URI (For example, URI of Forwarding Rule, URL Map,
and Backend Service).The service_properties
block contains:
gcp_project
-
(Output)
Output only. The service project identifier that the underlying cloud resource resides in.
location
-
(Output)
Output only. The location that the underlying resource resides in, for example, us-west1.
zone
-
(Output)
Output only. The location that the underlying resource resides in if it is zonal, for example, us-west1-a).
This resource provides the following Timeouts configuration options:
create
- Default is 20 minutes.update
- Default is 20 minutes.delete
- Default is 20 minutes.Service can be imported using any of these accepted formats:
projects/{{project}}/locations/{{location}}/applications/{{application_id}}/services/{{service_id}}
{{project}}/{{location}}/{{application_id}}/{{service_id}}
{{location}}/{{application_id}}/{{service_id}}
In Terraform v1.5.0 and later, use an import
block to import Service using one of the formats above. For example:
import {
id = "projects/{{project}}/locations/{{location}}/applications/{{application_id}}/services/{{service_id}}"
to = google_apphub_service.default
}
When using the terraform import
command, Service can be imported using one of the formats above. For example:
$ terraform import google_apphub_service.default projects/{{project}}/locations/{{location}}/applications/{{application_id}}/services/{{service_id}}
$ terraform import google_apphub_service.default {{project}}/{{location}}/{{application_id}}/{{service_id}}
$ terraform import google_apphub_service.default {{location}}/{{application_id}}/{{service_id}}
This resource supports User Project Overrides.