-
Notifications
You must be signed in to change notification settings - Fork 112
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 vcd_rde_behavior_invocation data source to invoke behaviors #1117
Add vcd_rde_behavior_invocation data source to invoke behaviors #1117
Conversation
Signed-off-by: abarreiro <[email protected]>
Signed-off-by: abarreiro <[email protected]>
Signed-off-by: abarreiro <[email protected]>
Signed-off-by: abarreiro <[email protected]>
Signed-off-by: abarreiro <[email protected]>
Signed-off-by: abarreiro <[email protected]>
Signed-off-by: abarreiro <[email protected]>
Signed-off-by: abarreiro <[email protected]>
Signed-off-by: abarreiro <[email protected]>
Signed-off-by: abarreiro <[email protected]>
Signed-off-by: abarreiro <[email protected]>
Signed-off-by: abarreiro <[email protected]>
Signed-off-by: abarreiro <[email protected]>
Signed-off-by: abarreiro <[email protected]>
Signed-off-by: abarreiro <[email protected]>
Signed-off-by: abarreiro <[email protected]>
Signed-off-by: abarreiro <[email protected]>
Signed-off-by: abarreiro <[email protected]>
Signed-off-by: abarreiro <[email protected]>
Signed-off-by: abarreiro <[email protected]>
Signed-off-by: abarreiro <[email protected]>
Signed-off-by: abarreiro <[email protected]>
Signed-off-by: abarreiro <[email protected]>
One thing that comes to mind: could we have the |
Signed-off-by: abarreiro <[email protected]>
It could be a good option indeed, and would be more optimal as one could use a variable to switch it on/off (more CI/CD friendly than adding/removing code). Also the caveat mentioned in the docs could be controlled in a better way (instead of using
|
Signed-off-by: abarreiro <[email protected]>
Signed-off-by: abarreiro <[email protected]>
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.
Successfully tested on 10.5.0, thanks for the feature!
Signed-off-by: abarreiro <[email protected]>
Signed-off-by: abarreiro <[email protected]>
Signed-off-by: abarreiro <[email protected]>
Overview
This PR adds a new data source to invoke RDE Interface/Type Behaviors.
Detailed description
We onboarded RDE Interface/Type Behaviors in v3.10.0 of the VCD Provider. For simplicity, let's say that a Behavior is an equivalent term for "function", so we're talking about invoking/calling functions, that are specified in RDE Interfaces/Types and invoked on RDEs. One could invoke them programatically using the Go SDK, but users may be in the need of invoking them directly using Terraform.
For that purpose, this PR onboards a new data source
vcd_rde_behavior_invocation
that behaves similarly to the HTTP data source created by HashiCorp, in the sense that it is an imperative concept (calling a function, calling a HTTP method) introduced in a declarative toolset.That's why it was created as a data source. While it would make more sense to have it as a resource, as conceptually this would fit more with the term "invocation" (as we know, a function invocation can mutate/write things), because invoking Behaviors can modify RDEs. But the implementation of a resource for such a "imperative" concept is tricky. You can check the section "Caveats of the resource implementation" to know more.
The data source is pretty trivial, it only has a Read operation that invokes the Behavior on every refresh, with the given arguments/metadata (if given), and writes the result of the invocation in a Computed field. This field can be pretty much anything, as the invocation returns the raw result (it could be a JSON, plain text, etc).
Caveats of the resource implementation
As we have Create, Update, Read and Delete, we would need a required argument
invoke_on_every_refresh
to decide whether we want to invoke the Behavior on every Read, or only during Create/Update. This has also an odd drawback that could be undesired, a Refresh and an Update would invoke the Behavior twice. We could make Update a no-op, but we need to be able to update arguments/metadata for the invocation. If we make Update a no-nop, we need to make everythingForceNew: true
, but this would give us the same situation.Also, Delete would be a no-op in any case.
While resource fits more with the concept of "invoking Behaviors can mutate RDEs", in reality the implementation is tricky and would be more complicated for end users. Also, we have the precedent of the HTTP Provider giving the
http
data source, despite one can do PUT/POST/DELETE calls with it. Probably they faced the same situation, which gets trivially solved with a data source.Other things included in this PR
Improvement: The field
rde_type_id
from resourcevcd_rde
does not haveForceNew: true
anymore. This was a bit inconvenient when one wanted to upgrade an RDE from one RDE Type to a newer version of the same, as it forced its deletion and re-creation, which may not suit all users needs. Now the RDE Type can be updated without any previous deletion, allowing smoother RDE Type version upgrades. Note: As stated in the updated documentation, one should only upgrade the RDE Type version. VCD API doesn't allow updating to a different type or downgrading the version.Fixes a bug that made impossible to delete
vcd_rde_type_behavior_acl
resources when the Access Level is the last one in the Behavior. This fix is automatically done taking the changes in Improve RDE related methods go-vcloud-director#615. The bug happened because the Provider callsSetBehaviorAccessControls
with a nil slice of Access Levels, and the method was not considering this case as special.Fixes the resource
vcd_rde_type_behavior_acl
to avoid race conditions when creating, updating or deleting more than one Access Level. This is fixed by using a mutex wheneverSetBehaviorAccessControls
method is used. The problem withSetBehaviorAccessControls
is that, as the name implies, sets whatever Access Levels are specified in the input, so two calls at the same time can override each other.