Skip to content

Commit

Permalink
Merge pull request #1035 from linode/dev
Browse files Browse the repository at this point in the history
Release v2.8.0
  • Loading branch information
amisiorek-akamai authored Sep 26, 2023
2 parents 100b5d6 + 9772b2b commit 973ae14
Show file tree
Hide file tree
Showing 45 changed files with 748 additions and 189 deletions.
60 changes: 59 additions & 1 deletion .github/workflows/integration_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,64 @@ jobs:
with:
go-version: 'stable'
- run: go version
- run: make testacc

- name: Update system packages
run: sudo apt-get update -y

- name: Install system deps
run: sudo apt-get install -y build-essential

- name: Setup Python
uses: actions/setup-python@v4
with:
python-version: '3.x'

- name: Install Python deps
run: pip3 install requests wheel boto3

- name: Set release version env
run: echo "RELEASE_VERSION=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV

- name: Install go-junit-report
run: go install github.com/jstemmer/go-junit-report/v2@latest

- run: |
timestamp=$(date +'%Y%m%d%H%M')
report_filename="${timestamp}_terraform_test_report.json"
make testacc TESTARGS="-json" | tee "$report_filename"
env:
LINODE_TOKEN: ${{ secrets.DX_LINODE_TOKEN }}
- name: Convert JSON Report to XML
run: |
filename=$(ls | grep -E '^[0-9]{12}_terraform_test_report\.json')
if [ -f "$filename" ]; then
go_junit_report_dir=$(go env GOPATH)/bin
export PATH="$PATH:$go_junit_report_dir"
xml_filename=$(echo "$filename" | sed 's/\.json$/.xml/')
go-junit-report < "$filename" > "$xml_filename"
echo "Conversion from JSON to XML completed successfully."
else
echo "JSON test report file not found."
exit 1
fi
env:
GO111MODULE: on

- name: Add additional information to XML report
run: |
filename=$(ls | grep -E '^[0-9]{12}_terraform_test_report\.xml$')
python scripts/add_to_xml_test_report.py \
--branch_name "${{ env.RELEASE_VERSION }}" \
--gha_run_id "$GITHUB_RUN_ID" \
--gha_run_number "$GITHUB_RUN_NUMBER" \
--xmlfile "${filename}"
- name: Upload test results to bucket
run: |
report_filename=$(ls | grep -E '^[0-9]{12}_terraform_test_report\.xml$')
python3 scripts/test_report_upload_script.py "${report_filename}"
env:
LINODE_CLI_OBJ_ACCESS_KEY: ${{ secrets.LINODE_CLI_OBJ_ACCESS_KEY }}
LINODE_CLI_OBJ_SECRET_KEY: ${{ secrets.LINODE_CLI_OBJ_SECRET_KEY }}
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ jobs:
gpg_private_key: ${{ secrets.GPG_PRIVATE_KEY }}
passphrase: ${{ secrets.PASSPHRASE }}
- name: Run GoReleaser
uses: goreleaser/goreleaser-action@5fdedb94abba051217030cc86d4523cf3f02243d # pin@v4.6.0
uses: goreleaser/goreleaser-action@7ec5c2b0c6cdda6e8bbb49444bc797dd33d74dd8 # pin@v5.0.0
with:
version: latest
args: release --rm-dist
Expand Down
8 changes: 8 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ linters-settings:
check-type-assertions: true
check-blank: true

gomoddirectives:
replace-allow-list:
- github.com/linode/linodego

govet:
check-shadowing: true

Expand Down Expand Up @@ -75,6 +79,9 @@ linters:
- gocritic
- scopelint

# Not useful because we widely use open-source dependencies.
- depguard

# These ignores have been added to maintain compatibility with the existing codebase.
# These issues should be resolved at a later date.
- wrapcheck
Expand All @@ -97,5 +104,6 @@ linters:
- errorlint
- forbidigo
- godot
- gomoddirectives

fast: false
10 changes: 5 additions & 5 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,19 @@ require (
github.com/hashicorp/terraform-plugin-mux v0.12.0
github.com/hashicorp/terraform-plugin-sdk/v2 v2.29.0
github.com/hashicorp/terraform-plugin-testing v1.5.1
github.com/linode/linodego v1.21.0
github.com/linode/linodego v1.22.0
github.com/linode/linodego/k8s v0.0.0-20200831124119-58d5d5bb7947
github.com/stretchr/testify v1.8.4
golang.org/x/crypto v0.13.0
golang.org/x/net v0.15.0
)

require (
github.com/ProtonMail/go-crypto v0.0.0-20230717121422-5aa5874ade95 // indirect
github.com/apparentlymart/go-textseg/v15 v15.0.0 // indirect
github.com/cloudflare/circl v1.3.3 // indirect
github.com/mattn/go-isatty v0.0.14 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
golang.org/x/exp v0.0.0-20230809150735-7b3493d9a819 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20230525234030-28d5490b6b19 // indirect
)

require (
Expand Down Expand Up @@ -56,7 +56,6 @@ require (
github.com/jmespath/go-jmespath v0.4.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/mattn/go-colorable v0.1.12 // indirect
github.com/mattn/go-isatty v0.0.14 // indirect
github.com/mitchellh/copystructure v1.2.0 // indirect
github.com/mitchellh/go-testing-interface v1.14.1 // indirect
github.com/mitchellh/go-wordwrap v1.0.0 // indirect
Expand All @@ -70,14 +69,15 @@ require (
github.com/vmihailenco/msgpack/v5 v5.3.5 // indirect
github.com/vmihailenco/tagparser/v2 v2.0.0 // indirect
github.com/zclconf/go-cty v1.14.0 // indirect
golang.org/x/exp v0.0.0-20230809150735-7b3493d9a819 // indirect
golang.org/x/mod v0.12.0 // indirect
golang.org/x/net v0.14.0 // indirect
golang.org/x/oauth2 v0.7.0 // indirect
golang.org/x/sys v0.12.0 // indirect
golang.org/x/term v0.12.0 // indirect
golang.org/x/text v0.13.0 // indirect
golang.org/x/time v0.0.0-20210723032227-1f47c861a9ac // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20230525234030-28d5490b6b19 // indirect
google.golang.org/grpc v1.57.0 // indirect
google.golang.org/protobuf v1.31.0 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -302,8 +302,8 @@ github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0SNc=
github.com/linode/linodego v0.20.1/go.mod h1:XOWXRHjqeU2uPS84tKLgfWIfTlv3TYzCS0io4GOQzEI=
github.com/linode/linodego v1.21.0 h1:VIco962oysKyNM7xkFGto+6ZwsepKbxeHDGBTLlqB4w=
github.com/linode/linodego v1.21.0/go.mod h1:eDc/1GxYzNsNfDTC/8QKuMJNkdfN/ndYwldupf4ue1M=
github.com/linode/linodego v1.22.0 h1:YWBs0MnTcPue4qI6N3l05lxJ+mLp9CM0F7nui8k4gi0=
github.com/linode/linodego v1.22.0/go.mod h1:K5PlGeJzVo47S2v7bsDi20DbgTxdHT9dVLi6de2NerI=
github.com/linode/linodego/k8s v0.0.0-20200831124119-58d5d5bb7947 h1:e+tpC7AIiEgfYGEDq9Rjtdybq+V10S6OXzWjeGV/CEk=
github.com/linode/linodego/k8s v0.0.0-20200831124119-58d5d5bb7947/go.mod h1:MWI0tFyaJqRpirMv0VO7CGYT4V3IhHvml2rs/DlRQmY=
github.com/mailru/easyjson v0.0.0-20160728113105-d5b7844b561a/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc=
Expand Down Expand Up @@ -499,8 +499,8 @@ golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug
golang.org/x/net v0.2.0/go.mod h1:KqCZLdyyvdV855qA2rE3GC2aiw5xGR5TEjj8smXukLY=
golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs=
golang.org/x/net v0.8.0/go.mod h1:QVkue5JL9kW//ek3r6jTKnTFis1tRmNAW2P1shuFdJc=
golang.org/x/net v0.14.0 h1:BONx9s002vGdD9umnlX1Po8vOZmrgH34qlHcD1MfK14=
golang.org/x/net v0.14.0/go.mod h1:PpSgVXXLK0OxS0F31C1/tv6XNguvCrnXIDrFMspZIUI=
golang.org/x/net v0.15.0 h1:ugBLEUaxABaB5AJqW9enI0ACdci2RUd4eP51NTBvuJ8=
golang.org/x/net v0.15.0/go.mod h1:idbUs1IY1+zTqbi8yxTbhexhEEk5ur9LInksu6HrEpk=
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
Expand Down
4 changes: 2 additions & 2 deletions linode/acceptance/test_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -428,9 +428,9 @@ func CheckVolumeExists(name string, volume *linodego.Volume) resource.TestCheckF
}
}

func CheckFirewallExists(provider *schema.Provider, name string, firewall *linodego.Firewall) resource.TestCheckFunc {
func CheckFirewallExists(name string, firewall *linodego.Firewall) resource.TestCheckFunc {
return func(s *terraform.State) error {
client := provider.Meta().(*helper.ProviderMeta).Client
client := TestAccProvider.Meta().(*helper.ProviderMeta).Client

rs, ok := s.RootModule().Resources[name]
if !ok {
Expand Down
8 changes: 8 additions & 0 deletions linode/acceptance/tmpl/provider_no_poll.gotf
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{{ define "provider_no_poll" }}

provider "linode" {
skip_instance_delete_poll = true
skip_instance_ready_poll = true
}

{{ end }}
15 changes: 15 additions & 0 deletions linode/acceptance/tmpl/template.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package tmpl

import (
"testing"

"github.com/linode/terraform-provider-linode/linode/acceptance"
)

// ProviderNoPoll is used to configure the provider to disable instance
// polling.
func ProviderNoPoll(t *testing.T) string {
return acceptance.ExecuteTemplate(t,
"provider_no_poll", nil,
)
}
2 changes: 1 addition & 1 deletion linode/databasemysql/framework_models_unit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func TestParseMySQLDatabase(t *testing.T) {
assert.Contains(t, data.AllowList.String(), "203.0.113.1/32")
assert.Contains(t, data.AllowList.String(), "192.0.1.0/24")

assert.Contains(t, data.Updates.String(), "sunday")
assert.Contains(t, data.Updates.String(), "monday")
assert.Contains(t, data.Updates.String(), "3")
assert.Contains(t, data.Updates.String(), "weekly")
assert.Contains(t, data.Updates.String(), "0")
Expand Down
2 changes: 1 addition & 1 deletion linode/databasepostgresql/framework_models_unit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func TestParsePostgresDatabase(t *testing.T) {
assert.Equal(t, types.StringValue("lin-0000-000-pgsql-primary.servers.linodedb.net"), data.HostPrimary)
assert.Equal(t, types.StringValue("lin-0000-000-pgsql-primary-private.servers.linodedb.net"), data.HostSecondary)

assert.Contains(t, data.Updates.String(), "sunday")
assert.Contains(t, data.Updates.String(), "monday")
assert.Contains(t, data.Updates.String(), "3")
assert.Contains(t, data.Updates.String(), "weekly")
assert.Contains(t, data.Updates.String(), "0")
Expand Down
5 changes: 3 additions & 2 deletions linode/firewall/datasource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,9 @@ func TestAccDataSourceFirewall_basic(t *testing.T) {
resource.TestCheckResourceAttr(testFirewallDataName, "outbound.0.ipv4.0", "0.0.0.0/0"),
resource.TestCheckResourceAttr(testFirewallDataName, "outbound.0.ipv6.#", "1"),
resource.TestCheckResourceAttr(testFirewallDataName, "outbound.0.ipv6.0", "2001:db8::/32"),
resource.TestCheckResourceAttr(testFirewallDataName, "devices.#", "1"),
resource.TestCheckResourceAttr(testFirewallDataName, "devices.0.type", "linode"),
resource.TestCheckResourceAttr(testFirewallDataName, "devices.#", "2"),
resource.TestCheckResourceAttrSet(testFirewallDataName, "devices.0.type"),
resource.TestCheckResourceAttr(testFirewallDataName, "nodebalancers.#", "1"),
resource.TestCheckResourceAttr(testFirewallDataName, "linodes.#", "1"),
resource.TestCheckResourceAttr(testFirewallDataName, "tags.#", "1"),
resource.TestCheckResourceAttr(testFirewallDataName, "tags.0", "test"),
Expand Down
20 changes: 19 additions & 1 deletion linode/firewall/firewall_helpers_unit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func compareRule(rule map[string]interface{}, expected map[string]interface{}) b
}

// Unit tests for private functions in helper
// Functions under test: expandFirewallStatus, expandFirewallRules, flattenFirewallLinodes, flattenFirewallRules, flattenFirewallDevices
// Functions under test: expandFirewallStatus, expandFirewallRules, flattenFirewallDeviceIDs, flattenFirewallRules, flattenFirewallDevices

func TestExpandFirewallStatus(t *testing.T) {
testCases := []struct {
Expand Down Expand Up @@ -176,6 +176,13 @@ func TestFlattenFirewallDevices(t *testing.T) {
URL: "test-firewall.example-2.com",
}

deviceEntity3 := linodego.FirewallDeviceEntity{
ID: 3333,
Type: linodego.FirewallDeviceNodeBalancer,
Label: "device_entity_3",
URL: "test-firewall.example-3.com",
}

devices := []linodego.FirewallDevice{
{
ID: 123,
Expand All @@ -185,6 +192,10 @@ func TestFlattenFirewallDevices(t *testing.T) {
ID: 1234,
Entity: deviceEntity2,
},
{
ID: 12345,
Entity: deviceEntity3,
},
}

expected := []map[string]interface{}{
Expand All @@ -202,6 +213,13 @@ func TestFlattenFirewallDevices(t *testing.T) {
"label": "device_entity_2",
"url": "test-firewall.example-2.com",
},
{
"id": 12345,
"entity_id": 3333,
"type": linodego.FirewallDeviceNodeBalancer,
"label": "device_entity_3",
"url": "test-firewall.example-3.com",
},
}

result := flattenFirewallDevices(devices)
Expand Down
27 changes: 21 additions & 6 deletions linode/firewall/framework_models.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ type FirewallModel struct {
Outbound types.List `tfsdk:"outbound"`
OutboundPolicy types.String `tfsdk:"outbound_policy"`
Linodes types.Set `tfsdk:"linodes"`
NodeBalancers types.Set `tfsdk:"nodebalancers"`
Devices types.List `tfsdk:"devices"`
Status types.String `tfsdk:"status"`
Created types.String `tfsdk:"created"`
Expand All @@ -40,12 +41,26 @@ func (data *FirewallModel) parseComputedAttributes(
data.Created = types.StringValue(firewall.Created.Format(helper.TIME_FORMAT))
data.Updated = types.StringValue(firewall.Updated.Format(helper.TIME_FORMAT))

linodes, diags := types.SetValueFrom(ctx, types.Int64Type, AggregateLinodeIDs(devices))
linodes, diags := types.SetValueFrom(
ctx,
types.Int64Type,
AggregateEntityIDs(devices, linodego.FirewallDeviceLinode),
)
if diags.HasError() {
return diags
}
data.Linodes = linodes

nodebalancers, diags := types.SetValueFrom(
ctx,
types.Int64Type,
AggregateEntityIDs(devices, linodego.FirewallDeviceNodeBalancer),
)
if diags.HasError() {
return diags
}
data.NodeBalancers = nodebalancers

firewallDevices, diags := parseFirewallDevices(devices)
if diags.HasError() {
return diags
Expand Down Expand Up @@ -133,14 +148,14 @@ func parseFirewallRules(
return &result, nil
}

func AggregateLinodeIDs(devices []linodego.FirewallDevice) []int {
linodes := make([]int, 0, len(devices))
func AggregateEntityIDs(devices []linodego.FirewallDevice, entityType linodego.FirewallDeviceType) []int {
results := make([]int, 0, len(devices))
for _, device := range devices {
if device.Entity.Type == linodego.FirewallDeviceLinode {
linodes = append(linodes, device.Entity.ID)
if device.Entity.Type == entityType {
results = append(results, device.Entity.ID)
}
}
return linodes
return results
}

func parseFirewallDevices(devices []linodego.FirewallDevice) (*basetypes.ListValue, diag.Diagnostics) {
Expand Down
18 changes: 14 additions & 4 deletions linode/firewall/framework_models_unit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,21 @@ func TestParseComputedAttributes(t *testing.T) {
Label: "device_entity_1",
URL: "test-firewall.example.com",
}
deviceEntity2 := linodego.FirewallDeviceEntity{
ID: 4321,
Type: linodego.FirewallDeviceNodeBalancer,
Label: "device_entity_2",
URL: "test-firewall.example.com",
}
devices := []linodego.FirewallDevice{
{
ID: 111,
Entity: deviceEntity1,
},
{
ID: 112,
Entity: deviceEntity2,
},
}

data := &FirewallModel{}
Expand All @@ -45,11 +55,11 @@ func TestParseComputedAttributes(t *testing.T) {
assert.Equal(t, int64(123), data.ID.ValueInt64())
assert.Contains(t, data.Status.String(), string(linodego.FirewallEnabled))

expectedLinodeID := "1234"
assert.Contains(t, data.Linodes.String(), expectedLinodeID)
assert.Contains(t, data.Linodes.String(), "1234")
assert.Contains(t, data.NodeBalancers.String(), "4321")

expectedDevicesID := "111"
assert.Contains(t, data.Devices.String(), expectedDevicesID)
assert.Contains(t, data.Devices.String(), "111")
assert.Contains(t, data.Devices.String(), "112")
}

func TestParseNonComputedAttributes(t *testing.T) {
Expand Down
7 changes: 6 additions & 1 deletion linode/firewall/framework_schema_datasource.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,12 @@ var frameworkDatasourceSchema = schema.Schema{
},
"linodes": schema.SetAttribute{
ElementType: types.Int64Type,
Description: "The IDs of Linodes to apply this firewall to.",
Description: "The IDs of Linodes assigned to this Firewall.",
Computed: true,
},
"nodebalancers": schema.SetAttribute{
ElementType: types.Int64Type,
Description: "The IDs of NodeBalancers assigned to this Firewall.",
Computed: true,
},
"devices": schema.ListAttribute{
Expand Down
Loading

0 comments on commit 973ae14

Please sign in to comment.