magic-modules
magic-modules copied to clipboard
Adding google_compute_service_attachment data source
This PR is for a new data resource that obtains the URI for a service attachment. Its based of this google api
[Issue is tracked here] (https://github.com/hashicorp/terraform-provider-google/issues/17122)
Release Note Template for Downstream PRs (will be copied)
`google_compute_service_attachment`
Hello! I am a robot. It looks like you are a: Community Contributor ~Googler~ ~Core Contributor~. Tests will require approval to run.
@NickElliot, a repository maintainer, has been assigned to review your changes. If you have not received review feedback within 2 business days, please leave a comment on this PR asking them to take a look.
You can help make sure that review is quick by doing a self-review and by running impacted tests locally.
Hi there, I'm the Modular magician. I've detected the following information about your changes:
Diff report
Your PR generated some diffs in downstreams - here they are.
Terraform GA: Diff ( 4 files changed, 253 insertions(+)) Terraform Beta: Diff ( 4 files changed, 253 insertions(+))
Tests analytics
Total tests: 874
Passed tests 808
Skipped tests: 65
Affected tests: 1
Click here to see the affected service packages
- compute
Action taken
Found 1 affected test(s) by replaying old test recordings. Starting RECORDING based on the most recent commit. Click here to see the affected tests
TestAccDataSourceGoogleServiceAttachment
$\textcolor{red}{\textsf{Tests failed during RECORDING mode:}}$
TestAccDataSourceGoogleServiceAttachment
[Error message] [Debug log]
$\textcolor{red}{\textsf{Please fix these to complete your PR.}}$ View the build log or the debug log for each test
Yes, I understood what i should do next. I was just busy with some other work. I will make these changes thank you so much.
On Thu, Feb 1, 2024 at 1:48 PM Nick Elliot @.***> wrote:
@.**** requested changes on this pull request.
Hi, the test is having an issue due to conflicting resource names. I suggested a broad formatting adjustment that should resolve this. Thanks!
In mmv1/third_party/terraform/services/compute/data_source_compute_service_attachment_test.go https://github.com/GoogleCloudPlatform/magic-modules/pull/9887#discussion_r1475188471 :
+// Copyright (c) HashiCorp, Inc. +// SPDX-License-Identifier: MPL-2.0 +package compute_test
+import (
- "fmt"
- "testing"
- "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
- "github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
- "github.com/hashicorp/terraform-provider-google/google/acctest"
- "github.com/hashicorp/terraform-provider-google/google/tpgresource" +)
+func TestAccDataSourceGoogleServiceAttachment(t *testing.T) {
- t.Parallel()
⬇️ Suggested change
- t.Parallel()
- t.Parallel()
- context := map[string]interface{}{
"random_suffix": acctest.RandString(t, 10),
- }
In mmv1/third_party/terraform/services/compute/data_source_compute_service_attachment_test.go https://github.com/GoogleCloudPlatform/magic-modules/pull/9887#discussion_r1475188707 :
+package compute_test
+import (
- "fmt"
- "testing"
- "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
- "github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
- "github.com/hashicorp/terraform-provider-google/google/acctest"
- "github.com/hashicorp/terraform-provider-google/google/tpgresource" +)
+func TestAccDataSourceGoogleServiceAttachment(t *testing.T) {
- t.Parallel()
- serviceAttachmentName := fmt.Sprintf("tf-test-%s", acctest.RandString(t, 10))
⬇️ Suggested change
- serviceAttachmentName := fmt.Sprintf("tf-test-%s", acctest.RandString(t, 10))
In mmv1/third_party/terraform/services/compute/data_source_compute_service_attachment_test.go https://github.com/GoogleCloudPlatform/magic-modules/pull/9887#discussion_r1475189371 :
- "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
- "github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
- "github.com/hashicorp/terraform-provider-google/google/acctest"
- "github.com/hashicorp/terraform-provider-google/google/tpgresource" +)
+func TestAccDataSourceGoogleServiceAttachment(t *testing.T) {
- t.Parallel()
- serviceAttachmentName := fmt.Sprintf("tf-test-%s", acctest.RandString(t, 10))
- acctest.VcrTest(t, resource.TestCase{
PreCheck: func() { acctest.AccTestPreCheck(t) },
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
Steps: []resource.TestStep{
{
Config: testAccDataSourceGoogleServiceAttachmentConfig(serviceAttachmentName),
⬇️ Suggested change
Config: testAccDataSourceGoogleServiceAttachmentConfig(serviceAttachmentName),
Config: testAccDataSourceGoogleServiceAttachmentConfig(context),
In mmv1/third_party/terraform/services/compute/data_source_compute_service_attachment_test.go https://github.com/GoogleCloudPlatform/magic-modules/pull/9887#discussion_r1475189945 :
attr_to_check,
ds_attr[attr_to_check],
rs_attr[attr_to_check],
)
}
}
if !tpgresource.CompareSelfLinkOrResourceName("", ds_attr["self_link"], rs_attr["self_link"], nil) && ds_attr["self_link"] != rs_attr["self_link"] {
return fmt.Errorf("self link does not match: %s vs %s", ds_attr["self_link"], rs_attr["self_link"])
}
return nil
- } +}
+func testAccDataSourceGoogleServiceAttachmentConfig(name string) string {
⬇️ Suggested change
-func testAccDataSourceGoogleServiceAttachmentConfig(name string) string { +func testAccDataSourceGoogleServiceAttachmentConfig(context map[string]interface{}) string {
In mmv1/third_party/terraform/services/compute/data_source_compute_service_attachment_test.go https://github.com/GoogleCloudPlatform/magic-modules/pull/9887#discussion_r1475190315 :
- load_balancing_scheme = "INTERNAL"
- backend_service = google_compute_region_backend_service.producer_service_backend.id
- all_ports = true
- network = google_compute_network.psc_ilb_network.name
- subnetwork = google_compute_subnetwork.psc_ilb_producer_subnetwork.name
- }
- resource "google_compute_region_backend_service" "producer_service_backend" {
- name = "producer-service"
- region = "us-west1"
- health_checks = [google_compute_health_check.producer_service_health_check.id]
- }
- resource "google_compute_health_check" "producer_service_health_check" {
- name = "producer-service-health-check"
⬇️ Suggested change
- name = "producer-service-health-check"
- name = "producer-service-health-check%{random_suffix}"
In mmv1/third_party/terraform/services/compute/data_source_compute_service_attachment_test.go https://github.com/GoogleCloudPlatform/magic-modules/pull/9887#discussion_r1475190423 :
- ip_cidr_range = "10.0.0.0/16"
- }
- resource "google_compute_subnetwork" "psc_ilb_nat" {
- name = "psc-ilb-nat"
- region = "us-west1"
- network = google_compute_network.psc_ilb_network.id
- purpose = "PRIVATE_SERVICE_CONNECT"
- ip_cidr_range = "10.1.0.0/16"
- } +data "google_compute_service_attachment" "my_attachment" {
- name = google_compute_service_attachment.foobar.name
- region = google_compute_service_attachment.foobar.region +} +`, name)
⬇️ Suggested change
-
, name) +
, context)
In mmv1/third_party/terraform/services/compute/data_source_compute_service_attachment_test.go https://github.com/GoogleCloudPlatform/magic-modules/pull/9887#discussion_r1475191052 :
ds_attr[attr_to_check],
rs_attr[attr_to_check],
)
}
}
if !tpgresource.CompareSelfLinkOrResourceName("", ds_attr["self_link"], rs_attr["self_link"], nil) && ds_attr["self_link"] != rs_attr["self_link"] {
return fmt.Errorf("self link does not match: %s vs %s", ds_attr["self_link"], rs_attr["self_link"])
}
return nil
- } +}
+func testAccDataSourceGoogleServiceAttachmentConfig(name string) string {
- return fmt.Sprintf(`
⬇️ Suggested change
- return fmt.Sprintf(`
- return acctest.Nprintf(`
In mmv1/third_party/terraform/services/compute/data_source_compute_service_attachment_test.go https://github.com/GoogleCloudPlatform/magic-modules/pull/9887#discussion_r1475191676 :
+}
+func testAccDataSourceGoogleServiceAttachmentConfig(name string) string {
- return fmt.Sprintf(` +resource "google_compute_service_attachment" "foobar" {
- name = "%s"
- description = "my-description"
- region = "us-west1"
- enable_proxy_protocol = true
- connection_preference = "ACCEPT_AUTOMATIC"
- nat_subnets = [google_compute_subnetwork.psc_ilb_nat.id]
- target_service = google_compute_forwarding_rule.psc_ilb_target_service.id +}
+resource "google_compute_forwarding_rule" "psc_ilb_target_service" {
- name = "producer-forwarding-rule"
⬇️ Suggested change
- name = "producer-forwarding-rule"
- name = "producer-forwarding-rule%{random_suffix}"
In mmv1/third_party/terraform/services/compute/data_source_compute_service_attachment_test.go https://github.com/GoogleCloudPlatform/magic-modules/pull/9887#discussion_r1475191977 :
)
}
}
if !tpgresource.CompareSelfLinkOrResourceName("", ds_attr["self_link"], rs_attr["self_link"], nil) && ds_attr["self_link"] != rs_attr["self_link"] {
return fmt.Errorf("self link does not match: %s vs %s", ds_attr["self_link"], rs_attr["self_link"])
}
return nil
- } +}
+func testAccDataSourceGoogleServiceAttachmentConfig(name string) string {
- return fmt.Sprintf(` +resource "google_compute_service_attachment" "foobar" {
- name = "%s"
⬇️ Suggested change
- name = "%s"
- name = "tf-test%{random_suffix}"
In mmv1/third_party/terraform/services/compute/data_source_compute_service_attachment_test.go https://github.com/GoogleCloudPlatform/magic-modules/pull/9887#discussion_r1475192316 :
- region = "us-west1"
- health_checks = [google_compute_health_check.producer_service_health_check.id]
- }
- resource "google_compute_health_check" "producer_service_health_check" {
- name = "producer-service-health-check"
- check_interval_sec = 1
- timeout_sec = 1
- tcp_health_check {
- port = "80"
- }
- }
- resource "google_compute_network" "psc_ilb_network" {
- name = "psc-ilb-network"
⬇️ Suggested change
- name = "psc-ilb-network"
- name = "psc-ilb-network%{random_suffix}"
In mmv1/third_party/terraform/services/compute/data_source_compute_service_attachment_test.go https://github.com/GoogleCloudPlatform/magic-modules/pull/9887#discussion_r1475192437 :
- resource "google_compute_health_check" "producer_service_health_check" {
- name = "producer-service-health-check"
- check_interval_sec = 1
- timeout_sec = 1
- tcp_health_check {
- port = "80"
- }
- }
- resource "google_compute_network" "psc_ilb_network" {
- name = "psc-ilb-network"
- auto_create_subnetworks = false
- }
- resource "google_compute_subnetwork" "psc_ilb_producer_subnetwork" {
- name = "psc-ilb-producer-subnetwork"
⬇️ Suggested change
- name = "psc-ilb-producer-subnetwork"
- name = "psc-ilb-producer-subnetwork%{random_suffix}"
In mmv1/third_party/terraform/services/compute/data_source_compute_service_attachment_test.go https://github.com/GoogleCloudPlatform/magic-modules/pull/9887#discussion_r1475192560 :
- }
- resource "google_compute_network" "psc_ilb_network" {
- name = "psc-ilb-network"
- auto_create_subnetworks = false
- }
- resource "google_compute_subnetwork" "psc_ilb_producer_subnetwork" {
- name = "psc-ilb-producer-subnetwork"
- region = "us-west1"
- network = google_compute_network.psc_ilb_network.id
- ip_cidr_range = "10.0.0.0/16"
- }
- resource "google_compute_subnetwork" "psc_ilb_nat" {
- name = "psc-ilb-nat"
⬇️ Suggested change
- name = "psc-ilb-nat"
- name = "psc-ilb-nat%{random_suffix}"
— Reply to this email directly, view it on GitHub https://github.com/GoogleCloudPlatform/magic-modules/pull/9887#pullrequestreview-1857697394, or unsubscribe https://github.com/notifications/unsubscribe-auth/AYIACZSMEAFI6KFG3PVXTELYRQERRAVCNFSM6AAAAABCNDZKUGVHI2DSMVQWIX3LMV43YUDVNRWFEZLROVSXG5CSMV3GSZLXHMYTQNJXGY4TOMZZGQ . You are receiving this because you authored the thread.Message ID: @.***>
I accepted all your changes. Is there anything else remaining? It says that the community-checker step is queued. @NickElliot
Hi there, I'm the Modular magician. I've detected the following information about your changes:
Diff report
Your PR generated some diffs in downstreams - here they are.
Terraform GA: Diff ( 4 files changed, 256 insertions(+)) Terraform Beta: Diff ( 4 files changed, 256 insertions(+))
Tests analytics
Total tests: 0
Passed tests 0
Skipped tests: 0
Affected tests: 0
Click here to see the affected service packages
- compute
$\textcolor{red}{\textsf{Errors occurred during REPLAYING mode. Please fix them to complete your PR}}$ View the build log
Hi there, I'm the Modular magician. I've detected the following information about your changes:
Diff report
Your PR generated some diffs in downstreams - here they are.
Terraform GA: Diff ( 4 files changed, 256 insertions(+)) Terraform Beta: Diff ( 4 files changed, 256 insertions(+))
Tests analytics
Total tests: 886
Passed tests 812
Skipped tests: 73
Affected tests: 1
Click here to see the affected service packages
- compute
Action taken
Found 1 affected test(s) by replaying old test recordings. Starting RECORDING based on the most recent commit. Click here to see the affected tests
TestAccDataSourceGoogleServiceAttachment
$\textcolor{green}{\textsf{Tests passed during RECORDING mode:}}$
TestAccDataSourceGoogleServiceAttachment
[Debug log]
Rerun these tests in REPLAYING mode to catch issues
$\textcolor{green}{\textsf{No issues found for passed tests after REPLAYING rerun.}}$
$\textcolor{green}{\textsf{All tests passed!}}$ View the build log or the debug log for each test
@NickElliot can I get some guidance on this? it passed locally, but not sure where its failing.
Also, every time I build the provider, I used to get this error message and always with these 2 resources/files . I would proceed to just replacing the file with the latest source code in github and then it would proceed with running the test case command.
@sanmaym there is almost certainly some conflict in your setup with your terraform versions -- often this sort of issue is resolved by doing the following: clean your tpg/b folders, git pull rebase your mmv1 branch on main build mmv1
now you should be able to build the provider. if your tpg version gets out of date with your mmv1 version, it can end up causing funky build problems locally even when nothing is wrong with the code (as seen by the CI passing your test)
@sanmaym there is almost certainly some conflict in your setup with your terraform versions -- often this sort of issue is resolved by doing the following: clean your tpg/b folders, git pull rebase your mmv1 branch on main build mmv1
now you should be able to build the provider. if your tpg version gets out of date with your mmv1 version, it can end up causing funky build problems locally even when nothing is wrong with the code (as seen by the CI passing your test)
@NickElliot I'm facing some challenges now. When I pull from upstream to get latest tpg updates, it didnt work. So, I just manually copied over the tpg directory from remote main to my local main. When I tried to build again, i'm seeing this error message
for terraform
I, [2024-02-12T00:34:04.218685 #18239] INFO -- : Compiling common files for terraform
make[1]: Leaving directory '/magic-modules'
make tpgtools
make[1]: Entering directory '/magic-modules'
make serialize
make[2]: Entering directory '/magic-modules'
cd tpgtools;\
cp -f serialization.go.base serialization.go &&\
go run . --path "api" --overrides "overrides" --mode "serialization" > temp.serial &&\
mv -f temp.serial serialization.go
**go: cannot find main module, but found .git/config in /magic-modules**
to create a module there, run:
cd .. && go mod init
Any thoughts?
Also , I have a second question about your comment here Just run the gofmt on /google/services/compute/data_source_compute_service_attachment_test.go and this PR will be ready to go.
This file is in the terraform provider that gets built right? As per my understanding, I only raise the PR from my magic modules repo. Then, what is the purpose of running the gofmt command there?
any thoughts @NickElliot ?
sorry for the delay, I went on PTO a couple days before your updates and didn't flag this PR to another reviewer, my bad!
cd tpgtools;
cp -f serialization.go.base serialization.go &&
go run . --path "api" --overrides "overrides" --mode "serialization" > temp.serial &&
mv -f temp.serial serialization.go
go: cannot find main module, but found .git/config in /home/runner/work/magic-modules/magic-modules
to create a module there, run:
cd .. && go mod init
This error is still remaining
/gcbrun
please rebase your changes on top of head again or cherry pick your changes to a fresh branch, your pr is very broken now, having combined in a mix of existing main branch commits/your own
@sanmaym, this PR is waiting for action from you. Please address any comments or change requests, or re-request review from a core reviewer if no action is required.
If no action is taken, this PR will be closed in 14 days.
This notification can be disabled with the disable-automatic-closure
label.
@sanmaym, this PR is waiting for action from you. Please address any comments or change requests, or re-request review from a core reviewer if no action is required.
If no action is taken, this PR will be closed in 2 weekdays.
This notification can be disabled with the disable-automatic-closure
label.
@sanmaym, this PR is being closed due to inactivity.