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

Introduce a google_kms_key_ring data source #2804

Closed
wants to merge 4 commits into from
Closed

Introduce a google_kms_key_ring data source #2804

wants to merge 4 commits into from

Conversation

joestump
Copy link

@joestump joestump commented Jan 4, 2019

This introduces a google_kms_key_ring data source that allows you to pull in KMS key ring information based on location and name.

I've also made a more generic testAccDataSourceMatchesResourceCheck function based on the one that was in the google_project data source. Due to the way my GCP organization is structured I've also introduced logic to allow folder_id to be used instead of org_id in my test.

I've tried running acceptance tests locally, but my GCP organization is structure in a way that's preventing me from running them. I'm PR'ing this now in the hopes that acceptance tests will run on the PR.

In the meantime, I need to figure out how to fix this error, which I'm 99% sure is unrelated to anything in this PR:

Error setting billing account "XXXXXX-YYYYYY-ZZZZZZ" for project "projects/terraform-gf2qlqy307": googleapi: Error 400: Precondition check failed., failedPrecondition

@chrisst chrisst self-assigned this Jan 8, 2019
}

output "key_self_link" {
value = "${data.google_kms_secret.info.self_link}"
Copy link
Contributor

Choose a reason for hiding this comment

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

Did you mean to add an example of using data.google_kms_key_ring here instead of the kms_secret?

@@ -51,3 +55,33 @@ func toBool(attribute string) (bool, error) {
}
return strconv.ParseBool(attribute)
}

func testAccDataSourceMatchesResourceCheck(dataSourceName string, resourceName string, attrsToCheck []string) resource.TestCheckFunc {
Copy link
Contributor

Choose a reason for hiding this comment

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

We use the testAccDataSource* prefix to indicate which resource/datasource that method is providing a config for and generally what file it exists in. For general purpose test helpers we don't use such verbose prefixes. Can you change to something without the testAcc prefix? Perhaps something like checkDataSourceMatchesResource.

return func(s *terraform.State) error {
ds, ok := s.RootModule().Resources[dataSourceName]
if !ok {
return fmt.Errorf("root module has no resource called %s", dataSourceName)
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you reword the error here and on line 68? I think this should say "module has no data source" instead of "resource" and the second error should be explicit that it can't find the "Resource"

projectOrg := getTestOrgFromEnv(t)
billingAccount := getTestBillingAccountFromEnv(t)
keyRingName := fmt.Sprintf("tf-test-%s", acctest.RandString(10))
folderId := os.Getenv("GOOGLE_FOLDER_ID")
Copy link
Contributor

Choose a reason for hiding this comment

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

We don't currently have a pattern for running tests in many configurations based on environment variables. If we need test 2 different configurations of a resource we have to create 2 separate tests. So as this test is encoded it will only ever run 1 of these paths in our CI system. Can you remove the logic for the folder test as it will be dead code for our CI system and anybody who doesn't have that variable set?

Normally I would encourage 2 separate tests, but in this case I think testing both project configurations is a more of a google_project test than a KMS data source test.

@chrisst
Copy link
Contributor

chrisst commented Jan 8, 2019

First of all, thank you for adding this! Also I added a quick commit to get the tests to pass but thanks for making that method more general purpose. Let me know when you've addressed the comments and I'll get this into our next build.

@chrisst
Copy link
Contributor

chrisst commented Jan 22, 2019

Duplicated by #2891

@chrisst chrisst closed this Jan 22, 2019
@joestump joestump deleted the jstump-data-resource-key-ring branch January 22, 2019 23:42
@ghost
Copy link

ghost commented Feb 22, 2019

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.

If you feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. If you feel I made an error 🤖 🙉 , please reach out to my human friends 👉 hashibot-feedback@hashicorp.com. Thanks!

@ghost ghost locked and limited conversation to collaborators Feb 22, 2019
@ghost ghost removed the waiting-response label Feb 22, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants