Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new resource Service for Apphub #10132

Merged
merged 46 commits into from
Mar 12, 2024
Merged
Show file tree
Hide file tree
Changes from 40 commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
31bf4fb
Add new resource for Service Project for Apphub
eshagoel06 Feb 26, 2024
e223255
Add new resource for Service Project for Apphub
eshagoel06 Feb 26, 2024
c6f1a6b
Add new resource for Service Project Attachment for Apphub
eshagoel06 Feb 26, 2024
0004d01
Add new resource for Service Project Attachment for Apphub
eshagoel06 Feb 26, 2024
dc1d7fb
Add new resource for Service Project Attachment for Apphub
eshagoel06 Feb 26, 2024
3659255
Add new resource for Application for Apphub
eshagoel06 Feb 27, 2024
4d60581
Add new resource for Application for Apphub
eshagoel06 Feb 27, 2024
5ec417d
Enable Apphub API in test cases
eshagoel06 Feb 29, 2024
1c67e69
Add new resource for Service Project Attachment for Apphub
eshagoel06 Feb 26, 2024
0bf9d22
Merge branch 'GoogleCloudPlatform:main' into application
eshagoel06 Feb 29, 2024
bdecf39
Enable apphub API in test cases
eshagoel06 Feb 28, 2024
80d75a4
Fix precheck error
eshagoel06 Mar 4, 2024
90f54bc
Fix precheck error
eshagoel06 Mar 4, 2024
6380564
Fix precheck error
eshagoel06 Mar 4, 2024
67630fb
Fix precheck error
eshagoel06 Mar 4, 2024
7c8bf7f
Merge branch 'GoogleCloudPlatform:main' into application
eshagoel06 Mar 5, 2024
9a751eb
Resolve comments
eshagoel06 Mar 5, 2024
9c862f2
Fix lint error
eshagoel06 Mar 5, 2024
fe69b2a
Fix errors
eshagoel06 Mar 5, 2024
5f3588a
Merge branch 'service-project' of https://github.com/eshagoel06/magic…
eshagoel06 Mar 5, 2024
0517686
Add new resource for Service for Apphub
eshagoel06 Mar 5, 2024
ce29615
Fix examples
eshagoel06 Mar 5, 2024
b4520dc
Merge branch 'application' of https://github.com/eshagoel06/magic-mod…
eshagoel06 Mar 5, 2024
bf6a98f
Add test
eshagoel06 Mar 5, 2024
9aff3e8
Fix tests
eshagoel06 Mar 6, 2024
9396e5d
Merge branch 'GoogleCloudPlatform:main' into service-trial
eshagoel06 Mar 6, 2024
549027a
Add IAM permissions
eshagoel06 Mar 8, 2024
512dd36
Merge branch 'GoogleCloudPlatform:main' into service-trial
eshagoel06 Mar 8, 2024
a598f71
Add IAM permission
eshagoel06 Mar 8, 2024
aa0bca7
Merge branch 'service-trial' of https://github.com/eshagoel06/magic-m…
eshagoel06 Mar 8, 2024
9aa2ffd
Fix IAM issues
eshagoel06 Mar 11, 2024
69d051b
Remove merged changes
eshagoel06 Mar 11, 2024
6b1328d
Merge branch 'GoogleCloudPlatform:main' into service-trial
eshagoel06 Mar 11, 2024
b601e1e
Add billing account
eshagoel06 Mar 11, 2024
92b131a
Remove extra delay from tests
eshagoel06 Mar 11, 2024
796d2e3
Add handwritten update test
eshagoel06 Mar 12, 2024
b14a8b1
Remove merged changes
eshagoel06 Mar 12, 2024
17296a7
Make changes to yaml file incorporating comments from https://github.…
Mar 12, 2024
e5d3c9d
Fix lint errors in Service YAML definition
Mar 12, 2024
f12b980
Add a delay between discovered resource fetch and forwarding rule cre…
Mar 12, 2024
cb0e08f
Add a delay between discovered resource fetch and forwarding rule cre…
Mar 12, 2024
907bb63
Add a delay between discovered resource fetch and forwarding rule cre…
Mar 12, 2024
79f96ee
Merge branch 'GoogleCloudPlatform:main' into service-trial
praseedhaPK Mar 12, 2024
334c512
Batch update tests to improve speed
Mar 12, 2024
c36ce7f
Use standard diff suppress function
Mar 12, 2024
97dcc6c
Update region from us-east1 to us-central1
Mar 12, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
237 changes: 237 additions & 0 deletions mmv1/products/apphub/Service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,237 @@
# Copyright 2024 Google Inc.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

--- !ruby/object:Api::Resource
base_url: projects/{{project}}/locations/{{location}}/applications/{{application_id}}/services
create_url: projects/{{project}}/locations/{{location}}/applications/{{application_id}}/services?serviceId={{service_id}}
self_link: projects/{{project}}/locations/{{location}}/applications/{{application_id}}/services/{{service_id}}
id_format: projects/{{project}}/locations/{{location}}/applications/{{application_id}}/services/{{service_id}}
import_format:
- projects/{{project}}/locations/{{location}}/applications/{{application_id}}/services/{{service_id}}
name: Service
description: '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.'
autogen_async: true
custom_code: !ruby/object:Provider::Terraform::CustomCode
constants: 'templates/terraform/constants/apphub_discovered_resource.go.erb'
examples:
- !ruby/object:Provider::Terraform::Examples
name: "apphub_service_basic"
pull_external: true
primary_resource_id: "example"
vars:
application_id: "example-application-1"
service_project_attachment_id: "project-1"
ilb_network: "l7-ilb-network"
ilb_subnet: "l7-ilb-subnet"
forwarding_rule: "l7-ilb-forwarding-rule"
backend_service: "l7-ilb-backend-subnet"
health_check: "l7-ilb-hc"
test_env_vars:
org_id: :ORG_ID
billing_account: :BILLING_ACCT
- !ruby/object:Provider::Terraform::Examples
name: "apphub_service_full"
pull_external: true
primary_resource_id: "example"
vars:
application_id: "example-application-1"
service_project_attachment_id: "project-1"
display_name: "Example Service Full"
description: "Register service for testing"
business_name: "Alice"
business_email: "[email protected]"
developer_name: "Bob"
developer_email: "[email protected]"
operator_name: "Charlie"
operator_email: "[email protected]"
ilb_network: "l7-ilb-network"
ilb_subnet: "l7-ilb-subnet"
forwarding_rule: "l7-ilb-forwarding-rule"
backend_service: "l7-ilb-backend-subnet"
health_check: "l7-ilb-hc"
test_env_vars:
org_id: :ORG_ID
billing_account: :BILLING_ACCT
async: !ruby/object:Api::OpAsync
operation: !ruby/object:Api::OpAsync::Operation
path: name
base_url: "{{op_id}}"
wait_ms: 1000
timeouts:
result: !ruby/object:Api::OpAsync::Result
path: response
resource_inside_response: true
status: !ruby/object:Api::OpAsync::Status
path: done
complete: true
allowed:
- true
- false
error: !ruby/object:Api::OpAsync::Error
path: error
message: message
update_verb: :PATCH
update_mask: true
parameters:
- !ruby/object:Api::Type::String
name: location
description: 'Part of `parent`. Full resource name of a parent Application. Example: projects/{HOST_PROJECT_ID}/locations/{LOCATION}/applications/{APPLICATION_ID} '
url_param_only: true
required: true
immutable: true
- !ruby/object:Api::Type::String
name: applicationId
description: 'Part of `parent`. Full resource name of a parent Application. Example: projects/{HOST_PROJECT_ID}/locations/{LOCATION}/applications/{APPLICATION_ID}'
url_param_only: true
required: true
immutable: true
- !ruby/object:Api::Type::String
name: serviceId
description: 'The Service identifier. '
url_param_only: true
required: true
immutable: true
properties:
- !ruby/object:Api::Type::String
name: name
output: true
description: "Identifier. The resource name of a Service. Format:\n\"projects/{host-project-id}/locations/{location}/applications/{application-id}/services/{service-id}\" "
- !ruby/object:Api::Type::String
name: displayName
description: 'User-defined name for the Service. '
- !ruby/object:Api::Type::String
name: description
description: 'User-defined description of a Service. '
- !ruby/object:Api::Type::NestedObject
properties:
- !ruby/object:Api::Type::String
name: uri
description: "Output only. The underlying resource URI (For example, URI of Forwarding
Rule, URL Map,\nand Backend Service). "
output: true
output: true
name: serviceReference
description: 'Reference to an underlying networking resource that can comprise a
Service. '
- !ruby/object:Api::Type::NestedObject
properties:
- !ruby/object:Api::Type::String
name: gcpProject
description: "Output only. The service project identifier that the underlying
cloud resource resides in. "
output: true
- !ruby/object:Api::Type::String
name: location
description: "Output only. The location that the underlying resource resides in,
for example, us-west1. "
output: true
- !ruby/object:Api::Type::String
name: zone
description: "Output only. The location that the underlying resource resides in
if it is zonal, for example, us-west1-a). "
output: true
output: true
name: serviceProperties
description: 'Properties of an underlying cloud resource that can comprise a Service. '
- !ruby/object:Api::Type::NestedObject
name: attributes
description: 'Consumer provided attributes. '
properties:
- !ruby/object:Api::Type::NestedObject
name: criticality
description: 'Criticality of the Application, Service, or Workload '
properties:
- !ruby/object:Api::Type::Enum
name: type
description: 'Criticality type. '
required: true
values:
- :MISSION_CRITICAL
- :HIGH
- :MEDIUM
- :LOW
- !ruby/object:Api::Type::NestedObject
name: environment
description: 'Environment of the Application, Service, or Workload '
properties:
- !ruby/object:Api::Type::Enum
name: type
description: 'Environment type. '
required: true
values:
- :PRODUCTION
- :STAGING
- :TEST
- :DEVELOPMENT
- !ruby/object:Api::Type::Array
name: developerOwners
description: 'Developer team that owns development and coding. '
item_type: !ruby/object:Api::Type::NestedObject
properties:
- !ruby/object:Api::Type::String
name: displayName
description: 'Contact''s name. '
- !ruby/object:Api::Type::String
name: email
description: 'Required. Email address of the contacts. '
required: true
- !ruby/object:Api::Type::Array
name: operatorOwners
description: 'Operator team that ensures runtime and operations. '
item_type: !ruby/object:Api::Type::NestedObject
properties:
- !ruby/object:Api::Type::String
name: displayName
description: 'Contact''s name. '
- !ruby/object:Api::Type::String
name: email
description: 'Required. Email address of the contacts. '
required: true
- !ruby/object:Api::Type::Array
name: businessOwners
description: 'Business team that ensures user needs are met and value
is delivered '
item_type: !ruby/object:Api::Type::NestedObject
properties:
- !ruby/object:Api::Type::String
name: displayName
description: 'Contact''s name. '
- !ruby/object:Api::Type::String
name: email
description: 'Required. Email address of the contacts. '
required: true
- !ruby/object:Api::Type::String
name: discoveredService
diff_suppress_func: 'DiscoveredResourceProjectNumberDiffSuppress'
description: 'Immutable. The resource name of the original discovered
service. '
required: true
immutable: true
- !ruby/object:Api::Type::String
name: createTime
description: 'Output only. Create time. '
output: true
- !ruby/object:Api::Type::String
name: updateTime
description: 'Output only. Update time. '
output: true
- !ruby/object:Api::Type::String
name: uid
description: "Output only. A universally unique identifier (UUID) for the `Service`
in the UUID4\nformat. "
output: true
- !ruby/object:Api::Type::String
name: state
description: "Output only. Service state. Possible values: STATE_UNSPECIFIED CREATING ACTIVE DELETING DETACHED"
output: true
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Suppress the project id or number in the field
// Format: "projects/<project-id-or-number>/*"
func DiscoveredResourceProjectNumberDiffSuppress(k, old, new string, d *schema.ResourceData) bool {
oldSplit := regexp.MustCompile("/").Split(old, 3)
newSplit := regexp.MustCompile("/").Split(new, 3)
if len(newSplit) < 3 {
return false
}
if newSplit[0]!=oldSplit[0] || newSplit[2]!=oldSplit[2] {
return false
}
return true
}
110 changes: 110 additions & 0 deletions mmv1/templates/terraform/examples/apphub_service_basic.tf.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
resource "google_apphub_application" "application" {
location = "us-east1"
application_id = "<%= ctx[:vars]['application_id'] %>"
scope {
type = "REGIONAL"
}
}

resource "google_project" "service_project" {
project_id ="<%= ctx[:vars]['service_project_attachment_id'] %>"
name = "Service Project"
org_id = "<%= ctx[:test_env_vars]['org_id'] %>"
billing_account = "<%= ctx[:test_env_vars]['billing_account'] %>"
}

# 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-east1"
service_uri = "//compute.googleapis.com/${google_compute_forwarding_rule.forwarding_rule.id}"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like this lookup is causing the test to fail. Do we maybe need to increase the wait time on the sleep to ensure the discovered service exists?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, we need to wait for a few minutes after the forwarding rule is created; I've made a change wait for 120 seconds to ensure the discovered service exists.

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" "<%= ctx[:primary_resource_id] %>" {
location = "us-east1"
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 = "<%= ctx[:vars]['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 = "<%= ctx[:vars]['ilb_subnet'] %>"
project = google_project.service_project.project_id
ip_cidr_range = "10.0.1.0/24"
region = "us-east1"
network = google_compute_network.ilb_network.id
}

# forwarding rule
resource "google_compute_forwarding_rule" "forwarding_rule" {
name ="<%= ctx[:vars]['forwarding_rule'] %>"
project = google_project.service_project.project_id
region = "us-east1"
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 = "<%= ctx[:vars]['backend_service'] %>"
project = google_project.service_project.project_id
region = "us-east1"
health_checks = [google_compute_health_check.default.id]
}

# health check
resource "google_compute_health_check" "default" {
name = "<%= ctx[:vars]['health_check'] %>"
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]
}


Loading