-
Notifications
You must be signed in to change notification settings - Fork 31
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
feat(audit-trail): add support for audit trail to terraform provider #495
feat(audit-trail): add support for audit trail to terraform provider #495
Conversation
69094c2
to
edeeded
Compare
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.
It looks like a neat copy-paste with intention behind it. However I don't know how a provider should be implemented properly, so an encouraging comment is best I can do 💪
@peterdeme @michalg9 I saw you working on terraform provider recently, you would mind taking a look? |
return diag.Errorf("could not create audit trail webhook: %v", internal.FromSpaceliftError(err)) | ||
} | ||
|
||
data.SetId(time.Now().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 you sure about this one?
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.
nope, not at all, I mean it works, but it's a hack, see: https://spacelift-io.slack.com/archives/CRTS17WLF/p1705055720419239
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.
I also drafted PRs to actually execute the "ulid based" solution: https://github.com/spacelift-io/backend/pull/6165
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.
I see. I don't have a strong opinion on this, so feel free to do whatever :D Personally, I would either generate a "smart" id (maybe from the endpoint URL?), or go through with the ULID pull request.
Waiting on other people's opinion.
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.
Personally if it works I'm fine with this approach. There's only ever one audit trail webhook, and I don't think there's a reason to need to import the resource (since the mutation works like an upsert).
@marcinwyszynski @adamconnelly I saw you've been active in the repo, could you take a look? Thanks in advance |
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.
Looks good overall. Left some comments, but nothing major.
func resourceAuditTrailWebhook() *schema.Resource { | ||
return &schema.Resource{ | ||
Description: "" + | ||
"`spacelift_audit_trail_webhook` represents a webhook endpoint to which Spacelift " + |
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.
Couple of suggestions here:
- Maybe we should say "sends POST requests" instead of "sends the POST request"?
- I'm not sure about the "events the user wants to track" part. It kinda implies that you can choose the events you're interested in. Maybe we should just say "about audit events" or something like that?
StateContext: schema.ImportStatePassthroughContext, | ||
}, | ||
|
||
Schema: map[string]*schema.Schema{ |
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.
Can you add descriptions to these fields please?
return diag.Errorf("could not create audit trail webhook: %v", internal.FromSpaceliftError(err)) | ||
} | ||
|
||
data.SetId(time.Now().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.
Personally if it works I'm fine with this approach. There's only ever one audit trail webhook, and I don't think there's a reason to need to import the resource (since the mutation works like an upsert).
} | ||
` | ||
|
||
func Test_resourceAuditTrailWebhook(t *testing.T) { |
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.
Might wanna test deletion as well.
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.
Deletion should be a part of each test (the test will fail if the resource created for the test was not successfully removed). Do you reckon we need to test it explicitly? Do you know how to test it explicitly? I don't see a test like that in the repo and I'm not sure how to do 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.
That's fine then - don't worry about it if the test fails anyway if deletion fails. I just hadn't realised that.
As for how you'd do it - I imagine you'd just add a test step that applied a configuration where the resource wasn't included.
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.
As for how you'd do it - I imagine you'd just add a test step that applied a configuration where the resource wasn't included.
yeah, just wasn't sure how to test for a missing resource after applying an empty config
}) | ||
}) | ||
|
||
t.Run("cannot change endpoint", func(t *testing.T) { |
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.
Is this not more a test of the API rejecting an endpoint that doesn't exist, rather than testing that the endpoint can't be changed (which should totally be possible)?
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.
testing that the endpoint can't be changed (which should totally be possible)?
It's not possible to edit the endpoint if the audit trail webhook is enabled.
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.
You sure? Looking at the backend code, it seems to allow that, and just sends to both old and new endpoints if that's the case.
Regardless, I don't think this test is verifying that the endpoint can't be changed. It's just checking that if you set the endpoint to one that doesn't exist, we don't allow the endpoint to be updated.
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.
you're right, I think the reason I was able to set the endpoint to a non-existent value was that I disabled audit trail first and the check is only performed if it's enabled.
thanks!
I think the test still brings some value so I'll leave it and update the name.
43b74c6
to
64582ae
Compare
Signed-off-by: Michal Wasilewski <[email protected]>
64582ae
to
e2d18b0
Compare
…495) Signed-off-by: Michal Wasilewski <[email protected]>
Description of the change
closes: https://app.clickup.com/t/8693fq8pf
blocked on:
expose idwon't be needed:https://github.com/spacelift-io/backend/pull/6147https://github.com/spacelift-io/backend/pull/6165Type of change
Related issues
Checklists
Development
false
.)go generate
to make sure the docs are up to dateCode review