Skip to content
This repository has been archived by the owner on Dec 17, 2020. It is now read-only.

Add Data Source for Network #2

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
  •  
  •  
  •  
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
terraform-provider-infoblox
example
.vscode
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ $ make testacc
* Allocation & Deallocation of IP from a Network
* Association & Disassociation of IP Address for a VM
* Creation and Deletion of A, CNAME, Host, and Ptr records
* Retrive network information based on Network name, TenantID and CIDR

## Disclaimer
To use the provider for DNS purposes, a parent (i.e. zone) must already exist. The plugin does not support the creation of zones.
Expand Down
8 changes: 8 additions & 0 deletions examples/infoblox/infoblox.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
provider "infoblox" {
}

data "infoblox_network" "network" {
network_view_name = "default"
cidr = "10.0.0.0/8"
tenant_id = ""
}
1 change: 1 addition & 0 deletions go.mod
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ go 1.12

require (
github.com/hashicorp/terraform v0.12.9
github.com/hashicorp/terraform-plugin-sdk v1.12.0
github.com/infobloxopen/infoblox-go-client v0.8.1-0.20190830062100-dd50c409ab6d
)
58 changes: 58 additions & 0 deletions go.sum

Large diffs are not rendered by default.

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

import (
"fmt"

"github.com/hashicorp/terraform/helper/schema"
ibclient "github.com/infobloxopen/infoblox-go-client"
)

func dataSourceNetwork() *schema.Resource {
return &schema.Resource{
Read: dataSourceNetworkRead,

Schema: map[string]*schema.Schema{
"network_view_name": &schema.Schema{
Type: schema.TypeString,
Optional: true,
Description: "The name of your network block.",
},
"cidr": &schema.Schema{
Type: schema.TypeString,
Required: true,
Description: "The network block in cidr format.",
},
"tenant_id": &schema.Schema{
Type: schema.TypeString,
Required: true,
Description: "Unique identifier of your tenant in cloud.",
},
},
}
}

// dataSourceNetworkRead: Read the network information from inflobox based on the network view name and CIDR address.
func dataSourceNetworkRead(d *schema.ResourceData, m interface{}) error {

networkName := d.Get("network_view_name").(string)
cidr := d.Get("cidr").(string)
tenantID := d.Get("tenant_id").(string)

connector := m.(*ibclient.Connector)
ea := make(ibclient.EA)
objMgr := ibclient.NewObjectManager(connector, "Terraform", tenantID)

obj, err := objMgr.GetNetwork(networkName, cidr, ea)
if err != nil {
return fmt.Errorf("Getting Network block from network view (%s) failed : %s", networkName, err)
}
return networkDescriptionAttributes(d, obj)
}

// networkDescriptionAttributes: populate the numberous fields for the returned network.
func networkDescriptionAttributes(d *schema.ResourceData, obj *ibclient.Network) error {
// simple attribute first
d.SetId(*&obj.Ref)
d.Set("network_view_name", obj.NetviewName)
d.Set("cidr", obj.Cidr)
d.Set("tenant_id", d.Get("tenant_id").(string))
return nil
}
31 changes: 31 additions & 0 deletions infoblox/data_source_infoblox_network_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package infoblox

import (
"testing"

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

func TestAccInfloBoxDataSourceNetwork(t *testing.T) {
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Config: testAccInfloBoxDataSourceNetworkConfig,
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttr("data.inflobox_network.test", "network_view_name", "default"),
),
},
},
})
}

// testAccInfloBoxDataSourceNetworkConfig: data source network base configuration
const testAccInfloBoxDataSourceNetworkConfig = `
data "infoblox_network" test {
network_view_name = "default"
cidr = "10.0.0.0/8"
tenant_id = "test"
}
`
8 changes: 6 additions & 2 deletions infoblox/provider.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package infoblox

import (
"time"

"github.com/hashicorp/terraform/helper/schema"
"github.com/hashicorp/terraform/terraform"
"github.com/infobloxopen/infoblox-go-client"
"time"
ibclient "github.com/infobloxopen/infoblox-go-client"
)

//Provider returns a terraform.ResourceProvider.
Expand Down Expand Up @@ -70,6 +71,9 @@ func Provider() terraform.ResourceProvider {
"infoblox_cname_record": resourceCNAMERecord(),
"infoblox_ptr_record": resourcePTRRecord(),
},
DataSourcesMap: map[string]*schema.Resource{
"infoblox_network": dataSourceNetwork(),
},
ConfigureFunc: providerConfigure,
}

Expand Down
28 changes: 28 additions & 0 deletions vendor/github.com/aws/aws-sdk-go/aws/client/no_op_retryer.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions vendor/github.com/aws/aws-sdk-go/internal/sdkio/byte.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions vendor/github.com/aws/aws-sdk-go/internal/sdkmath/floor.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

56 changes: 56 additions & 0 deletions vendor/github.com/aws/aws-sdk-go/internal/sdkmath/floor_go1.9.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions vendor/github.com/aws/aws-sdk-go/internal/sdkrand/read.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 24 additions & 0 deletions vendor/github.com/aws/aws-sdk-go/internal/sdkrand/read_1_5.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions vendor/github.com/aws/aws-sdk-go/service/sts/customizations.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

38 changes: 38 additions & 0 deletions vendor/github.com/hashicorp/go-hclog/context.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading