Skip to content

Add Splunk HEC p0 Integration #55

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

Merged

Conversation

dhing1024
Copy link
Contributor

@dhing1024 dhing1024 commented Jan 24, 2025

Adds the Splunk HEC terraform resource.

This reorganizes some of the utilities so that the file structure can match our backend's integration types:

  • provider
    • resources
      • install
        • aws
        • gcp
        • okta
        • ssh
    • event_collectors
      • install
        • splunk

Some of the commonalities are extracted to separate files for reusability, so that's why there are a bunch of small unrelated changes spread out.

Copy link
Contributor Author

@dhing1024 dhing1024 left a comment

Choose a reason for hiding this comment

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

Some notes/clarifications here

@@ -28,14 +23,6 @@ const (
// Order matters here; components installed in this order.
var InstallSteps = []string{Verify, Config}

func OperationPath(base_path string, step string) 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.

These were currently being unused

@@ -14,10 +13,6 @@ import (
const (
Config = "configure"
Verify = "verify"
IamAssessment = "iam-assessment"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Moved these to internal/provider/resources/install/resources.go under the installresources package.

@@ -1,8 +1,7 @@
package installresources
package common
Copy link
Contributor Author

Choose a reason for hiding this comment

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

package common contains general Install, RootInstall, and reporting utilities (ReportConversionError), as well as some constants that are generally used throughout

Copy link
Contributor

@GGonryun GGonryun Jan 27, 2025

Choose a reason for hiding this comment

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

I don't think I fully understand why we had to move the package. Outside of lining up with our backend structure. What is this refactor trying to accomplish?

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 had originally thought that was a good enough reason. I guess in part it was probably a little easier for me to understand, because i interpreted "resources" in this folder structure to refer to p0 "integration resource" as it appears on our integrations app page, rather than the concept of a "terraform resource".

Another thing - I think between when I started this and finished this PR, the Okta stuff got merged in, so with this change it wouldn't really align with our backend structure unless I additionally did another refactor to separate directory integrations into a separate package. So maybe it's just to just undo these specific changes and put everything back into one 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.

I think if there aren't any other objections, we can keep this for now and revisit it later if we find that it isn't working out for some reason.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think the new structure makes sense. But yes, we should do the Okta refactor.

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't have any objection, thank you for the clarity. I'd personally prefer to separate these types of refactors from enhancements so that there's less to review but i'm okay with moving forward with this for now.

Attributes: map[string]schema.Attribute{
"state": stateAttribute,
"token": schema.StringAttribute{
Computed: true,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The provider automatically generates a random UUID for the token ID that does not need to be states in the .tf file.


var currentTokenId types.String
resp.Diagnostics.Append(resp.State.GetAttribute(ctx, path.Root("token"), &currentTokenId)...)
if currentTokenId.ValueString() != "" {
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 condition solves some edge cases around refresh. Specifically if the resource is managed by terraform and the user deletes the token in the UI, then running terraform refresh without this would result in an inconsistent state.

Copy link
Contributor

Choose a reason for hiding this comment

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

@varunalla Why is anything returned here if the token is deleted in the UI? Shouldn't this return a 404 or something?

@dhing1024 I forget, what is the state when we do a refresh if there is no token in the UI? Does it delete the resource? Or what state do we end up with?

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 think these conditions + the other conditions may not be necessary anymore when the token is managed by the user instead, especially after adding the token ID via user input and adding the RequiresReplace to that property.

Prior terraform would get some consistency error related to the HEC token clear text (don't remember if it was exactly that or some other issue) if you ran those commands. Now when I tested removing these conditions, I haven't been seen those issues come up again.

stringvalidator.RegexMatches(UuidRegex, "Token must be a valid UUID"),
},
PlanModifiers: []planmodifier.String{
stringplanmodifier.RequiresReplace(),
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 indicates that the resource should be completely destroyed and replaced if this field changes. I think it does seem to do the right thing even without it, but adding this makes it behave a little bit more like how our UI works.

Copy link
Contributor

Choose a reason for hiding this comment

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

@varunalla Thoughts on this?

if currentTokenId.ValueString() != "" {
// manually set the token cleartext attribute
// this is needed because the cleartext token is not returned by the API
resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root(HecTokenClearTextKey), plan.HecTokenClearText)...)
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 value needs to be explicitly put back into the statefile because it is not returned by the API

@dhing1024 dhing1024 marked this pull request as ready for review January 24, 2025 22:11
@dhing1024 dhing1024 changed the title Dominickhing/eng 3409 terraform install splunk hec p0 integration Add Splunk HEC p0 Integration Jan 24, 2025
@fabgo fabgo requested a review from varunalla January 25, 2025 00:07
@dhing1024 dhing1024 requested a review from fabgo January 27, 2025 23:25
}

var api auditLogsApiReadWrite
var model auditLogsModel
Copy link
Contributor

Choose a reason for hiding this comment

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

Not sure you need model here. I think you can pass in &auditLogsModel to the installer functions.

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 tested this and you still need to declare a placeholder variable in this way to pass into the other functions.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think you can do this by typing &auditLogsModel{} but this is fine too 👍


var currentTokenId types.String
resp.Diagnostics.Append(resp.State.GetAttribute(ctx, path.Root("token_id"), &currentTokenId)...)
if currentTokenId.ValueString() != "" {
Copy link
Contributor

Choose a reason for hiding this comment

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

Wouldn't the token id always be set? Why do you need this check?

s.installer.Stage(ctx, &resp.Diagnostics, &req.Plan, &resp.State, &api, &model)
s.installer.UpsertFromStage(ctx, &resp.Diagnostics, &req.Plan, &resp.State, &api, &model)

var currentTokenId types.String
Copy link
Contributor

Choose a reason for hiding this comment

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

Isn't the token id already in the plan? Can't you just reference it from there?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You are right, I think this was but is no longer necessary.


s.installer.UpsertFromStage(ctx, &resp.Diagnostics, &req.Plan, &resp.State, &auditLogsApiReadWrite{}, &auditLogsModel{})

var currentTokenId types.String
Copy link
Contributor

Choose a reason for hiding this comment

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

Same question here I guess. Can't you just get the token id from the plan? And do you need the if condition here?

// manually set the token cleartext attribute
// this is needed because the cleartext token is not returned by the API
var currTokenClearText types.String
resp.Diagnostics.Append(req.Plan.GetAttribute(ctx, path.Root(HecTokenClearTextKey), &currTokenClearText)...)
Copy link
Contributor

Choose a reason for hiding this comment

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

Isn't this already in the plan variable?

Copy link
Contributor

@GGonryun GGonryun left a comment

Choose a reason for hiding this comment

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

changes make sense to me but ill defer to @fabgo

@dhing1024 dhing1024 merged commit f68d86c into main Jan 29, 2025
14 checks passed
@dhing1024 dhing1024 deleted the dominickhing/eng-3409-terraform-install-splunk-hec-p0-integration branch January 29, 2025 02:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants