-
Notifications
You must be signed in to change notification settings - Fork 200
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
Protection and tools for managing stateful resources and avoiding deletion #901
Comments
@ekeren @staycoolcall911 I suspect this is something we will need to consider as P1 for beta given the fact that Terraform doesn't offer support for this (so this can't even be solved using plugins). |
I've bumped to P1 for now and we can discuss scope and priority for beta. |
See also #1054 |
This is p1 for RFC |
Did you consider making ID the key and not the value? bring cloud;
new cloud.Bucket();
bring cloud;
class MyStore {
new() {
new cloud.Bucket();
}
}
new MyStore();
My thinking that reading the diff file from left to right will be easier(starting with the key as the constant) |
some thoughts:
|
Not sure I understand... what's the use case? Are you referring to custom terraform resources?
Yes, good point. This is meant to prevent resource destruction caused by identity mapping. We should also address replacement protection, which I think terraform is very lousy about... I'll spin off another issue to discuss and focus this issue.
Yes, CLI should have
Yes. I am wondering if this is something we can implement as a platform provider, I'll open an issue to track. |
Use only the class name instead of the fully qualified name as the default preflight object ID because the namespace (e.g. `foo` in `foo.MyClass`) is a local name determined by the `bring` statement. Fixes #5564 BREAKING CHANGE: caution (and apologies)! This change is going to cause a replacement of any resource that didn't have an explicit identity. We are working to make it [safer and easier](#901) to control IDs of resources (especially ones with state).
…5658) Use only the class name instead of the fully qualified name as the default preflight object ID because the namespace (e.g. `foo` in `foo.MyClass`) is a local name determined by the `bring` statement. Fixes #5564 BREAKING CHANGE: Caution⚠️ (and apologies 🙏)! This change is going to cause a replacement of any resource that didn't have an explicit identity. We are working to make it [safer and easier](#901) to control IDs of resources (especially ones with state), but for now, if you wish to avoid the replacement, you'll need to add `as "cloud.Xxx"` to explicitly use the old naming. Don't hesitate to [ping us](https://t.winglang.io/slack) and we will help out with migration as needed. ## Checklist - [x] Title matches [Winglang's style guide](https://www.winglang.io/contributing/start-here/pull_requests#how-are-pull-request-titles-formatted) - [x] Description explains motivation and solution - [x] Tests added (always) - [x] Docs updated (only required for features) - [x] Added `pr/e2e-full` label if this feature requires end-to-end testing *By submitting this pull request, I confirm that my contribution is made under the terms of the [Wing Cloud Contribution License](https://github.com/winglang/wing/blob/main/CONTRIBUTION_LICENSE.md)*.
RFC (Rev 1.)
Here's a proposal for a simple mechanism to prevent damage caused by logical name mapping changes.
If a resource is marked as
stateful
, it's Terraform resource name will be determined by looking up its path in a map stored in a<entrypoint>.w.lock
file, next to the entrypoint file, which will be committed to the repository.If an entry for this resource cannot be found in the lockfile, the compilation will fail and instruct the user to explicitly add an entry and provide a resource name.
Additionally, compilation will also fail if the file includes an entry that doesn't map to a stateful resource in the app.
This will ensure that:
We can offer some CLI commands to edit the lockfile, but that's not P1.
Here's an example.
Say I write this Wing called
hello.main.w
:Now, I compile:
Now, let's say we refactored the app and we will move the same bucket into a class:
At some point we can be smarter and offer a nice DX:
We can also offer some CLI commands to update:
$ wing state new /root/Bucket my_s3_bucket $ wing state mv /root/Bucket /root/MyStore/Bucket $ wing state rm /root/Bucket $ # etc
Original Feature Spec
Each Wing resource has a path that represents its unique address within the resource tree. This path is used to produce a deterministic Terraform identifier for each resource (which is what Terraform uses in its state file to map to the physical resource).
When refactoring code and resources are moved around, their Terraform identifier could change. In certain cases, especially for stateful resources with important data, this could be hazardous.
Wing resources can be explicitly marked as "stateful" or "stateless". If a resource is marked as "stateful", Wing will protect it from being accidentally deleted during deployment, and will offer a way to associated the
We provide some mechanism for you to relocate the terraform identifier of a resource in order to link the old identifier to the newly placed resource.
Use Cases
In some cases, users may want their Buckets to be emptied when their app is destroyed, while in other cases users may want their Buckets to be retained if their app is destroyed. (And in further cases, users may want to configure this on a per-Bucket basis).
The same general pattern applies to any stateful resource, including Counter etc.
Implementation Notes
Sadly, and surprisingly, Terraform's
prevent_destory
attribute cannot be used to implement this feature:This means that if the resource is completely removed from the configuration, it will be destroyed in the next
apply
.There is a heated conversation in this issue.
Alternatives to consider:
sql_database_instance
).Intuitively it feels like this is something Wing should handle regardless of the provisioning system, so I believe it's worth trying to find the right mechanism.
The text was updated successfully, but these errors were encountered: