-
Notifications
You must be signed in to change notification settings - Fork 11
In-place update for VPC firewall rules #432
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
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
ba991d3
In-place update for VPC firewall rules
karencfv 4e34a5b
oxide_vpc_firewall_rules: update acceptance tests
sudomateo b458c03
oxide_vpc_firewall_rules: support removing all vpc rules
sudomateo ce564af
makefile: update lint tool version
sudomateo 853e96c
oxide_vpc_firewall_rules: update documentation
sudomateo 0fcdddd
debug ci/cd
sudomateo b20322f
changelog
karencfv File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -28,4 +28,4 @@ jobs: | |
| - name: test | ||
| run: make test | ||
| - name: lint | ||
| run: sudo make lint | ||
| run: make lint | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| terraform { | ||
| required_version = ">= 1.0" | ||
| required_version = ">= 1.11" | ||
|
|
||
| required_providers { | ||
| oxide = { | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| terraform { | ||
| required_version = ">= 1.0" | ||
| required_version = ">= 1.11" | ||
|
|
||
| required_providers { | ||
| oxide = { | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| terraform { | ||
| required_version = ">= 1.0" | ||
| required_version = ">= 1.11" | ||
|
|
||
| required_providers { | ||
| oxide = { | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| terraform { | ||
| required_version = ">= 1.0" | ||
| required_version = ">= 1.11" | ||
|
|
||
| required_providers { | ||
| oxide = { | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,7 +19,6 @@ import ( | |
| "github.com/hashicorp/terraform-plugin-framework/resource" | ||
| "github.com/hashicorp/terraform-plugin-framework/resource/schema" | ||
| "github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier" | ||
| "github.com/hashicorp/terraform-plugin-framework/resource/schema/setplanmodifier" | ||
| "github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier" | ||
| "github.com/hashicorp/terraform-plugin-framework/schema/validator" | ||
| "github.com/hashicorp/terraform-plugin-framework/types" | ||
|
|
@@ -114,9 +113,6 @@ func (r *vpcFirewallRulesResource) Schema(ctx context.Context, _ resource.Schema | |
| "rules": schema.SetNestedAttribute{ | ||
| Required: true, | ||
| Description: "Associated firewall rules.", | ||
| PlanModifiers: []planmodifier.Set{ | ||
| setplanmodifier.RequiresReplace(), | ||
| }, | ||
| NestedObject: schema.NestedAttributeObject{ | ||
| Attributes: map[string]schema.Attribute{ | ||
| "action": schema.StringAttribute{ | ||
|
|
@@ -495,14 +491,18 @@ func (r *vpcFirewallRulesResource) Delete(ctx context.Context, req resource.Dele | |
| tflog.Trace(ctx, fmt.Sprintf("deleted firewall rules for VPC with ID: %v", state.VPCID.ValueString()), map[string]any{"success": true}) | ||
| } | ||
|
|
||
| // newVPCFirewallRulesUpdateBody builds the parameters required by the Oxide | ||
| // vpc_firewall_rules_update API using the specified rules. | ||
| func newVPCFirewallRulesUpdateBody(rules []vpcFirewallRulesResourceRuleModel) *oxide.VpcFirewallRuleUpdateParams { | ||
| var updateRules []oxide.VpcFirewallRuleUpdate | ||
| // The make builtin is used to explicitly get an empty slice rather than a zero | ||
| // value slice for the use case of removing all the firewall rules from a VPC. | ||
| // | ||
| // This is necessary because of the following. | ||
| // * The vpc_firewall_rules_update API requires `{"rules": []}` to remove all rules. | ||
| // * [oxide.VpcFirewallRuleUpdateParams] uses `omitzero` on its Rules field. | ||
| updateRules := make([]oxide.VpcFirewallRuleUpdate, 0) | ||
| body := new(oxide.VpcFirewallRuleUpdateParams) | ||
|
|
||
| if rules == nil { | ||
| return body | ||
| } | ||
|
|
||
|
Comment on lines
-502
to
-505
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No longer needed because the range below will not run when nil. |
||
| for _, rule := range rules { | ||
| r := oxide.VpcFirewallRuleUpdate{ | ||
| Action: oxide.VpcFirewallRuleAction(rule.Action.ValueString()), | ||
|
|
@@ -523,8 +523,13 @@ func newVPCFirewallRulesUpdateBody(rules []vpcFirewallRulesResourceRuleModel) *o | |
| return body | ||
| } | ||
|
|
||
| // newVPCFirewallRulesModel translates a slice of [oxide.VpcFirewallRule] into a | ||
| // slice of [vpcFirewallRulesResourceRuleModel]. | ||
| func newVPCFirewallRulesModel(rules []oxide.VpcFirewallRule) ([]vpcFirewallRulesResourceRuleModel, diag.Diagnostics) { | ||
| var model []vpcFirewallRulesResourceRuleModel | ||
| // The make builtin is used to explicitly get an empty slice rather than a zero | ||
| // value slice for the use case of removing all the firewall rules from a VPC. | ||
| // See the comment within [newVPCFirewallRulesUpdateBody] for more information. | ||
| model := make([]vpcFirewallRulesResourceRuleModel, 0) | ||
|
|
||
| for _, rule := range rules { | ||
| m := vpcFirewallRulesResourceRuleModel{ | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
@karencfv I didn't see why the
sudowas added in the blamed commit (#95). I removed it because it was causing the runner to fall back to the version of Go included in the runner rather than the version of Go installed bysetup-go.