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

Code commit test #5

Closed
Closed
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
The diff you're trying to view is too large. We only load the first 3000 changed files.
8 changes: 4 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Goland
/.idea
.idea/workspace.xml

# Mac specific files
.DS_Store

# Vim
[._]*.s[a-w][a-z]
Expand All @@ -13,9 +16,6 @@ pyvenv.cfg
# Go coverage files
cover.out

# Go vendor directory
vendor

# Terraform files in the examples directory
examples/*/*/.terraform
examples/*/*/.terraform.lock.hcl
Expand Down
23 changes: 23 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
TEST?=$$(go list ./... | grep -v 'vendor')
HOSTNAME=github.com
NAMESPACE=infobloxopen
NAME=bloxone
BINARY=terraform-provider-${NAME}
VERSION=0.1.5
OS_ARCH=linux_amd64

default: install

build:
go build -o ${BINARY}

install: build
mkdir -p ~/.terraform.d/plugins/${HOSTNAME}/${NAMESPACE}/${NAME}/${VERSION}/${OS_ARCH}
mv ${BINARY} ~/.terraform.d/plugins/${HOSTNAME}/${NAMESPACE}/${NAME}/${VERSION}/${OS_ARCH}

test:
go test -i $(TEST) || exit 1
echo $(TEST) | xargs -t -n4 go test $(TESTARGS) -timeout=30s -parallel=4 -coverprofile cover.out

testacc:
TF_ACC=1 go test $(TEST) -v $(TESTARGS) -timeout 120m -coverprofile testacc-cover.out
108 changes: 108 additions & 0 deletions b1ddi/b1ddi/data_source_dns_auth_nsg.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
package b1ddi

import (
"context"
"github.com/go-openapi/swag"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
b1ddiclient "github.com/infobloxopen/b1ddi-go-client/client"
"github.com/infobloxopen/b1ddi-go-client/dns_config/auth_nsg"
"github.com/infobloxopen/b1ddi-go-client/models"
"strconv"
"time"
)

func dataSourceConfigAuthNSG() *schema.Resource {
return &schema.Resource{
ReadContext: dataSourceConfigAuthNSGRead,
Schema: map[string]*schema.Schema{
"filters": {
Type: schema.TypeMap,
Optional: true,
Description: "Configure a map of filters to be applied on the search result.",
},
"results": {
Type: schema.TypeList,
Computed: true,
Elem: dataSourceSchemaFromResource(resourceConfigAuthNSG),
Description: "List of DNS Auth NSGs matching filters. The schema of each element is identical to the b1ddi_dns_auth_nsg resource schema.",
},
},
}
}

func dataSourceConfigAuthNSGRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
c := m.(*b1ddiclient.Client)

var diags diag.Diagnostics

filtersMap := d.Get("filters").(map[string]interface{})
filterStr := filterFromMap(filtersMap)

resp, err := c.DNSConfigurationAPI.AuthNsg.AuthNsgList(
&auth_nsg.AuthNsgListParams{
Filter: swag.String(filterStr),
Context: ctx,
},
nil,
)
if err != nil {
return diag.FromErr(err)
}

results := make([]interface{}, 0, len(resp.Payload.Results))
for _, nsg := range resp.Payload.Results {
results = append(results, flattenConfigAuthNSG(nsg)...)
}
err = d.Set("results", results)
if err != nil {
diags = append(diags, diag.FromErr(err)...)
}

// always run
d.SetId(strconv.FormatInt(time.Now().Unix(), 10))

return diags
}

func flattenConfigAuthNSG(r *models.ConfigAuthNSG) []interface{} {
if r == nil {
return nil
}

externalPrimaries := make([]map[string]interface{}, 0, len(r.ExternalPrimaries))
for _, ep := range r.ExternalPrimaries {
externalPrimaries = append(externalPrimaries, flattenConfigExternalPrimary(ep))
}

externalSecondaries := make([]map[string]interface{}, 0, len(r.ExternalSecondaries))
for _, es := range r.ExternalSecondaries {
externalSecondaries = append(externalSecondaries, flattenConfigExternalSecondary(es))
}

internalSecondaries := make([]map[string]interface{}, 0, len(r.InternalSecondaries))
for _, is := range r.InternalSecondaries {
internalSecondaries = append(internalSecondaries, flattenConfigInternalSecondary(is))
}

return []interface{}{
map[string]interface{}{

"comment": r.Comment,

"external_primaries": externalPrimaries,

"external_secondaries": externalSecondaries,

"id": r.ID,

"internal_secondaries": internalSecondaries,

"name": r.Name,

"nsgs": r.Nsgs,

"tags": r.Tags,
},
}
}
54 changes: 54 additions & 0 deletions b1ddi/b1ddi/data_source_dns_auth_nsg_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package b1ddi

import (
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"testing"
)

func TestAccDataSourceConfigAuthNsg_Basic(t *testing.T) {
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
ProviderFactories: testAccProviderFactories,
Steps: []resource.TestStep{
resourceDnsAuthNsgBasicTestStep(t),
{
Config: `
data "b1ddi_dns_auth_nsgs" "tf_acc_auth_nsg" {
filters = {
name = "tf_acc_test_auth_nsg"
}
}
`,
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttr("data.b1ddi_dns_auth_nsgs.tf_acc_auth_nsg", "results.#", "1"),
resource.TestCheckResourceAttrSet("data.b1ddi_dns_auth_nsgs.tf_acc_auth_nsg", "results.0.id"),
resource.TestCheckResourceAttr("data.b1ddi_dns_auth_nsgs.tf_acc_auth_nsg", "results.0.name", "tf_acc_test_auth_nsg"),
),
},
},
})
}

func TestAccDataSourceConfigAuthNsg_FullConfig(t *testing.T) {
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
ProviderFactories: testAccProviderFactories,
Steps: []resource.TestStep{
resourceDnsAuthNsgFullConfigTestStep(t),
{
Config: `
data "b1ddi_dns_auth_nsgs" "tf_acc_auth_nsg" {
filters = {
name = "tf_acc_test_auth_nsg"
}
}
`,
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttr("data.b1ddi_dns_auth_nsgs.tf_acc_auth_nsg", "results.#", "1"),
resource.TestCheckResourceAttrSet("data.b1ddi_dns_auth_nsgs.tf_acc_auth_nsg", "results.0.id"),
resource.TestCheckResourceAttr("data.b1ddi_dns_auth_nsgs.tf_acc_auth_nsg", "results.0.name", "tf_acc_test_auth_nsg"),
),
},
},
})
}
139 changes: 139 additions & 0 deletions b1ddi/b1ddi/data_source_dns_auth_zone.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
package b1ddi

import (
"context"
"github.com/go-openapi/swag"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
b1ddiclient "github.com/infobloxopen/b1ddi-go-client/client"
"github.com/infobloxopen/b1ddi-go-client/dns_config/auth_zone"
"github.com/infobloxopen/b1ddi-go-client/models"
"strconv"
"time"
)

func dataSourceConfigAuthZone() *schema.Resource {
return &schema.Resource{
ReadContext: dataSourceConfigAuthZoneRead,
Schema: map[string]*schema.Schema{
"filters": {
Type: schema.TypeMap,
Optional: true,
Description: "Configure a map of filters to be applied on the search result.",
},
"results": {
Type: schema.TypeList,
Computed: true,
Elem: dataSourceSchemaFromResource(resourceConfigAuthZone),
Description: "List of DNS Auth Zones matching filters. The schema of each element is identical to the b1ddi_dns_auth_zone resource schema.",
},
},
}
}

func dataSourceConfigAuthZoneRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
c := m.(*b1ddiclient.Client)

var diags diag.Diagnostics

filtersMap := d.Get("filters").(map[string]interface{})
filterStr := filterFromMap(filtersMap)

is := "partial"

resp, err := c.DNSConfigurationAPI.AuthZone.AuthZoneList(&auth_zone.AuthZoneListParams{
Filter: swag.String(filterStr),
Inherit: &is,
Context: ctx,
}, nil)
if err != nil {
return diag.FromErr(err)
}

results := make([]interface{}, 0, len(resp.Payload.Results))
for _, ab := range resp.Payload.Results {
results = append(results, flattenConfigAuthZone(ab)...)
}
err = d.Set("results", results)
if err != nil {
diags = append(diags, diag.FromErr(err)...)
}

// always run
d.SetId(strconv.FormatInt(time.Now().Unix(), 10))

return diags
}

func flattenConfigAuthZone(r *models.ConfigAuthZone) []interface{} {
if r == nil {
return nil
}

externalPrimaries := make([]map[string]interface{}, 0, len(r.ExternalPrimaries))
for _, ep := range r.ExternalPrimaries {
externalPrimaries = append(externalPrimaries, flattenConfigExternalPrimary(ep))
}

externalSecondaries := make([]map[string]interface{}, 0, len(r.ExternalSecondaries))
for _, es := range r.ExternalSecondaries {
externalSecondaries = append(externalSecondaries, flattenConfigExternalSecondary(es))
}

inheritanceAssignedHosts := make([]interface{}, 0, len(r.InheritanceAssignedHosts))
for _, iah := range r.InheritanceAssignedHosts {
inheritanceAssignedHosts = append(inheritanceAssignedHosts, flattenInheritance2AssignedHost(iah))
}

internalSecondaries := make([]interface{}, 0, len(r.InternalSecondaries))
for _, is := range r.InternalSecondaries {
internalSecondaries = append(internalSecondaries, flattenConfigInternalSecondary(is))
}

queryACL := make([]interface{}, 0, len(r.QueryACL))
for _, aclItem := range r.QueryACL {
queryACL = append(queryACL, flattenConfigACLItem(aclItem))
}

transferACL := make([]interface{}, 0, len(r.TransferACL))
for _, aclItem := range r.TransferACL {
transferACL = append(transferACL, flattenConfigACLItem(aclItem))
}

updateACL := make([]interface{}, 0, len(r.UpdateACL))
for _, aclItem := range r.UpdateACL {
updateACL = append(updateACL, flattenConfigACLItem(aclItem))
}

return []interface{}{
map[string]interface{}{
"id": r.ID,
"comment": r.Comment,
"created_at": r.CreatedAt.String(),
"disabled": r.Disabled,
"external_primaries": externalPrimaries,
"external_secondaries": externalSecondaries,
"fqdn": r.Fqdn,
"gss_tsig_enabled": r.GssTsigEnabled,
"inheritance_assigned_hosts": inheritanceAssignedHosts,
"inheritance_sources": flattenConfigAuthZoneInheritance(r.InheritanceSources),
"initial_soa_serial": r.InitialSoaSerial,
"internal_secondaries": internalSecondaries,
"mapped_subnet": r.MappedSubnet,
"mapping": r.Mapping,
"notify": r.Notify,
"nsgs": r.Nsgs,
"parent": r.Parent,
"primary_type": r.PrimaryType,
"protocol_fqdn": r.ProtocolFqdn,
"query_acl": queryACL,
"tags": r.Tags,
"transfer_acl": transferACL,
"update_acl": updateACL,
"updated_at": r.UpdatedAt.String(),
"use_forwarders_for_subzones": r.UseForwardersForSubzones,
"view": r.View,
"zone_authority": flattenConfigZoneAuthority(r.ZoneAuthority),
},
}
}
Loading
Loading