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

Add Traffic Filter data source #619

Conversation

andrew-moldovan
Copy link
Contributor

First contribution to this project so I'm approaching it slowly. The current implementation is super simple and just fetches the name when provided with an ID. (Also I'm sure there's a million things wrong with it still, never written Go before or touched the TF provider).

The reason behind this PR is #405. The ask there is to be able to fetch the id based on the name, so reverse of what I have now. The problem is that I'm not sure we have an API that can do that? Anyone got any ideas?

/cc @dimuon @tobio

Description

Related Issues

Motivation and Context

How Has This Been Tested?

Types of Changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Refactoring (improves code quality but has no user-facing effect)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation

Readiness Checklist

  • My code follows the code style of this project
  • My change requires a change to the documentation
  • I have updated the documentation accordingly
  • I have added tests to cover my changes
  • All new and existing tests passed

@tobio
Copy link
Member

tobio commented Apr 17, 2023

The problem is that I'm not sure we have an API that can do that? Anyone got any ideas?

List all rulesets then do client side filtering on the name I think is the only solution at the moment.

@dimuon
Copy link
Contributor

dimuon commented Apr 18, 2023

@andrew-moldovan , I think it makes sense to add unit tests for modelToState, similar to ec/ecresource/trafficfilterresource/flatteners_test.go and an integration test for the new data source.

@andrew-moldovan
Copy link
Contributor Author

Yep, I will add tests still, and expose more of the attributes. Just struggling with Go and learning how this all works, so progress is a bit slow

@andrew-moldovan
Copy link
Contributor Author

@dimuon could you please take a look at the test I have tried to write? I am struggling with types, figuring out how they all go and why they're so awful 😂 I feel like what I have should theoretically work, but it's yelling about something

@andrew-moldovan
Copy link
Contributor Author

Ok so I've got the unit tests up and running and working on the acceptance tests. Couple things:

  1. Almost all of them seem to be failing and I have a hard time believing that adding an extra data source has made them all fail. They're all failing with After applying this test step, the plan was not empty and it looks like they might be trying to add apm_secret_token?
  2. For my actual acceptance test, I basically want to make sure it can filter by id/name/region (or even just one of them) and return the number of rulesets I expect and some details of the ruleset. However, I'm not sure what account is being used and if this is checking our QA? or Staging? Can I add a single traffic filter that I can make sure won't be deleted? Right now there seems to be 42 rulesets for us-east-1 so I'm worried that isn't likely to be a stable number. I see that the datasource_stack test essentially just checks to see if version is set but doesn't check to what it's set. I guess I could use something similar, ie just make sure that some rulesets are returned? But even that could be screwed if all the rulesets are deleted by some other process.

Any ideas @tobio @dimuon

@dimuon
Copy link
Contributor

dimuon commented Apr 20, 2023 via email

@dimuon
Copy link
Contributor

dimuon commented Apr 20, 2023

@andrew-moldovan , can you leverage ec_deployment_traffic_filter to create a filter or two and then reuse them in acceptance test? E.g. ec/acc/deployment_traffic_filter_test.go creates such traffic filters.

@andrew-moldovan
Copy link
Contributor Author

@dimuon ah yes good call. I think I've got that working 🎉

Marking this as ready to review now

@andrew-moldovan andrew-moldovan marked this pull request as ready for review April 20, 2023 22:08
@andrew-moldovan andrew-moldovan requested a review from a team as a code owner April 20, 2023 22:08
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.

We should add some docs for this data source.

examples/deployment/deployment.tf Outdated Show resolved Hide resolved
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.

Small docs change, but lgtm. We should be generating these docs so happy to leave this as is for now and hopefully someo can automate it soon.

* `region` (Optional) - Region where the traffic filter is. For Elastic Cloud Enterprise (ECE) installations, use `"ece-region`.

## Attributes Reference
See https://www.elastic.co/guide/en/cloud/current/definitions.html#TrafficFilterRulesets for the API guide
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
See https://www.elastic.co/guide/en/cloud/current/definitions.html#TrafficFilterRulesets for the API guide
See the [API guide](https://www.elastic.co/guide/en/cloud/current/definitions.html#TrafficFilterRulesets) for the available fields.

Although it would be better to document the actual structure here instead.

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 deliberately didn't document the actual structure here because I felt that wasn't the right choice. Why am I copy/pasting the structure from the link and writing up my own descriptions (or copying them) when that structure could change or new things added or descriptions changed? Then we'd have to remember to update them in these docs as well instead of just having people visit the one source of truth

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Just re-read your comment about autogenerating these docs and I totally agree with that!

Copy link
Member

Choose a reason for hiding this comment

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

when that structure could change or new things added or descriptions changed

Because API structure changes aren't automatically reflected here. We'd have to add those fields to the provider as well.

@andrew-moldovan andrew-moldovan merged commit cd25ecf into elastic:master Apr 27, 2023
@andrew-moldovan andrew-moldovan deleted the #405-add-traffic-filter-datasource branch April 27, 2023 17:09
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