Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions .changelog/0.10.0.toml
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
[[breaking]]
title = "Minimum Terraform version required"
description = "`oxide_silo` [#425](https://github.com/oxidecomputer/terraform-provider-oxide/pull/425). Breaking change due to `tls_certificates` attribute being a
[write-only attribute](https://developer.hashicorp.com/terraform/plugin/framework/resources/write-only-arguments)."
title = "Minimum Terraform version v1.11 required"
description = "Due to the introduction of [write-only attributes](https://developer.hashicorp.com/terraform/plugin/framework/resources/write-only-arguments) in the new `oxide_silo` resoucre, the minimum Terraform version is now v1.11 [#425](https://github.com/oxidecomputer/terraform-provider-oxide/pull/425)."

[[features]]
title = "New resource"
description = "`oxide_silo` [#425](https://github.com/oxidecomputer/terraform-provider-oxide/pull/425)."

[[features]]
title = "New data resource"
description = "`oxide_vpc_router_route` [#423](https://github.com/oxidecomputer/terraform-provider-oxide/pull/423)."

[[enhancements]]
title = ""
description = ""
title = "VPC firewall rules resource"
description = "In place updates are now supported [#432](https://github.com/oxidecomputer/terraform-provider-oxide/pull/432)"

[[bugs]]
title = ""
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/build-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@ jobs:
- name: test
run: make test
- name: lint
run: sudo make lint
run: make lint
Copy link
Collaborator

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 sudo was 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 by setup-go.

10 changes: 5 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -113,11 +113,11 @@ sdk-version:
# This way linting tools don't need to be downloaded/installed every time you
# want to run the linters.
VERSION_DIR:=$(GOBIN)/versions
VERSION_GOLANGCILINT:=v1.61.0
VERSION_TFPROVIDERDOCS:=v0.9.1
VERSION_TERRAFMT:=v0.5.2
VERSION_TFPROVIDERLINT:=v0.30.0
VERSION_WHATSIT:=7fd2b385f
VERSION_GOLANGCILINT:=v1.64.8
VERSION_TFPROVIDERDOCS:=v0.12.1
VERSION_TERRAFMT:=v0.5.4
VERSION_TFPROVIDERLINT:=v0.31.0
VERSION_WHATSIT:=053446d

tools: $(GOBIN)/golangci-lint $(GOBIN)/tfproviderdocs $(GOBIN)/terrafmt $(GOBIN)/tfproviderlint

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ To generate a token, follow these steps:

```hcl
terraform {
required_version = ">= 1.0"
required_version = ">= 1.11"

required_providers {
oxide = {
Expand Down
2 changes: 1 addition & 1 deletion docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ Note: Cannot use `profile` with `host` and `token` arguments and vice versa.

```hcl
terraform {
required_version = ">= 1.0"
required_version = ">= 1.11"

required_providers {
oxide = {
Expand Down
6 changes: 5 additions & 1 deletion docs/resources/oxide_vpc_firewall_rules.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ This resource manages VPC firewall rules.
!> Firewall rules defined by this resource are considered exhaustive and will
overwrite any other firewall rules for the VPC once applied.

!> Setting the `rules` attribute to `[]` will delete all firewall rules for the
VPC which may cause undesired network traffic. Please double check the firewall
rules when updating this resource.

## Example Usage

```hcl
Expand Down Expand Up @@ -48,7 +52,7 @@ resource "oxide_vpc_firewall_rules" "example" {
### Required

- `vpc_id` (String) ID of the VPC that will have the firewall rules applied to.
- `rules` (Set) Associated firewall rules. Updates require replacement. (see [below for nested schema](#nestedatt--rules))
- `rules` (Set) Associated firewall rules. Set to `[]` to delete all firewall rules. (see [below for nested schema](#nestedatt--rules))

### Optional

Expand Down
2 changes: 1 addition & 1 deletion examples/demo/demo.tf
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 = {
Expand Down
2 changes: 1 addition & 1 deletion examples/disk_resource/disk.tf
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 = {
Expand Down
2 changes: 1 addition & 1 deletion examples/instance_resource/instance.tf
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 = {
Expand Down
2 changes: 1 addition & 1 deletion examples/vpc_resource/vpc.tf
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 = {
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/oxidecomputer/terraform-provider-oxide

go 1.23.0
go 1.24.3

require (
github.com/google/uuid v1.6.0
Expand All @@ -11,7 +11,7 @@ require (
github.com/hashicorp/terraform-plugin-log v0.9.0
github.com/hashicorp/terraform-plugin-sdk/v2 v2.37.0
github.com/hashicorp/terraform-plugin-testing v1.13.1
github.com/oxidecomputer/oxide.go v0.4.1-0.20250423011427-65b1d0f6b391
github.com/oxidecomputer/oxide.go v0.4.1-0.20250530023940-ecfa72d833e0
github.com/stretchr/testify v1.10.0
)

Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,8 @@ github.com/mitchellh/reflectwalk v1.0.2 h1:G2LzWKi524PWgd3mLHV8Y5k7s6XUvT0Gef6zx
github.com/mitchellh/reflectwalk v1.0.2/go.mod h1:mSTlrgnPZtwu0c4WaC2kGObEpuNDbx0jmZXqmk4esnw=
github.com/oklog/run v1.0.0 h1:Ru7dDtJNOyC66gQ5dQmaCa0qIsAUFY3sFpK1Xk8igrw=
github.com/oklog/run v1.0.0/go.mod h1:dlhp/R75TPv97u0XWUtDeV/lRKWPKSdTuV0TZvrmrQA=
github.com/oxidecomputer/oxide.go v0.4.1-0.20250423011427-65b1d0f6b391 h1:q/ebxcSiqQrrdmDsd+w7gwqZUcGhpHmY9Bu2uYKNGL8=
github.com/oxidecomputer/oxide.go v0.4.1-0.20250423011427-65b1d0f6b391/go.mod h1:yNLdQdroM42/yDIFlCsLAR9PawAdeJZDgHdAx+wcywg=
github.com/oxidecomputer/oxide.go v0.4.1-0.20250530023940-ecfa72d833e0 h1:P/pU75YLSgM9vIbdTyAc92H9k+yuXYWLTzaMk71QubA=
github.com/oxidecomputer/oxide.go v0.4.1-0.20250530023940-ecfa72d833e0/go.mod h1:4gfHlxdBQLs/34UbChPvINd+pGNAnGlASRGEd4xIz1Y=
github.com/pelletier/go-toml v1.9.5 h1:4yBQzkHv+7BHq2PQUZF3Mx0IYxG7LsP222s7Agd3ve8=
github.com/pelletier/go-toml v1.9.5/go.mod h1:u1nR/EPcESfeI/szUZKdtJ0xRNbUoANCkoOuaOx1Y+c=
github.com/pjbgf/sha1cd v0.3.2 h1:a9wb0bp1oC2TGwStyn0Umc/IGKQnEgF0vVaZ8QF8eo4=
Expand Down
25 changes: 15 additions & 10 deletions internal/provider/resource_vpc_firewall_rules.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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{
Expand Down Expand Up @@ -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
Copy link
Collaborator

Choose a reason for hiding this comment

The 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()),
Expand All @@ -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{
Expand Down
47 changes: 45 additions & 2 deletions internal/provider/resource_vpc_firewall_rules_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,24 @@ resource "oxide_vpc_firewall_rules" "{{.BlockName}}" {
}
`

var resourceFirewallRulesUpdateConfigTpl3 = `
data "oxide_project" "{{.SupportBlockName}}" {
name = "tf-acc-test"
}

resource "oxide_vpc" "{{.SupportBlockName2}}" {
project_id = data.oxide_project.{{.SupportBlockName}}.id
description = "a test vpc"
name = "{{.VPCName}}"
dns_name = "my-vpc-dns"
}

resource "oxide_vpc_firewall_rules" "{{.BlockName}}" {
vpc_id = oxide_vpc.{{.SupportBlockName2}}.id
rules = []
}
`

func TestAccCloudResourceFirewallRules_full(t *testing.T) {
blockName := newBlockName("firewall_rules")
supportBlockName := newBlockName("support")
Expand Down Expand Up @@ -202,7 +220,7 @@ func TestAccCloudResourceFirewallRules_full(t *testing.T) {
resourceFirewallRulesUpdateConfigTpl,
)
if err != nil {
t.Errorf("error parsing config template data: %e", err)
t.Errorf("error parsing update config template data: %e", err)
}

configUpdate2, err := parsedAccConfig(
Expand All @@ -215,7 +233,20 @@ func TestAccCloudResourceFirewallRules_full(t *testing.T) {
resourceFirewallRulesUpdateConfigTpl2,
)
if err != nil {
t.Errorf("error parsing config template data: %e", err)
t.Errorf("error parsing update config 2 template data: %e", err)
}

configUpdate3, err := parsedAccConfig(
resourceFirewallRulesConfig{
BlockName: blockName,
SupportBlockName: supportBlockName,
SupportBlockName2: supportBlockName2,
VPCName: vpcName,
},
resourceFirewallRulesUpdateConfigTpl3,
)
if err != nil {
t.Errorf("error parsing update config 3 template data: %e", err)
}

resource.ParallelTest(t, resource.TestCase{
Expand All @@ -235,6 +266,10 @@ func TestAccCloudResourceFirewallRules_full(t *testing.T) {
Config: configUpdate2,
Check: checkResourceFirewallRulesUpdate2(resourceName, vpcName),
},
{
Config: configUpdate3,
Check: checkResourceFirewallRulesUpdate3(resourceName),
},
},
})
}
Expand Down Expand Up @@ -321,6 +356,14 @@ func checkResourceFirewallRulesUpdate2(resourceName, vpcName string) resource.Te
}...)
}

func checkResourceFirewallRulesUpdate3(resourceName string) resource.TestCheckFunc {
return resource.ComposeAggregateTestCheckFunc([]resource.TestCheckFunc{
resource.TestCheckResourceAttrSet(resourceName, "id"),
resource.TestCheckResourceAttrSet(resourceName, "vpc_id"),
resource.TestCheckResourceAttr(resourceName, "rules.#", "0"),
}...)
}

func testAccFirewallRulesDestroy(s *terraform.State) error {
client, err := newTestClient()
if err != nil {
Expand Down