Skip to content

add resource for datastream lifecycle #852

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
merged 3 commits into from
Oct 23, 2024

Conversation

aizerin
Copy link
Contributor

@aizerin aizerin commented Oct 17, 2024

resolves #838

Copy link
Member

@tobio tobio left a comment

Choose a reason for hiding this comment

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

Thanks for taking the time to add this in.

Is it possible to have this resource built on the Plugin Framework instead? There's a strong preference here for new code to utilise that framework over the old SDK v2 and we're not re-using any existing SDK code here. This commit is an example of converting to the plugin framework if that helps.

It looks like lint is failing because the generated docs don't match what's committed, which can be fixed by committing the result of make docs-generate

// generate renadom name
dsName := sdkacctest.RandStringFromCharSet(22, sdkacctest.CharSetAlpha)

resource.Test(t, resource.TestCase{
Copy link
Member

Choose a reason for hiding this comment

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

We'll want to skip these when the backing cluster doesn't support DS lifecycles (example)

)

func TestAccResourceDataStreamLifecycle(t *testing.T) {
// generate renadom name
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
// generate renadom name
// generate random name


{{ tffile "examples/resources/elasticstack_elasticsearch_data_stream_lifecycle/resource.tf" }}

{{ .SchemaMarkdown | trimspace }}
Copy link
Member

Choose a reason for hiding this comment

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

Can we include an import example here as well

},
},
},
"lifecycles": {
Copy link
Member

Choose a reason for hiding this comment

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

It's not clear what value we get with this block.

Since we're not writing these values back to the top level attributes TF drift detection won't pickup out of band changes. Choosing which value to use when the response includes multiple lifecycles is a challenge, but something we should solve IMO (a simple heuristic would be to use any value which differed from the configured value so drift detection worked, and if no diff was found just use the first).

In reality, I suspect most users will likely target a single data stream.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Originally I had it so that I only detected the value that changed, then I thought it would be nice to have everything in state, but I didn't know that TF couldn't work with it that way.

I will change it back :)

@aizerin
Copy link
Contributor Author

aizerin commented Oct 18, 2024

Thanks for taking the time to add this in.

Is it possible to have this resource built on the Plugin Framework instead? There's a strong preference here for new code to utilise that framework over the old SDK v2 and we're not re-using any existing SDK code here. This commit is an example of converting to the plugin framework if that helps.

It looks like lint is failing because the generated docs don't match what's committed, which can be fixed by committing the result of make docs-generate

ok, not a problem.

@aizerin aizerin force-pushed the feature/ds_lifecycle branch 2 times, most recently from 20c1f15 to fe15c35 Compare October 22, 2024 13:33
@aizerin
Copy link
Contributor Author

aizerin commented Oct 22, 2024

updated

Copy link
Member

@tobio tobio left a comment

Choose a reason for hiding this comment

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

Thanks for adding this resource, it's really useful!

One small comment on de-duplicating the Create/Update implementations but otherwise LGTM.

"github.com./hashicorp/terraform-plugin-framework/types"
)

func (r *Resource) Update(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) {
Copy link
Member

Choose a reason for hiding this comment

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

This looks identical to the Create method. Can we pull this out to a common write (or some other name if you prefer) method and re-use it in both Create and Update?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OK, I did the same as here:

internal/fleet/integration/create.go
internal/fleet/integration/update.go

@aizerin aizerin force-pushed the feature/ds_lifecycle branch from fe15c35 to 32987b8 Compare October 23, 2024 07:33
Copy link
Member

@tobio tobio left a comment

Choose a reason for hiding this comment

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

Love it, thanks again for taking the time to get this one added, and for working through the review changes.

@tobio tobio merged commit 35ef008 into elastic:main Oct 23, 2024
20 checks passed
kjwardy pushed a commit to kjwardy/terraform-provider-elasticstack that referenced this pull request Nov 19, 2024
* add resource for datastream lifecycle

* Just return diags

---------

Co-authored-by: Toby Brain <[email protected]>
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.

[Feature] Datastream lifecycle
2 participants