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

Migrate monitoring monitored project to mmv1 #8008

Merged
merged 3 commits into from
Jun 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
59 changes: 59 additions & 0 deletions mmv1/products/monitoring/MonitoredProject.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# Copyright 2023 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
name: MonitoredProject
base_url: v1/locations/global/metricsScopes
create_url: v1/locations/global/metricsScopes/{{metrics_scope}}/projects
delete_url: v1/locations/global/metricsScopes/{{metrics_scope}}/projects/{{name}}
self_link: v1/locations/global/metricsScopes/{{metrics_scope}}
slevenick marked this conversation as resolved.
Show resolved Hide resolved
id_format: v1/locations/global/metricsScopes/{{metrics_scope}}/projects/{{name}}
slevenick marked this conversation as resolved.
Show resolved Hide resolved
import_format:
- v1/locations/global/metricsScopes/{{metrics_scope}}/projects/{{name}}
references: !ruby/object:Api::Resource::ReferenceLinks
guides:
'Official Documentation': 'https://cloud.google.com/monitoring/settings/manage-api'
api: 'https://cloud.google.com/monitoring/api/ref_v3/rest/v1/locations.global.metricsScopes.projects'
nested_query: !ruby/object:Api::Resource::NestedQuery
keys:
- monitoredProjects
description: "A [project being monitored](https://cloud.google.com/monitoring/settings/multiple-projects#create-multi) by a Metrics Scope."
immutable: true
custom_code: !ruby/object:Provider::Terraform::CustomCode
encoder: templates/terraform/encoders/monitoring_monitored_project.go.erb
decoder: templates/terraform/decoders/monitoring_monitored_project.go.erb
test_check_destroy: templates/terraform/custom_check_destroy/monitoring_monitored_project.go.erb
examples:
- !ruby/object:Provider::Terraform::Examples
name: 'monitoring_monitored_project_basic'
primary_resource_id: 'primary'
vars:
monitored_project: 'm-id'
test_env_vars:
org_id: :ORG_ID
project_id: :PROJECT_NAME
parameters:
- !ruby/object:Api::Type::String
name: metricsScope
description: 'Required. The resource name of the existing Metrics Scope that will monitor this project. Example: locations/global/metricsScopes/{SCOPING_PROJECT_ID_OR_NUMBER}'
url_param_only: true
slevenick marked this conversation as resolved.
Show resolved Hide resolved
required: true
properties:
- !ruby/object:Api::Type::String
name: name
slevenick marked this conversation as resolved.
Show resolved Hide resolved
description: 'Immutable. The resource name of the `MonitoredProject`. On input, the resource name includes the scoping project ID and monitored project ID. On output, it contains the equivalent project numbers. Example: `locations/global/metricsScopes/{SCOPING_PROJECT_ID_OR_NUMBER}/projects/{MONITORED_PROJECT_ID_OR_NUMBER}`'
required: true
- !ruby/object:Api::Type::String
name: createTime
description: Output only. The time when this `MonitoredProject` was created.
output: true
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<%# The license inside this block applies to this file.
# Copyright 2023 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.
-%>
config := GoogleProviderConfig(t)

url, err := tpgresource.ReplaceVarsForTest(config, rs, "{{MonitoringBasePath}}v1/locations/global/metricsScopes/{{metrics_scope}}")
if err != nil {
return err
}

billingProject := ""

if config.BillingProject != "" {
billingProject = config.BillingProject
}

res, err := transport_tpg.SendRequest(transport_tpg.SendRequestOptions{
Config: config,
Method: "GET",
Project: billingProject,
RawURL: url,
UserAgent: config.UserAgent,
})

rName := tpgresource.GetResourceNameFromSelfLink(rs.Primary.Attributes["name"])
project, err := config.NewResourceManagerClient(config.UserAgent).Projects.Get(rName).Do()
rName = strconv.FormatInt(project.ProjectNumber, 10)

for _, monitoredProject := range res["monitoredProjects"].([]any) {
if strings.HasSuffix(monitoredProject.(map[string]any)["name"].(string), rName) {
return fmt.Errorf("MonitoringMonitoredProject still exists at %s", url)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<%# The license inside this block applies to this file.
# Copyright 2023 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.
-%>
config := meta.(*transport_tpg.Config)
name := res["name"].(string)
name = tpgresource.GetResourceNameFromSelfLink(name)
if name != "" {
project, err := config.NewResourceManagerClient(config.UserAgent).Projects.Get(name).Do()
if err != nil {
return nil, err
}
res["name"] = project.Name
}
return res, nil
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<%- # the license inside this block applies to this file
# Copyright 2023 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.
-%>
name := d.Get("name").(string)
name = tpgresource.GetResourceNameFromSelfLink(name)
metricsScope := d.Get("metrics_scope").(string)
metricsScope = tpgresource.GetResourceNameFromSelfLink(metricsScope)
obj["name"] = fmt.Sprintf("locations/global/metricsScopes/%s/projects/%s", metricsScope, name)
slevenick marked this conversation as resolved.
Show resolved Hide resolved
return obj, nil
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
resource "google_monitoring_monitored_project" "<%= ctx[:primary_resource_id] %>" {
metrics_scope = "<%= ctx[:test_env_vars]['project_id'] %>"
name = google_project.basic.name
}

resource "google_project" "basic" {
project_id = "<%= ctx[:vars]['monitored_project'] %>"
name = "<%= ctx[:vars]['monitored_project'] %>"
org_id = "<%= ctx[:test_env_vars]['org_id'] %>"
}
17 changes: 0 additions & 17 deletions tpgtools/overrides/monitoring/beta/monitored_project.yaml

This file was deleted.

8 changes: 0 additions & 8 deletions tpgtools/overrides/monitoring/beta/tpgtools_product.yaml

This file was deleted.

17 changes: 0 additions & 17 deletions tpgtools/overrides/monitoring/monitored_project.yaml

This file was deleted.

This file was deleted.

This file was deleted.

7 changes: 0 additions & 7 deletions tpgtools/overrides/monitoring/tpgtools_product.yaml

This file was deleted.