-
Notifications
You must be signed in to change notification settings - Fork 9.6k
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
provider/digitalocean: Add support for certificates #14578
Conversation
There are three "deeper" changes included with this update: 1) The `Detach` function got removed from the `StorageActionsService` in favor of `DetachByDropletID` (which is now used in `resource_digitalocean_volume.go`). 2) The `Update` function got removed from `TagsService` (renaming a tag has been deprecated in the API). 3) Every function in godo now takes a `context.Context` as first argument, so I've changed all calls to send in a `context.Background()`.
Besides the support for DO certificates themselves, this commit also includes: 1) A new `RandTLSCert` function that generates a valid, self-signed TLS certificate to be used in the test 2) A fix for the PEM encoding of the private key generated in `RandSSHKeyPair`: the PEM was always empty
Just realized this is missing updates to docs, so marking it as WIP. |
Docs added in a565001. Removing [WIP]. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall, looks good. Great work on this! Just a few minor nits/questions.
Name: d.Get("name").(string), | ||
PrivateKey: d.Get("private_key").(string), | ||
LeafCertificate: d.Get("leaf_certificate").(string), | ||
CertificateChain: d.Get("certificate_chain").(string), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are there any undesired effects to certificate_chain
being nil
in the CertificateRequest
struct? As certificate_chain
is an optional parameter, might be worthwhile to verify it's populated with d.GetOk()
. If it doesn't cause any undesired effects, looks good as-is.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@grubernaut AFAIK, there are no undesired effects to certificate_chain
being nil. But I'd rather play safe here, so I'm gonna add a check around it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Although I just checked the docs for Get
on ResourceData
and it seems to be safe for TypeString
(it just returns the zero value, or ""
). I think it's safe to leave it as is.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's correct about Get
returning the nil
type for the native golang string type, however, does that have any adverse effect during the Create request in the DO API?
IE: will setting certificate_chain
to ""
, cause the API request to attempt to set certificate_chain
to ""
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@grubernaut It doesn't seem to have any adverse effects.
|
||
d.Set("name", cert.Name) | ||
d.Set("not_after", cert.NotAfter) | ||
d.Set("sha1_fingerprint", cert.SHA1Fingerprint) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are the other attributes listed in the schema not available in the cert
object? These will need to be set as well so Terraform can detect any configuration drift between config/state.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@grubernaut Correct, they're available only for creation, but not returned by the API (for security reasons, I assume).
This is the example response from the API docs:
{
"certificate": {
"id": "892071a0-bb95-49bc-8021-3afd67a210bf",
"name": "web-cert-01",
"not_after": "2017-02-22T00:23:00Z",
"sha1_fingerprint": "dfcc9f57d86bf58e321c2c6c31c7a971be244ac7",
"created_at": "2017-02-08T16:02:37Z"
}
}
return fmt.Errorf("Error deleting Certificate: %s", err) | ||
} | ||
|
||
d.SetId("") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The Delete
method doesn't need to set the ID to nil, as a non-error return from the Delete method already does this. However, it's not critical to remove, just noting for future knowledge 😄
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool, I'm gonna remove it anyway. Thanks for the tip!
Also, as a follow-up, what attributes were changing in the acceptance test that causes the need for setting |
Hey, @grubernaut, thanks a lot for the feedback! I'll address it soon and let you know when I think this is ready for a second pass. |
@grubernaut I collected the log from the failing test after removing https://gist.github.com/caiofilipini/f0628fffd39abb631f2f374d62e4a057 Let me know if you have any insights so we can move this forward. Thank you! |
Hey @caiofilipini, if you add |
* `certificate_chain` - (Optional) The full PEM-formatted trust chain | ||
between the certificate authority's certificate and your domain's TLS | ||
certificate. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are not_after
and sha1_fingerprint
not allowed to be specified? In the resource schema, they're listed as Optional
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@grubernaut They're not recognized (ignored) by the API and always computed based on the input. I wasn't sure how to best represent them so they would make it to the resulting state, but without them being required in the request. Is this the way to go, or is there a better way?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@caiofilipini ah okay awesome. If they aren't accepted inputs to the API request, we can remove Optional
and ForceNew
and the attributes will simply be Computed
attributes that we set inside the Read
method.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@grubernaut Ah, that makes sense. Done in c4bbb6e.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@caiofilipini Awesome, ready to review?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@grubernaut Yeah! 😄
@grubernaut |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome work here! Thanks!
LGTM!
Thanks for all your help, @grubernaut! |
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 have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further. |
This PR addresses that by introducing the
resource_digitalocean_certificate
.Fixes #14577.
A few things to note:
context.Context
, and a few things got deprecated/removed).RandTLSCert
function inhelper/acctest/random.go
that generates a valid, self-signed TLS certificate so that we can properly test the integration.Step 0 error: After applying this step, the plan was not empty:
while running the new tests and I couldn't really figure it out. I think it's because the attributes that DO's API returns for a certificate are different from the ones we use fore creating one. For that reason, I've setExpectNonEmptyPlan
totrue
, but I'd love some guidance here.