33
44// ----------------------------------------------------------------------------
55//
6- // *** AUTO GENERATED CODE *** Type: DCL ***
6+ // *** AUTO GENERATED CODE *** Type: MMv1 ***
77//
88// ----------------------------------------------------------------------------
99//
10- // This file is managed by Magic Modules (https://github.com/GoogleCloudPlatform/magic-modules)
11- // and is based on the DCL (https://github.com/GoogleCloudPlatform/declarative-resource-client-library).
12- // Changes will need to be made to the DCL or Magic Modules instead of here.
10+ // This file is automatically generated by Magic Modules and manual
11+ // changes will be clobbered when the file is regenerated.
1312//
14- // We are not currently able to accept contributions to this file. If changes
15- // are required, please file an issue at https://github.com/hashicorp/terraform-provider-google/issues/new/choose
13+ // Please read more about how to change this file in
14+ // .github/CONTRIBUTING.md.
1615//
1716// ----------------------------------------------------------------------------
1817
1918package google
2019
2120import (
22- "context"
2321 "fmt"
24- dcl "github.com/GoogleCloudPlatform/declarative-resource-client-library/dcl"
25- monitoring "github.com/GoogleCloudPlatform/declarative-resource-client-library/services/google/monitoring/beta"
26- "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
27- "github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
22+ "strconv"
2823 "strings"
2924 "testing"
3025
26+ "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
27+ "github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
28+
3129 "github.com/hashicorp/terraform-provider-google-beta/google-beta/acctest"
3230 "github.com/hashicorp/terraform-provider-google-beta/google-beta/envvar"
31+ "github.com/hashicorp/terraform-provider-google-beta/google-beta/tpgresource"
3332 transport_tpg "github.com/hashicorp/terraform-provider-google-beta/google-beta/transport"
3433)
3534
36- func TestAccMonitoringMonitoredProject_BasicMonitoredProject (t * testing.T ) {
35+ func TestAccMonitoringMonitoredProject_monitoringMonitoredProjectBasicExample (t * testing.T ) {
3736 t .Parallel ()
3837
3938 context := map [string ]interface {}{
4039 "org_id" : envvar .GetTestOrgFromEnv (t ),
41- "project_name" : envvar .GetTestProjectFromEnv (),
40+ "project_id" : envvar .GetTestProjectFromEnv (),
4241 "random_suffix" : RandString (t , 10 ),
4342 }
4443
@@ -48,38 +47,37 @@ func TestAccMonitoringMonitoredProject_BasicMonitoredProject(t *testing.T) {
4847 CheckDestroy : testAccCheckMonitoringMonitoredProjectDestroyProducer (t ),
4948 Steps : []resource.TestStep {
5049 {
51- Config : testAccMonitoringMonitoredProject_BasicMonitoredProject (context ),
50+ Config : testAccMonitoringMonitoredProject_monitoringMonitoredProjectBasicExample (context ),
5251 },
5352 {
54- ResourceName : "google_monitoring_monitored_project.primary" ,
55- ImportState : true ,
56- ImportStateVerify : true ,
53+ ResourceName : "google_monitoring_monitored_project.primary" ,
54+ ImportState : true ,
55+ ImportStateVerify : true ,
56+ ImportStateVerifyIgnore : []string {"metrics_scope" },
5757 },
5858 },
5959 })
6060}
6161
62- func testAccMonitoringMonitoredProject_BasicMonitoredProject (context map [string ]interface {}) string {
62+ func testAccMonitoringMonitoredProject_monitoringMonitoredProjectBasicExample (context map [string ]interface {}) string {
6363 return acctest .Nprintf (`
6464resource "google_monitoring_monitored_project" "primary" {
65- metrics_scope = "%{project_name }"
65+ metrics_scope = "%{project_id }"
6666 name = google_project.basic.name
6767}
6868
6969resource "google_project" "basic" {
70- project_id = "tf-test-id%{random_suffix}"
71- name = "tf-test-id%{random_suffix}"
70+ project_id = "tf-test-m- id%{random_suffix}"
71+ name = "tf-test-m- id%{random_suffix}"
7272 org_id = "%{org_id}"
7373}
74-
75-
7674` , context )
7775}
7876
7977func testAccCheckMonitoringMonitoredProjectDestroyProducer (t * testing.T ) func (s * terraform.State ) error {
8078 return func (s * terraform.State ) error {
8179 for name , rs := range s .RootModule ().Resources {
82- if rs .Type != "rs. google_monitoring_monitored_project" {
80+ if rs .Type != "google_monitoring_monitored_project" {
8381 continue
8482 }
8583 if strings .HasPrefix (name , "data." ) {
@@ -88,23 +86,36 @@ func testAccCheckMonitoringMonitoredProjectDestroyProducer(t *testing.T) func(s
8886
8987 config := GoogleProviderConfig (t )
9088
89+ url , err := tpgresource .ReplaceVarsForTest (config , rs , "{{MonitoringBasePath}}v1/locations/global/metricsScopes/{{metrics_scope}}" )
90+ if err != nil {
91+ return err
92+ }
93+
9194 billingProject := ""
95+
9296 if config .BillingProject != "" {
9397 billingProject = config .BillingProject
9498 }
9599
96- obj := & monitoring.MonitoredProject {
97- MetricsScope : dcl .String (rs .Primary .Attributes ["metrics_scope" ]),
98- Name : dcl .String (rs .Primary .Attributes ["name" ]),
99- CreateTime : dcl .StringOrNil (rs .Primary .Attributes ["create_time" ]),
100- }
101-
102- client := transport_tpg .NewDCLMonitoringClient (config , config .UserAgent , billingProject , 0 )
103- _ , err := client .GetMonitoredProject (context .Background (), obj )
104- if err == nil {
105- return fmt .Errorf ("google_monitoring_monitored_project still exists %v" , obj )
100+ res , err := transport_tpg .SendRequest (transport_tpg.SendRequestOptions {
101+ Config : config ,
102+ Method : "GET" ,
103+ Project : billingProject ,
104+ RawURL : url ,
105+ UserAgent : config .UserAgent ,
106+ })
107+
108+ rName := tpgresource .GetResourceNameFromSelfLink (rs .Primary .Attributes ["name" ])
109+ project , err := config .NewResourceManagerClient (config .UserAgent ).Projects .Get (rName ).Do ()
110+ rName = strconv .FormatInt (project .ProjectNumber , 10 )
111+
112+ for _ , monitoredProject := range res ["monitoredProjects" ].([]any ) {
113+ if strings .HasSuffix (monitoredProject .(map [string ]any )["name" ].(string ), rName ) {
114+ return fmt .Errorf ("MonitoringMonitoredProject still exists at %s" , url )
115+ }
106116 }
107117 }
118+
108119 return nil
109120 }
110121}
0 commit comments