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

Added org policy policy resource. #5199

Merged
merged 7 commits into from
Sep 20, 2021

Conversation

trodge
Copy link
Contributor

@trodge trodge commented Sep 14, 2021

Added org policy policy resource to tpgtools. This is a new, schema-incompatible version of google_organization_policy, google_folder_organization_policy, and google_project_organization_policy which can have any of the three parent resources.

Added cloudresourcemanager folder and project resources with serialization only override for use in testing. These resources are still not implemented in terraform through the DCL.

fixes hashicorp/terraform-provider-google#2605

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)

`google_org_policy_policy`

@google-cla google-cla bot added the cla: yes label Sep 14, 2021
@modular-magician
Copy link
Collaborator

Oops! It looks like you're using an unknown release-note type in your changelog entries:

  • REPLACEME

Please only use the types listed in https://github.com/GoogleCloudPlatform/magic-modules/blob/master/.ci/RELEASE_NOTES_GUIDE.md.

@modular-magician
Copy link
Collaborator

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

I have detected that you are a community contributor, so your PR will be assigned to someone with a commit-bit on this repo for initial review.

Thanks for your contribution! A human will be with you soon.

@c2thorn, please review this PR or find an appropriate assignee.

@modular-magician
Copy link
Collaborator

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

Diff report:

Terraform GA: Diff ( 29 files changed, 1356 insertions(+), 9574 deletions(-))
Terraform Beta: Diff ( 33 files changed, 1621 insertions(+), 11308 deletions(-))
TF Conversion: Diff ( 1 file changed, 5 insertions(+), 3 deletions(-))


func resourceOrgPolicyPolicyCustomImport(d *schema.ResourceData, meta interface{}) error {
config := meta.(*Config)
if err := parseImportId([]string{
Copy link
Contributor

Choose a reason for hiding this comment

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

I would add a comment which says "this differs from the normal import method because it permits slashes in the first element and requires the parent to start at the beginning of the string.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

Copy link
Member

Choose a reason for hiding this comment

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

I can't think of any off the top of my head, but do we see this import pattern in other resources? Any merit to a generic solution?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There are other resources in the DCL that allow a forward slashes in the values for certain fields. Usually, as it is here, this is because the field is a parent field and there can be more than one type of parent for the resource.

- type: SERIALIZATION_ONLY
- type: CUSTOM_TERRAFORM_PRODUCT_NAME
details:
product: ""
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe a comment that says "this produces the correct name google_folder"?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

// of the DCL resource with a different location type. All references in samples
// to a resource with an alternate location will point to the main version.
func (r Resource) IsAlternateLocation() bool {
// For now, we consider non-regional resources to be alternate.
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd extend this comment to say "non-locational resources have the empty string for their location."

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

return serializeProjectToHCL(m)
}

func serializeProjectToHCL(m map[string]interface{}) (string, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I notice this doesn't have folder, is that a git history mishap or is that on purpose?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Folder does not need a custom serializer because it has the same schema in DCL and terraform.

@@ -235,9 +235,9 @@ func resource{{$.PathType}}Create(d *schema.ResourceData, meta interface{}) erro
}
{{ end }}

id, err := {{ $.IdFunction }}(d, config, "{{$.ID}}")
Copy link
Contributor

Choose a reason for hiding this comment

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

Does this mean we can remove IdFunction and ID now that the DCL exports an ID method?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I believe so. Should I do that in this PR?

Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm... leave a TODO, maybe? This does already include an awful lot of changes that are required-but-tangentially-related.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

Copy link
Member

Choose a reason for hiding this comment

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

I believe this would be better tracked if there were a GH issue that this TODO could point to

@nat-henderson
Copy link
Contributor

@c2thorn - Thomas and I pair programmed most of this, so I'll take a first pass on review but we'll ping you when we need a fresh pair of eyes. :)

@modular-magician
Copy link
Collaborator

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

Diff report:

Terraform GA: Diff ( 29 files changed, 1356 insertions(+), 9574 deletions(-))
Terraform Beta: Diff ( 34 files changed, 1622 insertions(+), 11309 deletions(-))
TF Conversion: Diff ( 1 file changed, 5 insertions(+), 3 deletions(-))

go.sum Outdated
@@ -0,0 +1 @@
3644975SUM_LINE
Copy link
Contributor

Choose a reason for hiding this comment

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

This file should be removed - some kind of issue copying makefile commands I assume?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@@ -1577,3 +1579,6 @@ rsc.io/sampler v1.3.0 h1:7uVkIFmeBqHfdjD+gZwtXXI+RODJ2Wc4O7MPEh/QiW4=
rsc.io/sampler v1.3.0/go.mod h1:T1hPZKmBbMNahiBKFy5HrXp6adAjACjK9JXDnKaTXpA=
sigs.k8s.io/yaml v1.1.0 h1:4A07+ZFc2wgJwo8YNlQpr1rVlgUDlxXHhPJciaPY5gs=
sigs.k8s.io/yaml v1.1.0/go.mod h1:UJmg0vDUVViEyp3mgSv9WPwZCDxu4rQW1olrI1uml+o=
3644975SUM_LINE
Copy link
Contributor

Choose a reason for hiding this comment

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

This line should be removed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've amended the commit that added this line. Let me know if it's still incorrect.

@nat-henderson
Copy link
Contributor

You'll need to rebase + update those go.mod-related files again.

@trodge trodge force-pushed the orgpolicy-policy-dcl branch 2 times, most recently from 5c995c5 to 01b7437 Compare September 15, 2021 00:23
@modular-magician
Copy link
Collaborator

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

Diff report:

Terraform GA: Diff ( 21 files changed, 1333 insertions(+), 24 deletions(-))
Terraform Beta: Diff ( 25 files changed, 1343 insertions(+), 31 deletions(-))
TF Conversion: Diff ( 1 file changed, 5 insertions(+), 3 deletions(-))

@nat-henderson
Copy link
Contributor

Awesome, looks like this all compiles and passes lints. /gcbrun to get the full test suite running. It'll take til tomorrow, we'll look at it in the morning.

@trodge
Copy link
Contributor Author

trodge commented Sep 15, 2021

/gcbrun

@nat-henderson
Copy link
Contributor

Ah, sorry, it needed me to do it. It's going to complain you're not on the allowlist. But it did trigger, we can check in at https://ci-oss.hashicorp.engineering/buildConfiguration/GoogleCloudBeta_ProviderGoogleCloudBetaMmUpstreamVcr/205879? in the morning - although I suspect permissions there will be a hassle. Something else to get sorted before the e2e experiment.

@modular-magician
Copy link
Collaborator

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

Diff report:

Terraform GA: Diff ( 21 files changed, 1333 insertions(+), 24 deletions(-))
Terraform Beta: Diff ( 24 files changed, 1342 insertions(+), 30 deletions(-))
TF Conversion: Diff ( 1 file changed, 5 insertions(+), 3 deletions(-))

@nat-henderson
Copy link
Contributor

There's an issue in a DCL-based resource which is likely related to DCL-side handling of the .ID() change - we are probably not correctly normalizing everything that goes in that field. Once we fix that, should be good for review.

@nat-henderson
Copy link
Contributor

Okay, I pushed a change that should fix that test failure. We'll have to see after the diff generation.

@modular-magician
Copy link
Collaborator

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

Diff report:

Terraform GA: Diff ( 21 files changed, 1324 insertions(+), 15 deletions(-))
Terraform Beta: Diff ( 25 files changed, 1331 insertions(+), 19 deletions(-))
TF Conversion: Diff ( 1 file changed, 5 insertions(+), 3 deletions(-))

@nat-henderson
Copy link
Contributor

/gcbrun

@modular-magician
Copy link
Collaborator

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

Diff report:

Terraform GA: Diff ( 21 files changed, 1324 insertions(+), 15 deletions(-))
Terraform Beta: Diff ( 25 files changed, 1331 insertions(+), 19 deletions(-))
TF Conversion: Diff ( 1 file changed, 5 insertions(+), 3 deletions(-))

@modular-magician
Copy link
Collaborator

I have triggered VCR tests in RECORDING mode for the following tests that failed during VCR: TestAccOrgPolicyPolicy_EnforcePolicy|TestAccOrgPolicyPolicy_FolderPolicy|TestAccOrgPolicyPolicy_OrganizationPolicy|TestAccOrgPolicyPolicy_ProjectPolicy You can view the result here: https://ci-oss.hashicorp.engineering/viewQueued.html?itemId=206047

@nat-henderson
Copy link
Contributor

Great. Now only the new tests are failing and we have gotten all of them to pass on our side already so we have a good reason to think they will pass when they run.

@modular-magician
Copy link
Collaborator

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

Diff report:

Terraform GA: Diff ( 31 files changed, 1377 insertions(+), 9575 deletions(-))
Terraform Beta: Diff ( 35 files changed, 1642 insertions(+), 11309 deletions(-))
TF Conversion: Diff ( 1 file changed, 5 insertions(+), 3 deletions(-))

@modular-magician
Copy link
Collaborator

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

Diff report:

Terraform GA: Diff ( 23 files changed, 1356 insertions(+), 15 deletions(-))
Terraform Beta: Diff ( 28 files changed, 1364 insertions(+), 21 deletions(-))
TF Conversion: Diff ( 1 file changed, 5 insertions(+), 3 deletions(-))

@nat-henderson
Copy link
Contributor

/gcbrun

1 similar comment
@nat-henderson
Copy link
Contributor

/gcbrun

@trodge trodge force-pushed the orgpolicy-policy-dcl branch 2 times, most recently from 8f63d84 to af6f45a Compare September 20, 2021 15:53
@modular-magician
Copy link
Collaborator

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

Diff report:

Terraform GA: Diff ( 23 files changed, 1354 insertions(+), 13 deletions(-))
Terraform Beta: Diff ( 27 files changed, 1361 insertions(+), 17 deletions(-))
TF Conversion: Diff ( 1 file changed, 5 insertions(+), 3 deletions(-))

@nat-henderson
Copy link
Contributor

/gcbrun

@modular-magician
Copy link
Collaborator

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

Diff report:

Terraform GA: Diff ( 23 files changed, 1354 insertions(+), 13 deletions(-))
Terraform Beta: Diff ( 26 files changed, 1360 insertions(+), 16 deletions(-))
TF Conversion: Diff ( 1 file changed, 5 insertions(+), 3 deletions(-))

@modular-magician
Copy link
Collaborator

I have triggered VCR tests in RECORDING mode for the following tests that failed during VCR: TestAccComputeManagedSslCertificate_managedSslCertificateBasicExample|TestAccComputeServiceAttachment_serviceAttachmentBasicExample|TestAccOrgPolicyPolicy_EnforcePolicy|TestAccOrgPolicyPolicy_FolderPolicy|TestAccOrgPolicyPolicy_OrganizationPolicy|TestAccOrgPolicyPolicy_ProjectPolicy You can view the result here: https://ci-oss.hashicorp.engineering/viewQueued.html?itemId=206583

@modular-magician
Copy link
Collaborator

Tests failed during RECORDING mode: TestAccOrgPolicyPolicy_OrganizationPolicy|TestAccOrgPolicyPolicy_FolderPolicy|TestAccOrgPolicyPolicy_ProjectPolicy|TestAccOrgPolicyPolicy_EnforcePolicy|TestAccComputeServiceAttachment_serviceAttachmentBasicExample Please fix these to complete your PR

if err != nil {
return fmt.Errorf("Error constructing id: %s", err)
Copy link
Member

Choose a reason for hiding this comment

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

Why remove this extra formatting? The message still seems appropriate to me for the UseDCLID case, but if we need to modify it I think that's better than fully removing. Just makes it easier to read in the logs.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've put the extra formatting back, lowercased in case the error isn't at the start of a sentence.

details:
function: resourceOrgPolicyPolicyCustomImport
- type: USE_DCL_ID
- type: ENUM_BOOL
Copy link
Member

Choose a reason for hiding this comment

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

Non-review question: how would contributors be able to to recognize that a boolean should have this override applied to it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If the field is a boolean in the DCL and it's necessary to be able to distinguish between true, false, and nil, then it needs to be an enum/string in terraform which can be "TRUE", "FALSE", or "".
In this case the distinction is important because these fields conflict with each other and setting enforce to false is different than leaving all of them unset.

Copy link
Contributor

Choose a reason for hiding this comment

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

If it needs to have an unset case which is distinct from false. This would be a good place to insist we write those override docs!

Copy link
Member

Choose a reason for hiding this comment

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

Yes if we could add a one-pager doc per override added, that would help. I don't quite remember if we had a specific place where we've kept them all, @ndmckinley do you remember? Maybe we can chat in an internal chat about it.

@nat-henderson
Copy link
Contributor

FYI with respect to tests the issue was "api not enabled", enabled and rerunning.
https://ci-oss.hashicorp.engineering/buildConfiguration/GoogleCloudBeta_ProviderGoogleCloudBetaMmUpstream/206594

@@ -0,0 +1,10 @@
- type: CUSTOM_IMPORT_FUNCTION
Copy link
Member

Choose a reason for hiding this comment

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

The generated sweeper does not seem to work correctly likely tied to the need for the custom import. We should probably add a NO_SWEEPER override for now.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah, yes, thank you!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added.

@nat-henderson
Copy link
Contributor

FYI those tests all passed - this is a fully green run.

@modular-magician
Copy link
Collaborator

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

Diff report:

Terraform GA: Diff ( 23 files changed, 1354 insertions(+), 13 deletions(-))
Terraform Beta: Diff ( 25 files changed, 1288 insertions(+), 16 deletions(-))
TF Conversion: Diff ( 1 file changed, 5 insertions(+), 3 deletions(-))

@suckowbiz
Copy link

Hi @trodge ,

this mr closes #2605. Could you please point me to the new functionality that now enables to manage a monitoring workspace in an automated way?

@trodge
Copy link
Contributor Author

trodge commented Sep 21, 2021

Hi @trodge ,

this mr closes #2605. Could you please point me to the new functionality that now enables to manage a monitoring workspace in an automated way?

I seem to have linked this issue in the wrong PR.
#5218 will implement monitoring metrics scope and monitored project resources when it merges. These resources allow users to monitor metrics from multiple projects from the scope of a single project.

@trodge trodge deleted the orgpolicy-policy-dcl branch September 21, 2021 16:23
@rileykarson
Copy link
Member

@nat-henderson
Copy link
Contributor

Thanks, yes - I got the internal bugs and missed the external one. Appreciate the pointer.

khajduczenia pushed a commit to khajduczenia/magic-modules that referenced this pull request Oct 12, 2021
* Added org policy policy resource.

* Added additional comments.

* Allow resources to use the normal terraform ID process by default - DCL by override.

* Added a way to expand and flatten between terraform strings and dcl booleans.

* Updated GA version of policy.yaml.

* Ran make upgrade-dcl (and added missing tab to tf go.mod).

* Added NO_SWEEPER override for orgpolicy policy and formatting for id construction errors.

Co-authored-by: Nathan Mckinley <nmckinley@google.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add support for Stackdriver monitored project
6 participants