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
3 changes: 2 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ jobs:
# list whatever Terraform versions here you would like to support
terraform:
- '1.0.*'
- '1.6.*'
# - '1.6.*'
steps:
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
- uses: actions/setup-go@0a12ed9d6a96ab950c8f026ed9f722fe0da7ef32 # v5.0.2
Expand All @@ -77,5 +77,6 @@ jobs:
- run: go mod download
- env:
TF_ACC: "1"
NETLIFY_API_TOKEN: ${{ secrets.NETLIFY_API_TOKEN }}
run: go test -v -cover ./internal/provider/
timeout-minutes: 10
3 changes: 2 additions & 1 deletion GNUmakefile
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,5 @@ test: ## Test the go code.
go test -v ./...

testacc:
TF_ACC=1 go test ./... -v $(TESTARGS) -timeout 120m
TF_ACC=1 go test ./... -v $(TESTARGS)
# -timeout 120m
29 changes: 20 additions & 9 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,21 @@ require (
)

require (
github.com/agext/levenshtein v1.2.2 // indirect
github.com/go-openapi/errors v0.22.0 // indirect
github.com/go-openapi/runtime v0.28.0 // indirect
github.com/go-openapi/strfmt v0.23.0 // indirect
github.com/go-openapi/swag v0.23.0 // indirect
github.com/go-openapi/validate v0.24.0 // indirect
github.com/google/go-cmp v0.6.0 // indirect
github.com/hashicorp/go-cty v1.4.1-0.20200414143053-d3edf31b6320 // indirect
github.com/hashicorp/go-retryablehttp v0.7.7 // indirect
github.com/hashicorp/hcl/v2 v2.21.0 // indirect
github.com/hashicorp/logutils v1.0.0 // indirect
github.com/hashicorp/terraform-plugin-sdk/v2 v2.34.0 // indirect
github.com/mitchellh/go-wordwrap v1.0.0 // indirect
github.com/vmihailenco/msgpack v4.0.4+incompatible // indirect
google.golang.org/appengine v1.6.8 // indirect
)

require (
Expand Down Expand Up @@ -51,13 +61,14 @@ require (
github.com/hashicorp/go-plugin v1.6.0 // indirect
github.com/hashicorp/go-uuid v1.0.3 // indirect
github.com/hashicorp/go-version v1.7.0 // indirect
github.com/hashicorp/hc-install v0.7.0 // indirect
github.com/hashicorp/hc-install v0.8.0 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/hashicorp/terraform-exec v0.21.0 // indirect
github.com/hashicorp/terraform-json v0.22.1 // indirect
github.com/hashicorp/terraform-plugin-framework-validators v0.13.0
github.com/hashicorp/terraform-plugin-go v0.23.0 // indirect
github.com/hashicorp/terraform-plugin-go v0.23.0
github.com/hashicorp/terraform-plugin-log v0.9.0 // indirect
github.com/hashicorp/terraform-plugin-testing v1.10.0
github.com/hashicorp/terraform-registry-address v0.2.3 // indirect
github.com/hashicorp/terraform-svchost v0.1.1 // indirect
github.com/hashicorp/yamux v0.1.1 // indirect
Expand Down Expand Up @@ -97,18 +108,18 @@ require (
github.com/vmihailenco/tagparser/v2 v2.0.0 // indirect
github.com/yuin/goldmark v1.7.1 // indirect
github.com/yuin/goldmark-meta v1.1.0 // indirect
github.com/zclconf/go-cty v1.14.4 // indirect
github.com/zclconf/go-cty v1.15.0 // indirect
go.abhg.dev/goldmark/frontmatter v0.2.0 // indirect
go.mongodb.org/mongo-driver v1.15.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
golang.org/x/crypto v0.23.0 // indirect
golang.org/x/crypto v0.26.0 // indirect
golang.org/x/exp v0.0.0-20240416160154-fe59bbe5cc7f // indirect
golang.org/x/mod v0.17.0 // indirect
golang.org/x/mod v0.19.0 // indirect
golang.org/x/net v0.25.0 // indirect
golang.org/x/sync v0.7.0 // indirect
golang.org/x/sys v0.20.0 // indirect
golang.org/x/text v0.15.0 // indirect
golang.org/x/tools v0.21.0 // indirect
golang.org/x/sync v0.8.0 // indirect
golang.org/x/sys v0.23.0 // indirect
golang.org/x/text v0.17.0 // indirect
golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240429193739-8cf5692501f6 // indirect
google.golang.org/grpc v1.63.2 // indirect
google.golang.org/protobuf v1.34.1 // indirect
Expand Down
79 changes: 59 additions & 20 deletions go.sum

Large diffs are not rendered by default.

60 changes: 60 additions & 0 deletions internal/provider/dns_record_resource_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package provider

import (
"context"
"fmt"
"testing"

"github.com/hashicorp/terraform-plugin-testing/helper/resource"
"github.com/hashicorp/terraform-plugin-testing/terraform"
)

var zoneId = "66afdbce3cf2b4f0fab520d9"

func TestAccDnsRecordA(t *testing.T) {
accTest(t, []resource.TestStep{
{
Config: fmt.Sprintf(`resource "netlify_dns_record" "example" {
type = "A"
zone_id = "%s"
hostname = "testacc.examplepetstore.com"
value = "10.0.0.0"
}`, zoneId),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("netlify_dns_record.example", "type", "A"),
resource.TestCheckResourceAttr("netlify_dns_record.example", "zone_id", zoneId),
resource.TestCheckResourceAttr("netlify_dns_record.example", "hostname", "testacc.examplepetstore.com"),
resource.TestCheckResourceAttr("netlify_dns_record.example", "value", "10.0.0.0"),
),
},
{
Config: fmt.Sprintf(`resource "netlify_dns_record" "example" {
type = "A"
zone_id = "%s"
hostname = "testacc.examplepetstore.com"
value = "10.0.0.1"
}`, zoneId),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("netlify_dns_record.example", "type", "A"),
resource.TestCheckResourceAttr("netlify_dns_record.example", "zone_id", zoneId),
resource.TestCheckResourceAttr("netlify_dns_record.example", "hostname", "testacc.examplepetstore.com"),
resource.TestCheckResourceAttr("netlify_dns_record.example", "value", "10.0.0.1"),
),
},
}, testAccDnsRecordCheckDestroy("testacc.examplepetstore.com"))
}

func testAccDnsRecordCheckDestroy(hostname string) func(s *terraform.State) error {
return func(s *terraform.State) error {
records, _, err := testAccProvider.client.DNSZonesAPI.GetDnsRecords(context.Background(), zoneId).Execute()
if err != nil {
return err
}
for _, record := range records {
if record.Hostname == hostname {
return fmt.Errorf("DNS record still exists")
}
}
return nil
}
}
4 changes: 2 additions & 2 deletions internal/provider/environment_variable_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ func (r *environmentVariableResource) Create(ctx context.Context, req resource.C
}
var values []netlifyapi.EnvVarValue
var isSecret bool
if plan.SecretValues != nil && len(plan.SecretValues) > 0 {
if len(plan.SecretValues) > 0 {
values = serializeValues(plan.SecretValues)
isSecret = true
} else {
Expand Down Expand Up @@ -308,7 +308,7 @@ func (r *environmentVariableResource) Update(ctx context.Context, req resource.U
}
var values []netlifyapi.EnvVarValue
var isSecret bool
if plan.SecretValues != nil && len(plan.SecretValues) > 0 {
if len(plan.SecretValues) > 0 {
values = serializeValues(plan.SecretValues)
isSecret = true
} else {
Expand Down
4 changes: 3 additions & 1 deletion internal/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ var _ provider.Provider = &NetlifyProvider{}

type NetlifyProvider struct {
version string
client *netlifyapi.APIClient
}

type NetlifyProviderModel struct {
Expand Down Expand Up @@ -158,7 +159,8 @@ func (p *NetlifyProvider) Configure(ctx context.Context, req provider.ConfigureR
apiConfig.UserAgent = "Terraform Provider"
apiConfig.AddDefaultHeader("Authorization", "Bearer "+token)
// TODO: Add debug/trace logging to the API client, perhaps by overriding the behavior of apiConfig.Debug
data.client = netlifyapi.NewAPIClient(apiConfig)
p.client = netlifyapi.NewAPIClient(apiConfig)
data.client = p.client

var account *netlifyapi.Account

Expand Down
30 changes: 30 additions & 0 deletions internal/provider/test_utils.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package provider

import (
"os"
"testing"

"github.com/hashicorp/terraform-plugin-framework/providerserver"
"github.com/hashicorp/terraform-plugin-go/tfprotov6"
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
)

var testAccProvider = &NetlifyProvider{version: "0.0.0-test"}

func accTest(t *testing.T, steps []resource.TestStep, checkDestroy resource.TestCheckFunc) {
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){
"netlify": providerserver.NewProtocol6WithError(testAccProvider),
},
CheckDestroy: checkDestroy,
Steps: steps,
})
}

func testAccPreCheck(t *testing.T) {
v := os.Getenv("NETLIFY_API_TOKEN")
if v == "" {
t.Fatal("NETLIFY_API_TOKEN must be set for acceptance tests")
}
}