Skip to content

Conversation

@SarahFrench
Copy link
Contributor

@SarahFrench SarahFrench commented Sep 20, 2022

Closes hashicorp/terraform-provider-google#12610
also, closes hashicorp/terraform-provider-google#13667

The main change in this PR is removing this GA-only logic in the test template mmv1/templates/terraform/examples/base_configs/iam_test_file.go.erb

This change introduces import steps into beta IAM resources' tests, and a lot of those tests fail because of missing data in the YAML.

As a result of those failing tests I have added missing data where I can and I've renamed some variables for clarity and consistency.


If this PR is for Terraform, I acknowledge that I have:

  • Searched through the issue tracker for an open issue that this either resolves or contributes to, commented on it to claim it, and written "fixes {url}" or "part of {url}" in this PR description. If there were no relevant open issues, I opened one and commented that I would like to work on it (not necessary for very small changes).
  • Generated Terraform, and ran make test and make lint to ensure it passes unit and linter tests.
  • Ensured that all new fields I added that can be set by a user appear in at least one example (for generated resources) or third_party test (for handwritten resources or update tests).
  • Ran relevant acceptance tests (If the acceptance tests do not yet pass or you are unable to run them, please let your reviewer know).
  • Read the Release Notes Guide before writing my release note below.

Release Note Template for Downstream PRs (will be copied)


@modular-magician
Copy link
Collaborator

Hello! I am a robot who works on Magic Modules PRs.

I've detected that you're a community contributor. @c2thorn, a repository maintainer, has been assigned to assist you and help review your changes.

❓ First time contributing? Click here for more details

Your assigned reviewer will help review your code by:

  • Ensuring it's backwards compatible, covers common error cases, etc.
  • Summarizing the change into a user-facing changelog note.
  • Passes tests, either our "VCR" suite, a set of presubmit tests, or with manual test runs.

You can help make sure that review is quick by running local tests and ensuring they're passing in between each push you make to your PR's branch. Also, try to leave a comment with each push you make, as pushes generally don't generate emails.

If your reviewer doesn't get back to you within a week after your most recent change, please feel free to leave a comment on the issue asking them to take a look! In the absence of a dedicated review dashboard most maintainers manage their pending reviews through email, and those will sometimes get lost in their inbox.


@SarahFrench SarahFrench removed the request for review from c2thorn September 20, 2022 19:17
@modular-magician
Copy link
Collaborator

Hi! I'm the modular magician. Your PR generated some diffs in downstreams - here they are.

Diff report:

Terraform Beta: Diff ( 11 files changed, 441 insertions(+), 58 deletions(-))

@modular-magician
Copy link
Collaborator

Tests analytics

Total tests: 0
Passed tests 0
Skipped tests: 0
Failed tests: 0

Errors occurred during REPLAYING mode. Please fix them to complete your PR
View the build log

@SarahFrench
Copy link
Contributor Author

SarahFrench commented Sep 21, 2022

google-beta/iam_compute_machine_image_generated_test.go:144:123: expected operand, found ','

Error from terraform-provider-google-beta-test check

Corresponds to this template code

ImportStateId:     fmt.Sprintf("<%= import_url -%> <%= object.iam_policy.allowed_iam_role -%> %s"<% unless import_qualifiers.empty? -%>, <% end -%><%= import_qualifiers.join(', ') -%>, <%= example.primary_resource_name -%>, context["condition_title"]),

producing this Go code:

ImportStateId:     fmt.Sprintf("projects/%s/global/machineImages/%s roles/compute.admin %s", getTestProjectFromEnv(), , context["condition_title"]),

Looks like the ga-only logic is needed due to beta versions lacking data like example.primary_resource_name in the yaml files.

This appears to only be true for some resources, so I think it may be a case of adding the missing data to the terraform.yaml files for the affected resources instead of closing this PR. I'll follow this up later...

@SarahFrench SarahFrench force-pushed the iam-test-template-rm-ga-only-logic branch from bef688b to 9ff2989 Compare January 13, 2023 18:02
@modular-magician
Copy link
Collaborator

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 Beta: Diff ( 11 files changed, 477 insertions(+), 83 deletions(-))

@modular-magician
Copy link
Collaborator

Tests analytics

Total tests: 0
Passed tests 0
Skipped tests: 0
Failed tests: 0

Errors occurred during REPLAYING mode. Please fix them to complete your PR
View the build log

@SarahFrench
Copy link
Contributor Author

Rebased this PR as it's quite old (3-4months)

@SarahFrench
Copy link
Contributor Author

API Gateway tests are being more of a pain - need to provide parent resource name when building the ImportStateId and it doesn't seem like the template handles this. Decision about whether to address quickly or whether bigger changes needed...

@modular-magician
Copy link
Collaborator

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 Beta: Diff ( 11 files changed, 395 insertions(+))

@modular-magician
Copy link
Collaborator

Tests analytics

Total tests: 0
Passed tests 0
Skipped tests: 0
Failed tests: 0

Errors occurred during REPLAYING mode. Please fix them to complete your PR
View the build log

…dded to vars by including a hyphen in their value, add missing `primary_resource_name` properties

`primary_resource_name` values need to pass both the name of a parent resource and the name of the primary resource, as both are used to template out the full id of the resource.

Values of vars need to have `-` in them to trigger `tf-test-` being added to the start. Random string is added to the end automatically too. Making this uniform was important to know the value to define in the `primary_resource_name` values
@SarahFrench
Copy link
Contributor Author

In the most recent commit I had a go fixing the acceptance tests that fail the 'new' test code (that's now included due to removing ga-only logic).

I changed the names and values of a bunch of var values and I learned about this code:

rand_vars = vars.map do |k, v|
# Some resources only allow underscores.
testv = if v.include?('-')
"tf-test-#{v}"
elsif v.include?('_')
"tf_test_#{v}"
else
# Some vars like descriptions shouldn't have prefix
v
end
# Random suffix is 10 characters and standard name length <= 64
testv = "#{testv[0...54]}%{random_suffix}"
[k, testv]
end

It prepends tf-test- to vars only if the name already contains dashes. So I spent some time manually adding that prefix to var values, seeing that code generation added a second identical prefix, and then when I removed the hardcoded tf-test- I saw the automated addition of tf-test- also disappeared. Very annoying! The result is that I've left dangling dashes on the var values so that it triggers the automation.

@modular-magician
Copy link
Collaborator

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 ( 3 files changed, 8 insertions(+), 8 deletions(-))
Terraform Beta: Diff ( 17 files changed, 449 insertions(+), 54 deletions(-))
TF Validator: Diff ( 2 files changed, 3 insertions(+), 3 deletions(-))
TF OiCS: Diff ( 8 files changed, 16 insertions(+), 16 deletions(-))

@modular-magician
Copy link
Collaborator

Tests analytics

Total tests: 2424
Passed tests 2125
Skipped tests: 254
Failed tests: 45

Action taken

Triggering VCR tests in RECORDING mode for the tests that failed during VCR. Click here to see the failed tests
TestAccComputeMachineImageIamPolicyGenerated_withCondition|TestAccComputeMachineImageIamPolicyGenerated|TestAccComputeMachineImageIamBindingGenerated|TestAccComputeMachineImageIamBindingGenerated_withCondition|TestAccComputeMachineImageIamMemberGenerated|TestAccComputeMachineImageIamMemberGenerated_withCondition|TestAccBigqueryDatapolicyDataPolicyIamMemberGenerated|TestAccBigqueryDatapolicyDataPolicyIamPolicyGenerated|TestAccApiGatewayGatewayIamMemberGenerated|TestAccApiGatewayGatewayIamPolicyGenerated|TestAccApiGatewayGatewayIamBindingGenerated|TestAccApiGatewayApiIamPolicyGenerated|TestAccApiGatewayApiIamMemberGenerated|TestAccApiGatewayApiIamBindingGenerated|TestAccApiGatewayApiConfigIamPolicyGenerated|TestAccApiGatewayApiConfigIamMemberGenerated|TestAccApiGatewayApiConfigIamBindingGenerated|TestAccCloudfunctions2function_cloudfunctions2BasicGcsExample|TestAccApiGatewayApiConfig_apigatewayApiConfigGrpcFullExample|TestAccApiGatewayApiConfig_apigatewayApiConfigGrpcExample|TestAccApiGatewayApiConfig_apigatewayApiConfigFullExample|TestAccApiGatewayApiConfig_apigatewayApiConfigBasicExample|TestAccApiGatewayGateway_apigatewayGatewayFullExample|TestAccApiGatewayGateway_apigatewayGatewayBasicExample|TestAccServiceDirectoryServiceIamPolicyGenerated|TestAccServiceDirectoryNamespaceIamMemberGenerated|TestAccServiceDirectoryNamespaceIamBindingGenerated|TestAccApiGatewayApi_apigatewayApiBasicExampleUpdated|TestAccServiceDirectoryServiceIamMemberGenerated|TestAccServiceDirectoryServiceIamBindingGenerated|TestAccServiceDirectoryNamespaceIamPolicyGenerated|TestAccRuntimeConfigConfigIamPolicyGenerated|TestAccApiGatewayApi_apigatewayApiFullExample|TestAccApiGatewayApi_apigatewayApiBasicExample|TestAccDataprocMetastoreFederationIamPolicyGenerated|TestAccDataprocMetastoreFederationIamMemberGenerated|TestAccApiGatewayApiConfig_apigatewayApiConfigBasicExampleUpdated|TestAccDataCatalogTaxonomyIamMemberGenerated|TestAccDataCatalogTaxonomyIamBindingGenerated|TestAccDataCatalogPolicyTagIamPolicyGenerated|TestAccDataCatalogPolicyTagIamMemberGenerated|TestAccApiGatewayGateway_apigatewayGatewayBasicExampleUpdated|TestAccDataprocMetastoreFederationIamBindingGenerated|TestAccDataCatalogTaxonomyIamPolicyGenerated|TestAccDataCatalogPolicyTagIamBindingGenerated

@modular-magician
Copy link
Collaborator

Tests passed during RECORDING mode:
TestAccBigqueryDatapolicyDataPolicyIamMemberGenerated[Debug log]
TestAccBigqueryDatapolicyDataPolicyIamPolicyGenerated[Debug log]
TestAccApiGatewayGatewayIamMemberGenerated[Debug log]
TestAccApiGatewayGatewayIamPolicyGenerated[Debug log]
TestAccApiGatewayGatewayIamBindingGenerated[Debug log]
TestAccApiGatewayApiIamPolicyGenerated[Debug log]
TestAccApiGatewayApiIamMemberGenerated[Debug log]
TestAccApiGatewayApiIamBindingGenerated[Debug log]
TestAccApiGatewayApiConfig_apigatewayApiConfigFullExample[Debug log]
TestAccApiGatewayApiConfig_apigatewayApiConfigBasicExample[Debug log]
TestAccApiGatewayGateway_apigatewayGatewayFullExample[Debug log]
TestAccApiGatewayGateway_apigatewayGatewayBasicExample[Debug log]
TestAccApiGatewayApi_apigatewayApiBasicExampleUpdated[Debug log]
TestAccRuntimeConfigConfigIamPolicyGenerated[Debug log]
TestAccApiGatewayApi_apigatewayApiFullExample[Debug log]
TestAccApiGatewayApi_apigatewayApiBasicExample[Debug log]
TestAccApiGatewayApiConfig_apigatewayApiConfigBasicExampleUpdated[Debug log]
TestAccApiGatewayGateway_apigatewayGatewayBasicExampleUpdated[Debug log]

Tests failed during RECORDING mode:
TestAccComputeMachineImageIamPolicyGenerated_withCondition[Error message] [Debug log]
TestAccComputeMachineImageIamPolicyGenerated[Error message] [Debug log]
TestAccComputeMachineImageIamBindingGenerated[Error message] [Debug log]
TestAccComputeMachineImageIamBindingGenerated_withCondition[Error message] [Debug log]
TestAccComputeMachineImageIamMemberGenerated[Error message] [Debug log]
TestAccComputeMachineImageIamMemberGenerated_withCondition[Error message] [Debug log]
TestAccApiGatewayApiConfigIamPolicyGenerated[Error message] [Debug log]
TestAccApiGatewayApiConfigIamMemberGenerated[Error message] [Debug log]
TestAccApiGatewayApiConfigIamBindingGenerated[Error message] [Debug log]
TestAccCloudfunctions2function_cloudfunctions2BasicGcsExample[Error message] [Debug log]
TestAccApiGatewayApiConfig_apigatewayApiConfigGrpcFullExample[Error message] [Debug log]
TestAccApiGatewayApiConfig_apigatewayApiConfigGrpcExample[Error message] [Debug log]
TestAccServiceDirectoryServiceIamPolicyGenerated[Error message] [Debug log]
TestAccServiceDirectoryNamespaceIamMemberGenerated[Error message] [Debug log]
TestAccServiceDirectoryNamespaceIamBindingGenerated[Error message] [Debug log]
TestAccServiceDirectoryServiceIamMemberGenerated[Error message] [Debug log]
TestAccServiceDirectoryServiceIamBindingGenerated[Error message] [Debug log]
TestAccServiceDirectoryNamespaceIamPolicyGenerated[Error message] [Debug log]
TestAccDataprocMetastoreFederationIamPolicyGenerated[Error message] [Debug log]
TestAccDataprocMetastoreFederationIamMemberGenerated[Error message] [Debug log]
TestAccDataCatalogTaxonomyIamMemberGenerated[Error message] [Debug log]
TestAccDataCatalogTaxonomyIamBindingGenerated[Error message] [Debug log]
TestAccDataCatalogPolicyTagIamPolicyGenerated[Error message] [Debug log]
TestAccDataCatalogPolicyTagIamMemberGenerated[Error message] [Debug log]
TestAccDataprocMetastoreFederationIamBindingGenerated[Error message] [Debug log]
TestAccDataCatalogTaxonomyIamPolicyGenerated[Error message] [Debug log]
TestAccDataCatalogPolicyTagIamBindingGenerated[Error message] [Debug log]

Please fix these to complete your PR
View the build log or the debug log for each test

@SarahFrench
Copy link
Contributor Author

At least the code builds now!

@SarahFrench
Copy link
Contributor Author

SarahFrench commented Jan 24, 2023

Service directory IAM acceptance tests are a pain to update - around use of name that takes a value of the full ID of the resource and then correctly templating the URL for the resource using that.

Have issues with URL that repeats like project/x/location/x/namespace/x/service/project/x/location/x/namespace/x/service/x

@modular-magician
Copy link
Collaborator

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 ( 5 files changed, 16 insertions(+), 20 deletions(-))
Terraform Beta: Diff ( 22 files changed, 462 insertions(+), 71 deletions(-))
TF Validator: Diff ( 2 files changed, 3 insertions(+), 3 deletions(-))
TF OiCS: Diff ( 8 files changed, 16 insertions(+), 16 deletions(-))

@modular-magician
Copy link
Collaborator

Tests analytics

Total tests: 0
Passed tests 0
Skipped tests: 0
Failed tests: 0

Errors occurred during REPLAYING mode. Please fix them to complete your PR
View the build log

@modular-magician
Copy link
Collaborator

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 ( 5 files changed, 20 insertions(+), 20 deletions(-))
Terraform Beta: Diff ( 22 files changed, 466 insertions(+), 71 deletions(-))
TF Validator: Diff ( 2 files changed, 3 insertions(+), 3 deletions(-))
TF OiCS: Diff ( 8 files changed, 16 insertions(+), 16 deletions(-))

@SarahFrench
Copy link
Contributor Author

SarahFrench commented Jan 26, 2023

Import of DataCatalogTaxonomy resources is blocked, because the ID of the resource isn't determined by the config made by users. This is also the case for DataCatalogPolicyTag acceptance tests, because the parent resource used by those tests has the same identification issue.

In the example below you set display_name but it is just a display name.

resource "google_data_catalog_taxonomy" "basic_taxonomy" {
  provider = google-beta
  region = "us"
  display_name =  "tf_test_my_display_name"
  description = "A collection of policy tags"
  activated_policy_types = ["FINE_GRAINED_ACCESS_CONTROL"]
}

Given the HCL above, instead of having a name like this:

projects/PROJECT_ID/locations/us/taxonomies/tf_test_my_display_name

instead it's like this:

projects/PROJECT_ID/locations/us/taxonomies/12345678910

Where the number is returned from the API. Because of this, we would need to get data out of the test to configure the next test step that tests imports, and currently this isn't possible

@modular-magician
Copy link
Collaborator

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 ( 8 files changed, 31 insertions(+), 28 deletions(-))
Terraform Beta: Diff ( 27 files changed, 515 insertions(+), 117 deletions(-))
TF Validator: Diff ( 2 files changed, 3 insertions(+), 3 deletions(-))
TF OiCS: Diff ( 12 files changed, 24 insertions(+), 24 deletions(-))

@modular-magician
Copy link
Collaborator

Tests analytics

Total tests: 2430
Passed tests 2161
Skipped tests: 254
Failed tests: 15

Action taken

Triggering VCR tests in RECORDING mode for the tests that failed during VCR. Click here to see the failed tests
TestAccRegionInstanceGroupManager_stateful|TestAccContainerCluster_failedCreation|TestAccServiceDirectoryNamespaceIamBindingGenerated|TestAccServiceDirectoryServiceIamPolicyGenerated|TestAccServiceDirectoryServiceIamMemberGenerated|TestAccServiceDirectoryServiceIamBindingGenerated|TestAccServiceDirectoryNamespaceIamMemberGenerated|TestAccDataCatalogTaxonomyIamPolicyGenerated|TestAccDataCatalogTaxonomyIamMemberGenerated|TestAccDataCatalogPolicyTagIamPolicyGenerated|TestAccDataCatalogTaxonomyIamBindingGenerated|TestAccDataCatalogPolicyTagIamBindingGenerated|TestAccServiceDirectoryNamespaceIamPolicyGenerated|TestAccDataCatalogPolicyTagIamMemberGenerated|TestAccFirebaserulesRelease_BasicRelease

@modular-magician
Copy link
Collaborator

Tests passed during RECORDING mode:
TestAccContainerCluster_failedCreation[Debug log]
TestAccFirebaserulesRelease_BasicRelease[Debug log]

Tests failed during RECORDING mode:
TestAccRegionInstanceGroupManager_stateful[Error message] [Debug log]
TestAccServiceDirectoryNamespaceIamBindingGenerated[Error message] [Debug log]
TestAccServiceDirectoryServiceIamPolicyGenerated[Error message] [Debug log]
TestAccServiceDirectoryServiceIamMemberGenerated[Error message] [Debug log]
TestAccServiceDirectoryServiceIamBindingGenerated[Error message] [Debug log]
TestAccServiceDirectoryNamespaceIamMemberGenerated[Error message] [Debug log]
TestAccDataCatalogTaxonomyIamPolicyGenerated[Error message] [Debug log]
TestAccDataCatalogTaxonomyIamMemberGenerated[Error message] [Debug log]
TestAccDataCatalogPolicyTagIamPolicyGenerated[Error message] [Debug log]
TestAccDataCatalogTaxonomyIamBindingGenerated[Error message] [Debug log]
TestAccDataCatalogPolicyTagIamBindingGenerated[Error message] [Debug log]
TestAccServiceDirectoryNamespaceIamPolicyGenerated[Error message] [Debug log]
TestAccDataCatalogPolicyTagIamMemberGenerated[Error message] [Debug log]

Please fix these to complete your PR
View the build log or the debug log for each test

@modular-magician
Copy link
Collaborator

Hi there, I'm the Modular magician. I've detected the following information about your changes:

Breaking Change(s) Detected

The following breaking change(s) were detected within your pull request.

  • Field name within resource google_service_directory_namespace_iam_binding was either removed or renamed - reference
  • Field name within resource google_service_directory_namespace_iam_member was either removed or renamed - reference
  • Field name within resource google_service_directory_namespace_iam_policy was either removed or renamed - reference

If you believe this detection to be incorrect please raise the concern with your reviewer. If you intend to make this change you will need to wait for a major release window. An override-breaking-change label can be added to allow merging.

Diff report

Your PR generated some diffs in downstreams - here they are.

Terraform GA: Diff ( 8 files changed, 32 insertions(+), 26 deletions(-))
Terraform Beta: Diff ( 27 files changed, 596 insertions(+), 139 deletions(-))
TF Validator: Diff ( 2 files changed, 3 insertions(+), 3 deletions(-))
TF OiCS: Diff ( 12 files changed, 24 insertions(+), 24 deletions(-))

@SarahFrench
Copy link
Contributor Author

Breaking change is expected - I'm going to get feedback from my reviewer about how to address the IAM tests where code generate doesn't seem to place nicely with name fields (probably works fine if name is a long-form id, breaks when it's short-form)

@modular-magician
Copy link
Collaborator

Tests analytics

Total tests: 2435
Passed tests 2168
Skipped tests: 254
Failed tests: 13

Action taken

Triggering VCR tests in RECORDING mode for the tests that failed during VCR. Click here to see the failed tests
TestAccContainerCluster_failedCreation|TestAccServiceDirectoryServiceIamBindingGenerated|TestAccServiceDirectoryServiceIamPolicyGenerated|TestAccServiceDirectoryNamespaceIamMemberGenerated|TestAccServiceDirectoryServiceIamMemberGenerated|TestAccServiceDirectoryNamespaceIamPolicyGenerated|TestAccDataCatalogPolicyTagIamPolicyGenerated|TestAccDataCatalogPolicyTagIamBindingGenerated|TestAccDataCatalogPolicyTagIamMemberGenerated|TestAccDataCatalogTaxonomyIamPolicyGenerated|TestAccDataCatalogTaxonomyIamMemberGenerated|TestAccDataCatalogTaxonomyIamBindingGenerated|TestAccFirebaserulesRelease_BasicRelease

@modular-magician
Copy link
Collaborator

Tests passed during RECORDING mode:
TestAccContainerCluster_failedCreation[Debug log]
TestAccServiceDirectoryNamespaceIamMemberGenerated[Debug log]
TestAccServiceDirectoryNamespaceIamPolicyGenerated[Debug log]
TestAccFirebaserulesRelease_BasicRelease[Debug log]

Tests failed during RECORDING mode:
TestAccServiceDirectoryServiceIamBindingGenerated[Error message] [Debug log]
TestAccServiceDirectoryServiceIamPolicyGenerated[Error message] [Debug log]
TestAccServiceDirectoryServiceIamMemberGenerated[Error message] [Debug log]
TestAccDataCatalogPolicyTagIamPolicyGenerated[Error message] [Debug log]
TestAccDataCatalogPolicyTagIamBindingGenerated[Error message] [Debug log]
TestAccDataCatalogPolicyTagIamMemberGenerated[Error message] [Debug log]
TestAccDataCatalogTaxonomyIamPolicyGenerated[Error message] [Debug log]
TestAccDataCatalogTaxonomyIamMemberGenerated[Error message] [Debug log]
TestAccDataCatalogTaxonomyIamBindingGenerated[Error message] [Debug log]

Please fix these to complete your PR
View the build log or the debug log for each test

@SarahFrench
Copy link
Contributor Author

SarahFrench commented Jan 27, 2023

☝️ The breaking changes make the tests pass the import steps, but it's a breaking change. I'm prepared to revert bfcde13 but I don't know what the 'proper' solution is. I'm a bit stumped about how to make the ServiceDirectoryNamespace and ServiceDirectoryService (which is a child of Namespace and affected by the same issue) acceptance tests pass. Opening up the PR for review and feedback!

Also, the DataCatalog* tests don't seem to be resolvable due to the API creating an identifier for resource during create, and so that information isn't available when configuring the import step in the acceptance test's code (see comment).

primary_resource_name: "fmt.Sprintf(\"tf-test-api-%s\", context[\"random_suffix\"])"
vars:
name: "api"
api_id: "api-"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Note: dangling dash characters are here to trigger logic that automatically adds tf-test- at the start of the value in the templated HCL used in the test. Having a - present is necessary for this.

Copy link
Member

Choose a reason for hiding this comment

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

yeah, this is an unfortunate "feature". one way to make this look cleaner is to add a prefix like my-api

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah that's a good idea, I'll push a commit making these vars have prefixes after discussion about the issue(s) with ServiceDirectory tests is concluded - I don't want to make the PR timeline more disjointed!

Copy link
Member

Choose a reason for hiding this comment

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

👍 Alternately / additionally, I'd be happy to approve the straightforward bits in a separate PR while we sort out the complicated bits here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That sounds like the better solution - this PR ballooned a lot from the original intention

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Here's the new PR - it contains everything in this PR and leaves servicedirectory and datacatalog untouched other than changes needed to let the new import steps in those tests build (pass correct number of args into fmt.Sprintf).

There are failing VCR tests for servicedirectory and datacatalog, but those would be addressed in this PR

Comment on lines -41 to +46
parent_resource_attribute: 'name'
parent_resource_attribute: 'namespace_id'
method_name_separator: ':'
fetch_iam_policy_verb: :POST
set_iam_policy_verb: :POST
base_url: "projects/{{project}}/locations/{{location}}/namespaces/{{namespace_id}}"
import_format: ["projects/{{project}}/locations/{{location}}/namespaces/{{namespace_id}}"]
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is a breaking change 💔

The error that happens with the old code is that there's a 404 when trying to get the IAM policy on the Namespace:

POST /v1beta1/tf-test-example-namespace6agdt0mwhx:getIamPolicy?alt=json

This appears to be due to the qualifyNamespaceUrl function producing the wrong URL that lacks project/location etc info. I tried updating the test to have a long-form name so the URL is complete but it didn't work for me and I figured it was worth getting some advice!

Copy link
Member

Choose a reason for hiding this comment

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

yeah, this is definitely a breaking change for users of this resource. Basically to justify this change in a minor release we need to be reasonably sure that if someone was using a configuration with name it just wouldn't work for them - is that the case here? Like, can these IAM resources be used to set the IAM policy but then not get or update it, or do they just not work at all?

Copy link
Member

Choose a reason for hiding this comment

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

Just to double-check, does setting base_url & import_format to just contain {{name}} work?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Just to double-check, does setting base_url & import_format to just contain {{name}} work?

When this is set for the Namespace resource and I run the TestAccServiceDirectoryNamespaceIamMemberGenerated test it fails on the first step (test_step_number=1 mentioned in the copy/paste output below) because it's making a POST request to /v1beta1/projects:getIamPolicy?alt=json instead of /v1beta1/projects/XXX/locations/XXX/namespaces/tf-test-xxx:getIamPolicy?alt=json

2023-01-27T17:28:41.786Z [WARN]  sdk.helper_resource: Error running Terraform CLI command: test_step_number=1
  error=
  | exit status 1
  | 
  | Error: Error retrieving IAM policy for servicedirectory namespace "projects": googleapi: got HTTP response code 404 with body: <!DOCTYPE html>
  | <html lang=en>
  |   <meta charset=utf-8>
  |   <meta name=viewport content="initial-scale=1, minimum-scale=1, width=device-width">
  |   <title>Error 404 (Not Found)!!1</title>
  |   <style>
  |     *{margin:0;padding:0}html,code{font:15px/22px arial,sans-serif}html{background:#fff;color:#222;padding:15px}body{margin:7% auto 0;max-width:390px;min-height:180px;padding:30px 0 15px}* > body{background:url(//www.google.com/images/errors/robot.png) 100% 5px no-repeat;padding-right:205px}p{margin:11px 0 22px;overflow:hidden}ins{color:#777;text-decoration:none}a img{border:0}@media screen and (max-width:772px){body{background:none;margin-top:0;max-width:none;padding-right:0}}#logo{background:url(//www.google.com/images/branding/googlelogo/1x/googlelogo_color_150x54dp.png) no-repeat;margin-left:-5px}@media only screen and (min-resolution:192dpi){#logo{background:url(//www.google.com/images/branding/googlelogo/2x/googlelogo_color_150x54dp.png) no-repeat 0% 0%/100% 100%;-moz-border-image:url(//www.google.com/images/branding/googlelogo/2x/googlelogo_color_150x54dp.png) 0}}@media only screen and (-webkit-min-device-pixel-ratio:2){#logo{background:url(//www.google.com/images/branding/googlelogo/2x/googlelogo_color_150x54dp.png) no-repeat;-webkit-background-size:100% 100%}}#logo{display:inline-block;height:54px;width:150px}
  |   </style>
  |   <a href=//www.google.com/><span id=logo aria-label=Google></span></a>
  |   <p><b>404.</b> <ins>That’s an error.</ins>
  |   <p>The requested URL <code>/v1beta1/projects:getIamPolicy?alt=json</code> was not found on this server.  <ins>That’s all we know.</ins>
  | 
  | 
  |   with google_service_directory_namespace_iam_member.foo,
  |   on terraform_plugin_test.tf line 14, in resource "google_service_directory_namespace_iam_member" "foo":
  |   14: resource "google_service_directory_namespace_iam_member" "foo" {

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Basically to justify this change in a minor release we need to be reasonably sure that if someone was using a configuration with name it just wouldn't work for them - is that the case here? Like, can these IAM resources be used to set the IAM policy but then not get or update it, or do they just not work at all?

I manually tested creating a google_service_directory_namespace and a google_service_directory_namespace_iam_binding resource and can create and update the iam_binding without any errors. I'm not sure why there isn't a 404 like in the tests 😕

Something that doesn't seem to work is import of google_service_directory_namespace_iam_binding:

resource "google_service_directory_namespace" "example" {
  provider     = google-beta
  namespace_id = "tf-test-example-namespace-sarahfrench"
  location     = "us-central1"

  labels = {
    key = "value"
    foo = "bar"
  }
}

resource "google_service_directory_namespace_iam_binding" "foo" {
  provider = google-beta
  name     = google_service_directory_namespace.example.name
  role     = "roles/viewer"
  members  = ["user:[email protected]"]
}

After applying the plan to create these I then remove it from state and attempt to import the binding following the provider docs and it fails:

terraform state rm google_service_directory_namespace_iam_binding.foo
# works

terraform import google_service_directory_namespace_iam_binding.foo "projects/[PROJECT_ID]/locations/us-central1/namespaces/tf-test-example-namespace-sarahfrench roles/viewer"

# Error: Import id "" doesn't match any of the accepted formats: [projects/(?P<project>[^/]+)/locations/(?P<location>[^/]+)/namespaces/(?P<namespace_id>[^/]+) (?P<project>[^/]+)/(?P<location>[^/]+)/(?P<namespace_id>[^/]+) (?P<location>[^/]+)/(?P<namespace_id>[^/]+)]

@SarahFrench SarahFrench marked this pull request as ready for review January 27, 2023 15:25
@SarahFrench SarahFrench requested a review from melinath January 27, 2023 15:26
@modular-magician
Copy link
Collaborator

Hi there, I'm the Modular magician. I've detected the following information about your changes:

Breaking Change(s) Detected

The following breaking change(s) were detected within your pull request.

  • Field name within resource google_service_directory_namespace_iam_binding was either removed or renamed - reference
  • Field name within resource google_service_directory_namespace_iam_member was either removed or renamed - reference
  • Field name within resource google_service_directory_namespace_iam_policy was either removed or renamed - reference

If you believe this detection to be incorrect please raise the concern with your reviewer. If you intend to make this change you will need to wait for a major release window. An override-breaking-change label can be added to allow merging.

Diff report

Your PR generated some diffs in downstreams - here they are.

Terraform GA: Diff ( 8 files changed, 32 insertions(+), 26 deletions(-))
Terraform Beta: Diff ( 27 files changed, 596 insertions(+), 139 deletions(-))
TF Validator: Diff ( 2 files changed, 3 insertions(+), 3 deletions(-))
TF OiCS: Diff ( 12 files changed, 24 insertions(+), 24 deletions(-))

@modular-magician
Copy link
Collaborator

Tests analytics

Total tests: 2435
Passed tests 2170
Skipped tests: 254
Failed tests: 11

Action taken

Triggering VCR tests in RECORDING mode for the tests that failed during VCR. Click here to see the failed tests
TestAccRegionInstanceGroupManager_stateful|TestAccContainerCluster_failedCreation|TestAccServiceDirectoryServiceIamBindingGenerated|TestAccServiceDirectoryServiceIamPolicyGenerated|TestAccDataCatalogTaxonomyIamPolicyGenerated|TestAccDataCatalogPolicyTagIamPolicyGenerated|TestAccServiceDirectoryServiceIamMemberGenerated|TestAccDataCatalogTaxonomyIamMemberGenerated|TestAccDataCatalogTaxonomyIamBindingGenerated|TestAccDataCatalogPolicyTagIamMemberGenerated|TestAccDataCatalogPolicyTagIamBindingGenerated

@modular-magician
Copy link
Collaborator

Tests passed during RECORDING mode:
TestAccContainerCluster_failedCreation[Debug log]

Tests failed during RECORDING mode:
TestAccRegionInstanceGroupManager_stateful[Error message] [Debug log]
TestAccServiceDirectoryServiceIamBindingGenerated[Error message] [Debug log]
TestAccServiceDirectoryServiceIamPolicyGenerated[Error message] [Debug log]
TestAccDataCatalogTaxonomyIamPolicyGenerated[Error message] [Debug log]
TestAccDataCatalogPolicyTagIamPolicyGenerated[Error message] [Debug log]
TestAccServiceDirectoryServiceIamMemberGenerated[Error message] [Debug log]
TestAccDataCatalogTaxonomyIamMemberGenerated[Error message] [Debug log]
TestAccDataCatalogTaxonomyIamBindingGenerated[Error message] [Debug log]
TestAccDataCatalogPolicyTagIamMemberGenerated[Error message] [Debug log]
TestAccDataCatalogPolicyTagIamBindingGenerated[Error message] [Debug log]

Please fix these to complete your PR
View the build log or the debug log for each test

@SarahFrench SarahFrench changed the title Allow import steps in beta IAM resources Allow import steps in beta IAM resource tests - failing tests Jan 28, 2023
@SarahFrench
Copy link
Contributor Author

Latest commit closes hashicorp/terraform-provider-google#13667

@modular-magician
Copy link
Collaborator

Hi there, I'm the Modular magician. I've detected the following information about your changes:

Breaking Change(s) Detected

The following breaking change(s) were detected within your pull request.

  • Field name within resource google_service_directory_namespace_iam_binding was either removed or renamed - reference
  • Field name within resource google_service_directory_namespace_iam_member was either removed or renamed - reference
  • Field name within resource google_service_directory_namespace_iam_policy was either removed or renamed - reference

If you believe this detection to be incorrect please raise the concern with your reviewer. If you intend to make this change you will need to wait for a major release window. An override-breaking-change label can be added to allow merging.

Diff report

Your PR generated some diffs in downstreams - here they are.

Terraform GA: Diff ( 8 files changed, 32 insertions(+), 26 deletions(-))
Terraform Beta: Diff ( 26 files changed, 565 insertions(+), 139 deletions(-))
TF Validator: Diff ( 2 files changed, 3 insertions(+), 3 deletions(-))
TF OiCS: Diff ( 12 files changed, 24 insertions(+), 24 deletions(-))

@modular-magician
Copy link
Collaborator

Tests analytics

Total tests: 2454
Passed tests 2188
Skipped tests: 255
Failed tests: 11

Action taken

Triggering VCR tests in RECORDING mode for the tests that failed during VCR. Click here to see the failed tests
TestAccRegionInstanceGroupManager_stateful|TestAccComputeForwardingRule_update|TestAccApigeeAddonsConfig_apigeeAddonsTestExample|TestAccServiceDirectoryServiceIamBindingGenerated|TestAccServiceDirectoryServiceIamPolicyGenerated|TestAccServiceDirectoryServiceIamMemberGenerated|TestAccDataSourceDnsRecordSet_basic|TestAccFrameworkProviderMeta_setModuleName|TestAccCloudbuildv2ConnectionIamPolicyGenerated|TestAccCloudbuildv2ConnectionIamMemberGenerated|TestAccCloudbuildv2ConnectionIamBindingGenerated

@modular-magician
Copy link
Collaborator

Tests passed during RECORDING mode:
TestAccComputeForwardingRule_update[Debug log]
TestAccApigeeAddonsConfig_apigeeAddonsTestExample[Debug log]
TestAccDataSourceDnsRecordSet_basic[Debug log]
TestAccFrameworkProviderMeta_setModuleName[Debug log]

Tests failed during RECORDING mode:
TestAccRegionInstanceGroupManager_stateful[Error message] [Debug log]
TestAccServiceDirectoryServiceIamBindingGenerated[Error message] [Debug log]
TestAccServiceDirectoryServiceIamPolicyGenerated[Error message] [Debug log]
TestAccServiceDirectoryServiceIamMemberGenerated[Error message] [Debug log]
TestAccCloudbuildv2ConnectionIamPolicyGenerated[Error message] [Debug log]
TestAccCloudbuildv2ConnectionIamMemberGenerated[Error message] [Debug log]
TestAccCloudbuildv2ConnectionIamBindingGenerated[Error message] [Debug log]

Please fix these to complete your PR
View the build log or the debug log for each test

@SarahFrench SarahFrench marked this pull request as draft February 7, 2023 11:58
@SarahFrench
Copy link
Contributor Author

Converting to draft as this PR is eventually going to be closed, after replacement with PRs for:

  • template change + skip import functionality + skipping tests identified as broken in this PR
  • Fixing fixable tests
  • Looking at the service directory tests, which seem fixable but more of a pain to fix

@SarahFrench
Copy link
Contributor Author

Closing this PR in favour of:

@SarahFrench SarahFrench closed this Feb 7, 2023
@SarahFrench SarahFrench deleted the iam-test-template-rm-ga-only-logic branch March 26, 2024 11:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Implement skip_test_import for generated IAM resource tests Check if ga-only logic can be removed from iam_test_file.go.erb file

3 participants