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

Terraform Data Source to retrieve SQL instance CA certs #2901

Merged
merged 14 commits into from
Jan 6, 2020
Merged

Terraform Data Source to retrieve SQL instance CA certs #2901

merged 14 commits into from
Jan 6, 2020

Conversation

chrissng
Copy link
Contributor

@chrissng chrissng commented Dec 31, 2019

Terraform Data Source to get all of the trusted Certificate Authorities (CAs) for the specified SQL database instance.

Example usage: This data source could be used to look for upcoming CA certs (as part of cert rotation) and if so, generate new client certs.

Release Note Template for Downstream PRs (will be copied)

google_sql_ca_certs

@chrissng chrissng changed the title Terraform Data Source to retrieve SQL SSL CA certs Terraform Data Source to retrieve SQL instance CA certs Dec 31, 2019
@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. They will authorize it to run through our CI pipeline, which will generate downstream PRs.

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

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

Copy link
Contributor

@danawillow danawillow left a comment

Choose a reason for hiding this comment

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

Thanks @chrissng!

},
Computed: true,
},
"instance": {
Copy link
Contributor

Choose a reason for hiding this comment

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

Instead of separate instance and instance_self_link, let's have just one field that can take the instance name or self link. You can do this by using the compareSelfLinkOrResourceName DiffSuppressFunc- the logic you already have for the project field value will take care of getting the correct project.

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 great as it simplifies the implementation. Done.

[API](https://cloud.google.com/sql/docs/mysql/admin-api/rest/v1beta4/instances/listServerCas).


## Example Usage
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a terraform-relevant example of how this might be used, such as another resource that might interpolate on this value? If so, mind adding it as well?

Copy link
Contributor Author

@chrissng chrissng Jan 3, 2020

Choose a reason for hiding this comment

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

I am not able to find a TPG resource that could be interpolated into; typically this is used by applications to connect to the db via ssl. Therefore such a usage would be encapsulated as a Terraform module and exposed via relevant outputs.

I have extended my example a bit. Please see if it makes sense.

Copy link
Contributor

Choose a reason for hiding this comment

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

Looks good!


The following attributes are exported:

* `active_version` - The boot disk for the instance. Structure is documented below.
Copy link
Contributor

Choose a reason for hiding this comment

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

This description looks like a copy/paste error

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oops my mistake. fixed.

return &schema.Resource{
Read: dataSourceGoogleSQLCaCertsRead,

Schema: map[string]*schema.Schema{
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: Can you order this such that the fields go in the order Required -> Optional -> Computed?

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

config := meta.(*Config)

var project, instance string
if v, ok := d.GetOk("instance"); ok {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: instance is required, so we can remove this if/else and just keep the logic that's inside

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point. Removed

[API](https://cloud.google.com/sql/docs/mysql/admin-api/rest/v1beta4/instances/listServerCas).


## Example Usage
Copy link
Contributor

Choose a reason for hiding this comment

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

Looks good!

@modular-magician
Copy link
Collaborator

Hi! I'm the modular magician, I work on Magic Modules.
I see that this PR has already had some downstream PRs generated. Any open downstreams are already updated to your most recent commit, 38126d6.

Pull request statuses

No diff detected in terraform-google-conversion.
No diff detected in Ansible.
No diff detected in Inspec.

New Pull Requests

I built this PR into one or more new PRs on other repositories, and when those are closed, this PR will also be merged and closed.
depends: hashicorp/terraform-provider-google-beta#1580
depends: hashicorp/terraform-provider-google#5306

@modular-magician
Copy link
Collaborator

Hi! I'm the modular magician, I work on Magic Modules.
I see that this PR has already had some downstream PRs generated. Any open downstreams are already updated to your most recent commit, 931b4b1.

Pull request statuses

terraform-provider-google-beta already has an open PR.
No diff detected in terraform-google-conversion.
terraform-provider-google already has an open PR.
No diff detected in Ansible.
No diff detected in Inspec.

New Pull Requests

I didn't open any new pull requests because of this PR.

@danawillow
Copy link
Contributor

Gah I just merged the downstreams so don't do it in this PR, but can you create a followup to add a sidebar entry at https://github.com/GoogleCloudPlatform/magic-modules/blob/master/third_party/terraform/website-compiled/google.erb?

@modular-magician modular-magician merged commit 9c8442b into GoogleCloudPlatform:master Jan 6, 2020
@chrissng
Copy link
Contributor Author

chrissng commented Jan 7, 2020

@danawillow oh no I thought that was autogenerated. I'll raise a PR for the side bar asap

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants