-
Notifications
You must be signed in to change notification settings - Fork 8
feat(bunny_pullzone): add a datasource for pull zones #98
base: main
Are you sure you want to change the base?
Conversation
This PR is independent from, but ultimately serves the work I'm doing on Video Libraries each have a unique underlying Pull Zone that is manged by Bunny Stream. However, there is a lot of important data on these pull zones that is needed to properly use a Video Library for anything (such as signing keys, pull zone name, etc). By providing a data source you can do something like: resource "bunny_videolibrary" "vl" {
name = "foobar"
}
data "bunny_pullzone" "vlpz" {
pull_zone_id = bunny_videolibrary.vl.pull_zone_id
} You can then subsequently pass around important bits of information: |
@jspizziri duplicating all those fields with the descriptions in the data source will be a pain to maintain. Could you please also add a testcase? |
@fho that was my thought as well! Unfortunately, it appears this is how it has to be done with TF. I looked at how the providers for AWS and K8s are working and they do it like this as well (the example does it this way too). Lastly, there are schema properties that can be put on the Resource schema that simply cause a run-time error if they're present on the data import schema. If you could do some double-checking on this I think that would be wise, but this is what I found in my research last week. I could certainly pair it down a good deal at least for my use case, and probably a sensible amount for most use cases. If you confirm that this is the best path forward I'll go ahead and do that and add some tests. |
@jspizziri I was also checking other provides and could not find one that was reusing the schema definition.
great that you tried that 👍 Lets go then with a minimal data source definition. |
@fho I trimmed the payload and added a test. The test isn't working at the moment and I could use some guidance. When I run it I get the following error, but I don't know what the issue is:
|
|
@fho ah, thanks for that 🤦 . So to reduce the schema we'll have to duplicate the mapping. Is that still your preference? |
@jspizziri To reduce the duplicate code, we can also move the |
@fho updated, please take a look. |
keyZoneSecurityEnabled: { | ||
Type: schema.TypeBool, | ||
Computed: true, | ||
Description: "True if the URL secure token authentication security is enabled.", | ||
}, | ||
keyZoneSecurityIncludeHashRemoteIP: { | ||
Type: schema.TypeBool, | ||
Computed: true, | ||
Description: "True if the zone security hash should include the remote IP.", |
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.
What is the usecase for keyZoneSecurityEnabled and keyZoneSecurityIncludeHashRemoteIP, when managing a videolib?
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.
Those are properties that, while exposed via the Video Library update endpoint, are not fetchable as part of the Video Library, as they reside exclusively on the Pull Zone. I put them in here as I think they'll be helpful in certain cases to determine the full state of a video library.
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.
Do you mean that the EnableTokenIPVerification
and PlayerTokenAuthenticationEnabled
fields in the videolib update call change the keyZoneSecurityEnabled
and keyZoneSecurityIncludeHashRemoteIP
settings in the pull-zone? 👀
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.
Correct, those are pass throughs that bunny internally sets on the managed pull-zone. The unfortunate part is that they don't also return them in the video library API. I asked the Bunny team about this in a support request and they said you have to query the Pull Zone directly to get them. The other alternative to this is to do a special PullZone.Get as part of the VideoLibrary update process, which doesn't feel great to me. Exposing them in this way seemed fairly simple, although it has the downside of your bunny_videolibrary
resource state potentially being incorrect if something weird happens.
I do like bunny a lot, but when they do stuff like this I get a bit frustrated with them.
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.
hum, I see, that makes it complicated.
Having to use fields in a pullzone datasource as workaround for the issue makes the Terraform provider difficult to use.
Users would need to know these API internals, that a videolib has an underlying pullzone, that some videolib attributes are stored in the pullzone and also the different attribute names.
A simple solution in other cases were a field was not retrievable via the Get endpoint was to mark the resource attribute as ForceNew: true
.
I don't know if that is feasible for those videolib attributes.
Would be having to recreated the videolib when these attributes are changed an option?
Otherwise I think it is better to do the additional pullzone get call in the ReadContext
function of the videolib.
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.
ForceNew isn't really an option. It would delete all of your video content. As of the current state of the videolibrary resource I did something similar to what we did on the custom_404 property for storage zones if you recall that. Effectively, if the API call succeeds we just update the state to whatever value was sent to bunny. Which seems finish... until I found a bug in the bunny API where they were silently failing to set those properties in certain circumstances (I filed a bug report with them and they're going to fix it).
But still, stuff like that can happen unless you do a hard read on them.
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.
Also, if we're going to read the pullzone in the bunny videolibrary resource, then it seems like we might as well return the entire data set that we care about from it instead of doing a datasource. The data source seemed like a cleaner way at first, but maybe that should be considered instead.
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.
Also, if we're going to read the pullzone in the bunny videolibrary resource, then it seems like we might as well return the entire data set that we care about from it instead of doing a datasource.
Let's go for that solution.
Hiding these ugly internals to make the provider easier to use will be worth the additional api requests and code.
c6a8ce6
to
1f0bb76
Compare
No description provided.