Skip to content
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

PENG-2344: return zones with no records #293

Merged
merged 5 commits into from
Jul 12, 2023
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 2.0.4 (July 11, 2023)
* Version Bump to PENG-2344: Zone resource no longer returns record information
* Fixed bug in NotifyList headers

## 2.0.2 (March 14, 2023)
Version Bump to fix tagging issue

Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ require (
github.com/hashicorp/go-retryablehttp v0.7.2
github.com/hashicorp/terraform-plugin-sdk/v2 v2.24.1
github.com/stretchr/testify v1.8.1
gopkg.in/ns1/ns1-go.v2 v2.7.5
gopkg.in/ns1/ns1-go.v2 v2.7.7
)

require (
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -250,8 +250,8 @@ gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
gopkg.in/ns1/ns1-go.v2 v2.7.5 h1:tE4SLOAFx2YXawh6MPv57lmlaBFUTyxSYOWKOGDgkM4=
gopkg.in/ns1/ns1-go.v2 v2.7.5/go.mod h1:GMnKY+ZuoJ+lVLL+78uSTjwTz2jMazq6AfGKQOYhsPk=
gopkg.in/ns1/ns1-go.v2 v2.7.7 h1:rf5wQ+TZXKMjik/KJ/0c6McjyJBkThDtLvYLex/xdEI=
gopkg.in/ns1/ns1-go.v2 v2.7.7/go.mod h1:pfaU0vECVP7DIOr453z03HXS6dFJpXdNRwOyRzwmPSc=
gopkg.in/warnings.v0 v0.1.2 h1:wFXVbFY8DY5/xOe1ECiWdKCzZlxgshcYVNkBHstARME=
gopkg.in/warnings.v0 v0.1.2/go.mod h1:jksf8JmL6Qr/oQM2OXTHunEvvTAsrWBLb6OOjuVWRNI=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
Expand Down
2 changes: 1 addition & 1 deletion ns1/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
)

var (
clientVersion = "2.0.3"
clientVersion = "2.0.4"
providerUserAgent = "tf-ns1" + "/" + clientVersion
defaultRetryMax = 3
)
Expand Down
8 changes: 4 additions & 4 deletions ns1/resource_application.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ func resourceApplicationToResourceData(d *schema.ResourceData, a *pulsar.Applica
}
func defaultConfigToMap(d *pulsar.DefaultConfig) map[string]interface{} {
dm := make(map[string]interface{})
dm["http"] = d.Http
dm["https"] = d.Https
dm["http"] = d.HTTP
dm["https"] = d.HTTPS
dm["request_timeout_millis"] = d.RequestTimeoutMillis
dm["job_timeout_millis"] = d.JobTimeoutMillis
dm["use_xhr"] = d.UseXhr
Expand Down Expand Up @@ -116,11 +116,11 @@ func setDefaultConfig(ds interface{}) (d pulsar.DefaultConfig) {
d = pulsar.DefaultConfig{}
httpConf := defaultConfig["http"]
if httpConf != nil {
d.Http = httpConf.(bool)
d.HTTP = httpConf.(bool)
}
httpsConf := defaultConfig["https"]
if httpsConf != nil {
d.Https = httpsConf.(bool)
d.HTTPS = httpsConf.(bool)
}
xhrConf := defaultConfig["use_xhr"]
if xhrConf != nil {
Expand Down
17 changes: 9 additions & 8 deletions ns1/resource_application_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ package ns1

import (
"fmt"
ns1 "gopkg.in/ns1/ns1-go.v2/rest"
"gopkg.in/ns1/ns1-go.v2/rest/model/pulsar"
"log"
"testing"

ns1 "gopkg.in/ns1/ns1-go.v2/rest"
"gopkg.in/ns1/ns1-go.v2/rest/model/pulsar"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
Expand All @@ -19,8 +20,8 @@ func TestAccApplication_basic(t *testing.T) {
acctest.RandStringFromCharSet(15, acctest.CharSetAlphaNum),
)
d := pulsar.DefaultConfig{
Http: false,
Https: false,
HTTP: false,
HTTPS: false,
RequestTimeoutMillis: 0,
JobTimeoutMillis: 0,
UseXhr: false,
Expand Down Expand Up @@ -58,17 +59,17 @@ func TestAccApplication_updated(t *testing.T) {
acctest.RandStringFromCharSet(15, acctest.CharSetAlphaNum),
)
basicConfig := pulsar.DefaultConfig{
Http: false,
Https: false,
HTTP: false,
HTTPS: false,
RequestTimeoutMillis: 0,
JobTimeoutMillis: 0,
UseXhr: false,
StaticValues: false,
}

updatedConfig := pulsar.DefaultConfig{
Http: true,
Https: false,
HTTP: true,
HTTPS: false,
RequestTimeoutMillis: 100,
JobTimeoutMillis: 100,
UseXhr: false,
Expand Down
34 changes: 17 additions & 17 deletions ns1/resource_dns_view.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,41 +61,41 @@ func dnsView() *schema.Resource {
}
}

func dnsViewToResourceData(d *schema.ResourceData, v *dns.DNSView) error {
func dnsViewToResourceData(d *schema.ResourceData, v *dns.View) error {
d.SetId(v.Name)
d.Set("name", v.Name)
d.Set("created_at", v.Created_at)
d.Set("updated_at", v.Updated_at)
d.Set("read_acls", v.Read_acls)
d.Set("update_acls", v.Update_acls)
d.Set("created_at", v.CreatedAt)
d.Set("updated_at", v.UpdatedAt)
d.Set("read_acls", v.ReadACLs)
d.Set("update_acls", v.UpdateACLs)
d.Set("zones", v.Zones)
d.Set("networks", v.Networks)
d.Set("preference", v.Preference)

return nil
}

func resourceDataToDNSView(v *dns.DNSView, d *schema.ResourceData) error {
func resourceDataToDNSView(v *dns.View, d *schema.ResourceData) error {
v.Name = d.Get("name").(string)
v.Created_at = d.Get("created_at").(int)
v.Updated_at = d.Get("updated_at").(int)
v.CreatedAt = d.Get("created_at").(int)
v.UpdatedAt = d.Get("updated_at").(int)
if acls, ok := d.GetOk("read_acls"); ok {
readAclsRaw := acls.([]interface{})
v.Read_acls = make([]string, len(readAclsRaw))
v.ReadACLs = make([]string, len(readAclsRaw))
for i, readAcls := range readAclsRaw {
v.Read_acls[i] = readAcls.(string)
v.ReadACLs[i] = readAcls.(string)
}
} else {
v.Read_acls = []string{}
v.ReadACLs = []string{}
}
if acls, ok := d.GetOk("update_acls"); ok {
updateAclsRaw := acls.([]interface{})
v.Update_acls = make([]string, len(updateAclsRaw))
v.UpdateACLs = make([]string, len(updateAclsRaw))
for i, updateAcls := range updateAclsRaw {
v.Update_acls[i] = updateAcls.(string)
v.UpdateACLs[i] = updateAcls.(string)
}
} else {
v.Update_acls = []string{}
v.UpdateACLs = []string{}
}
if z, ok := d.GetOk("zones"); ok {
zonesRaw := z.(*schema.Set)
Expand Down Expand Up @@ -123,7 +123,7 @@ func resourceDataToDNSView(v *dns.DNSView, d *schema.ResourceData) error {
// DNSViewCreate creates the given DNS View in ns1
func DNSViewCreate(d *schema.ResourceData, meta interface{}) error {
client := meta.(*ns1.Client)
v := dns.DNSView{}
v := dns.View{}
if err := resourceDataToDNSView(&v, d); err != nil {
return err
}
Expand Down Expand Up @@ -154,7 +154,7 @@ func DNSViewRead(d *schema.ResourceData, meta interface{}) error {
// DNSViewUpdate updates the DNS view with given parameters in ns1
func DNSViewUpdate(view_schema *schema.ResourceData, meta interface{}) error {
client := meta.(*ns1.Client)
v := dns.DNSView{
v := dns.View{
Name: view_schema.Id(),
}
if err := resourceDataToDNSView(&v, view_schema); err != nil {
Expand All @@ -170,7 +170,7 @@ func DNSViewUpdate(view_schema *schema.ResourceData, meta interface{}) error {
// DNSViewDelete deletes the given DNS view from ns1
func DNSViewDelete(d *schema.ResourceData, meta interface{}) error {
client := meta.(*ns1.Client)
v := dns.DNSView{}
v := dns.View{}
resourceDataToDNSView(&v, d)
resp, err := client.View.Delete(v.Name)
d.SetId("")
Expand Down
18 changes: 9 additions & 9 deletions ns1/resource_dns_view_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
// Creating basic DNS view
func TestAccDNSView_basic(t *testing.T) {
var (
view = dns.DNSView{}
view = dns.View{}
viewName = fmt.Sprintf("terraform-test-%s.io", acctest.RandStringFromCharSet(15, acctest.CharSetAlphaNum))
viewPreference = 10
)
Expand Down Expand Up @@ -45,11 +45,11 @@ func TestAccDNSView_basic(t *testing.T) {
// Update DNS view
func TestAccDNSView_update(t *testing.T) {
var (
view = dns.DNSView{}
view = dns.View{}
viewName = fmt.Sprintf("terraform-test-%s.io", acctest.RandStringFromCharSet(15, acctest.CharSetAlphaNum))
viewPreference = 10

updatedView = dns.DNSView{}
updatedView = dns.View{}
updatedViewPreference = 5

zoneName = fmt.Sprintf("terraform-test-%s.io", acctest.RandStringFromCharSet(15, acctest.CharSetAlphaNum))
Expand Down Expand Up @@ -88,7 +88,7 @@ func TestAccDNSView_update(t *testing.T) {
// Manually deleting DNS View
func TestAccDNSView_ManualDelete(t *testing.T) {
var (
view = dns.DNSView{}
view = dns.View{}
viewName = fmt.Sprintf("terraform-test-%s.io", acctest.RandStringFromCharSet(15, acctest.CharSetAlphaNum))
viewPreference = 10
)
Expand Down Expand Up @@ -141,7 +141,7 @@ func testAccDNSViewUpdated(zoneName, viewName string, viewPreference int) string
`, zoneName, viewName, viewPreference)
}

func testAccCheckDNSViewName(view *dns.DNSView, expected string) resource.TestCheckFunc {
func testAccCheckDNSViewName(view *dns.View, expected string) resource.TestCheckFunc {
return func(s *terraform.State) error {
if view.Name != expected {
return fmt.Errorf("view.Name: got: %s want: %s", view.Name, expected)
Expand All @@ -150,7 +150,7 @@ func testAccCheckDNSViewName(view *dns.DNSView, expected string) resource.TestCh
}
}

func testAccCheckDNSViewPreference(view *dns.DNSView, expected int) resource.TestCheckFunc {
func testAccCheckDNSViewPreference(view *dns.View, expected int) resource.TestCheckFunc {
return func(s *terraform.State) error {
if view.Preference != expected {
return fmt.Errorf("view.Preference: got: %d want: %d", view.Preference, expected)
Expand All @@ -159,7 +159,7 @@ func testAccCheckDNSViewPreference(view *dns.DNSView, expected int) resource.Tes
}
}

func testAccCheckDNSViewZones(view *dns.DNSView, expected []string) resource.TestCheckFunc {
func testAccCheckDNSViewZones(view *dns.View, expected []string) resource.TestCheckFunc {
return func(s *terraform.State) error {
if !reflect.DeepEqual(view.Zones, expected) {
return fmt.Errorf("view.Zones: got: %v want: %v", view.Zones, expected)
Expand Down Expand Up @@ -187,7 +187,7 @@ func testAccCheckDNSViewDestroy(s *terraform.State) error {
return nil
}

func testAccCheckDNSViewExists(n string, view *dns.DNSView) resource.TestCheckFunc {
func testAccCheckDNSViewExists(n string, view *dns.View) resource.TestCheckFunc {
return func(s *terraform.State) error {
rs, ok := s.RootModule().Resources[n]

Expand All @@ -212,7 +212,7 @@ func testAccCheckDNSViewExists(n string, view *dns.DNSView) resource.TestCheckFu
}
}

func testAccManualDeleteDNSView(view *dns.DNSView) func() {
func testAccManualDeleteDNSView(view *dns.View) func() {
return func() {
client := testAccProvider.Meta().(*ns1.Client)
_, err := client.View.Delete(view.Name)
Expand Down
6 changes: 4 additions & 2 deletions ns1/resource_notifylist.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,9 @@ func notifyListToResourceData(d *schema.ResourceData, nl *monitor.NotifyList) er
ni := make(map[string]interface{})
ni["type"] = n.Type
if n.Config != nil {
ni["config"] = n.Config
configWithoutHeaders := n.Config
delete(configWithoutHeaders, "headers")
ni["config"] = configWithoutHeaders
}
notifications[i] = ni
}
Expand Down Expand Up @@ -89,7 +91,7 @@ func resourceDataToNotifyList(nl *monitor.NotifyList, d *schema.ResourceData) er
case "webhook":
url := config["url"]
if url != nil {
ns[i] = monitor.NewWebNotification(url.(string))
ns[i] = monitor.NewWebNotification(url.(string), nil)
} else {
return fmt.Errorf("wrong config for webhook expected url field into config")
}
Expand Down
30 changes: 15 additions & 15 deletions ns1/resource_pulsar_job.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ func pulsarJobResource() *schema.Resource {
}
}

func pulsarJobToResourceData(d *schema.ResourceData, j *pulsar.PulsarJob) error {
func pulsarJobToResourceData(d *schema.ResourceData, j *pulsar.Job) error {
d.SetId(j.JobID)
d.Set("customer", j.Customer)
d.Set("name", j.Name)
Expand All @@ -163,19 +163,19 @@ func pulsarJobToResourceData(d *schema.ResourceData, j *pulsar.PulsarJob) error
return nil
}

func jobConfigToResourceData(d *schema.ResourceData, j *pulsar.PulsarJob) error {
func jobConfigToResourceData(d *schema.ResourceData, j *pulsar.Job) error {
config := make(map[string]interface{})
if j.Config.Host != nil {
config["host"] = *j.Config.Host
}
if j.Config.URL_Path != nil {
config["url_path"] = *j.Config.URL_Path
if j.Config.URLPath != nil {
config["url_path"] = *j.Config.URLPath
}
if j.Config.Http != nil {
config["http"] = *j.Config.Http
if j.Config.HTTP != nil {
config["http"] = *j.Config.HTTP
}
if j.Config.Https != nil {
config["https"] = *j.Config.Https
if j.Config.HTTPS != nil {
config["https"] = *j.Config.HTTPS
}
if j.Config.RequestTimeoutMillis != nil {
config["request_timeout_millis"] = *j.Config.RequestTimeoutMillis
Expand Down Expand Up @@ -228,7 +228,7 @@ func weightsToResourceData(w *pulsar.Weights) map[string]interface{} {
return weight
}

func resourceDataToPulsarJob(j *pulsar.PulsarJob, d *schema.ResourceData) error {
func resourceDataToPulsarJob(j *pulsar.Job, d *schema.ResourceData) error {
j.Name = d.Get("name").(string)
j.TypeID = d.Get("type_id").(string)
j.JobID = d.Id()
Expand Down Expand Up @@ -274,15 +274,15 @@ func resourceDataToJobConfig(v interface{}) (*pulsar.JobConfig, error) {
}
if v, ok := rawconfig["url_path"]; ok {
url_path := v.(string)
j.URL_Path = &url_path
j.URLPath = &url_path
}
if v, ok := rawconfig["http"]; ok {
b := v.(bool)
j.Http = &b
j.HTTP = &b
}
if v, ok := rawconfig["https"]; ok {
b := v.(bool)
j.Https = &b
j.HTTPS = &b
}
if v, ok := rawconfig["request_timeout_millis"]; ok {
i := v.(int)
Expand Down Expand Up @@ -336,7 +336,7 @@ func resourceDataToWeights(v interface{}) []*pulsar.Weights {
// PulsarJobCreate creates the given Pulsar Job in ns1
func PulsarJobCreate(d *schema.ResourceData, meta interface{}) error {
client := meta.(*ns1.Client)
j := pulsar.PulsarJob{}
j := pulsar.Job{}
if err := resourceDataToPulsarJob(&j, d); err != nil {
return err
}
Expand Down Expand Up @@ -376,7 +376,7 @@ func pulsarJobRead(d *schema.ResourceData, meta interface{}) error {
// PulsarJobUpdate updates the Pulsar Job with given parameters in ns1
func PulsarJobUpdate(job_schema *schema.ResourceData, meta interface{}) error {
client := meta.(*ns1.Client)
j := pulsar.PulsarJob{
j := pulsar.Job{
JobID: job_schema.Id(),
AppID: job_schema.Get("app_id").(string),
}
Expand All @@ -394,7 +394,7 @@ func PulsarJobUpdate(job_schema *schema.ResourceData, meta interface{}) error {
// pulsarJobDelete deletes the given Pulsar Job from ns1
func pulsarJobDelete(d *schema.ResourceData, meta interface{}) error {
client := meta.(*ns1.Client)
j := pulsar.PulsarJob{}
j := pulsar.Job{}
resourceDataToPulsarJob(&j, d)
resp, err := client.PulsarJobs.Delete(&j)
d.SetId("")
Expand Down
Loading