Skip to content

Commit

Permalink
Anycast host resource implementation (#95)
Browse files Browse the repository at this point in the history
* datasource and resource for anycast

* fixed PR checks

* Ran go mod commands

* Regenerated go.sum

* added onprem host resource

* basic UT working

* basic UT working

* fixed UTs

* resolved new naming conventions from master and added examples

* renamed resource files

* fixed linter issue check

* addressed PR comments

* fixed linter issue

* fixed host dependency in UT's

---------

Co-authored-by: Ashish Mathew <[email protected]>
  • Loading branch information
AnilGadiyarHJ and mathewab authored May 3, 2024
1 parent 7afd272 commit 1b3471f
Show file tree
Hide file tree
Showing 22 changed files with 1,081 additions and 313 deletions.
10 changes: 7 additions & 3 deletions docs/data-sources/anycast_configs.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ data "bloxone_anycast_configs" "example_all" {

### Optional

- `filters` (Map of String) Filter are used to return a more specific list of results. Filters can be used to match resources by specific attributes, e.g. name. If you specify multiple filters, the results returned will have only resources that match all the specified filters.
- `host_id` (Number) Filter by host ID.
- `is_configured` (Boolean) Filter by configuration status.
- `service` (String) Filter by service type.
Expand Down Expand Up @@ -72,14 +73,17 @@ Read-Only:
<a id="nestedatt--results--onprem_hosts"></a>
### Nested Schema for `results.onprem_hosts`

Optional:
Required:

- `id` (Number) The resource identifier.

Optional:

- `ip_address` (String) IPv4 address of the host in string format
- `ipv6_address` (String) IPv6 address of the host in string format
- `name` (String) The name of the anycast.

Read-Only:

- `name` (String) The name of the anycast.
- `ophid` (String) Unique 32-character string identifier assigned to the host
- `runtime_status` (String)
- `runtime_status` (String) The runtime status of the host
9 changes: 6 additions & 3 deletions docs/resources/anycast_config.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,17 @@ resource "bloxone_anycast_config" "example" {
<a id="nestedatt--onprem_hosts"></a>
### Nested Schema for `onprem_hosts`

Optional:
Required:

- `id` (Number) The resource identifier.

Optional:

- `ip_address` (String) IPv4 address of the host in string format
- `ipv6_address` (String) IPv6 address of the host in string format
- `name` (String) The name of the anycast.

Read-Only:

- `name` (String) The name of the anycast.
- `ophid` (String) Unique 32-character string identifier assigned to the host
- `runtime_status` (String)
- `runtime_status` (String) The runtime status of the host
217 changes: 217 additions & 0 deletions docs/resources/anycast_host.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,217 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "bloxone_anycast_host Resource - terraform-provider-bloxone"
subcategory: "Anycast"
description: |-
Retrieve an Anycast host Configurations.
---

# bloxone_anycast_host (Resource)

Retrieve an Anycast host Configurations.

## Example Usage

```terraform
data "bloxone_infra_hosts" "anycast_hosts" {
filters = {
display_name = "my-host"
}
}
# Create an anycast config profile with onprem hosts
resource "bloxone_anycast_config" "example" {
anycast_ip_address = "10.10.10.1"
name = "Anycast_config_example"
service = "DNS"
}
# Adding an anycast host with BGP routing protocol
resource "bloxone_anycast_host" "example" {
id = one(data.bloxone_infra_hosts.anycast_hosts.results).legacy_id
# Adding the anycast config profile and enabling BGP routing protocol
anycast_config_refs = [
{
anycast_config_name = bloxone_anycast_config.test_onprem_hosts.name
routing_protocols = ["BGP", "OSPF"]
}
]
# Adding the BGP configuration
config_bgp = {
asn = "6500"
asn_text = "6500"
holddown_secs = 180
neighbors = [
{
asn = "6501"
ip_address = "10.20.0.3"
}
]
}
# Adding the OSPF configuration
config_ospf = {
area_type = "STANDARD"
area = "10.0.0.1"
authentication_type = "Clear"
interface = "eth0"
authentication_key = "YXV0aGV"
hello_interval = 10
dead_interval = 40
retransmit_interval = 5
transmit_delay = 1
}
}
```

<!-- schema generated by tfplugindocs -->
## Schema

### Required

- `id` (Number) Numeric host identifier.

### Optional

- `anycast_config_refs` (Attributes List) Array of AnycastConfigRef structures, identifying the anycast configurations that this host is a member of. (see [below for nested schema](#nestedatt--anycast_config_refs))
- `config_bgp` (Attributes) Struct BGP configuration; defines BGP configuration for one anycast-enabled on-prem host. (see [below for nested schema](#nestedatt--config_bgp))
- `config_ospf` (Attributes) Struct OSPF configuration; defines OSPF configuration for one anycast-enabled on-prem host. (see [below for nested schema](#nestedatt--config_ospf))
- `config_ospfv3` (Attributes) Struct OSPFv3 configuration; defines OSPFv3 configuration for one anycast-enabled on-prem host. (see [below for nested schema](#nestedatt--config_ospfv3))

### Read-Only

- `created_at` (String) Date/time this host was created in anycast service database.
- `ip_address` (String) IPv4 address of the on-prem host
- `ipv6_address` (String) IPv6 address of the on-prem host
- `name` (String) User-friendly name of the host @example "dns-host-1", "Central Office Server".
- `updated_at` (String) Date/time this host was last updated in anycast service database.

<a id="nestedatt--anycast_config_refs"></a>
### Nested Schema for `anycast_config_refs`

Required:

- `anycast_config_name` (String)

Optional:

- `routing_protocols` (List of String) Routing protocols enabled for this anycast configuration, on a particular host. Valid protocol names are "BGP", "OSPF"/"OSPFv2", "OSPFv3".


<a id="nestedatt--config_bgp"></a>
### Nested Schema for `config_bgp`

Required:

- `asn` (Number) Autonomous system number of this BGP/anycast enabled on-prem host.
- `holddown_secs` (Number) BGP route hold-down timer.

Optional:

- `fields` (Attributes) Represents a set of symbolic field paths. (see [below for nested schema](#nestedatt--config_bgp--fields))
- `keep_alive_secs` (Number) BGP keep-alive timer.
- `link_detect` (Boolean) Enable/disable link detection.
- `neighbors` (Attributes List) List of BgpNeighbor structs. (see [below for nested schema](#nestedatt--config_bgp--neighbors))
- `preamble` (String) Any predefined BGP configuration, with embedded new lines; the preamble will be prepended to the generated BGP configuration.

Read-Only:

- `asn_text` (String) Autonomous system as text (supported in ASDOT or ASPLAIN format) Optional, requires the asn field to be set to the equivalent integer value of the ASDOT/ASPLAIN string contained in this field or be unset/zero.
Example:

| ASDOT | ASPLAIN | INTEGER | VALID/INVALID |
|-------------|-------------|-------------|---------------|
| 0.1 | 1 | 1 | Valid |
| 1 | 1 | 1 | Valid |
| 65535 | 65535 | 65535 | Valid |
| 0.65535 | 65535 | 65535 | Valid |
| 1.0 | 65536 | 65536 | Valid |
| 1.1 | 65537 | 65537 | Valid |
| 1.65535 | 131071 | 131071 | Valid |
| 65535.0 | 4294901760 | 4294901760 | Valid |
| 65535.1 | 4294901761 | 4294901761 | Valid |
| 65535.65535 | 4294967295 | 4294967295 | Valid |
| 0.65536 | | | Invalid |
| 65535.655536| | | Invalid |
| 65536.0 | | | Invalid |
| 65536.65535 | | | Invalid |
| | 4294967296 | | Invalid |

<a id="nestedatt--config_bgp--fields"></a>
### Nested Schema for `config_bgp.fields`

Optional:

- `paths` (List of String) The set of field mask paths.


<a id="nestedatt--config_bgp--neighbors"></a>
### Nested Schema for `config_bgp.neighbors`

Required:

- `asn` (Number) Autonomous system number of this BGP/anycast enabled on-prem host.

Optional:

- `asn_text` (String) Autonomous system as text (supported in ASDOT or ASPLAIN format) Optional, requires the asn field to be set to the equivalent integer value of the ASDOT/ASPLAIN string contained in this field or be unset/zero.
Example:

| ASDOT | ASPLAIN | INTEGER | VALID/INVALID |
|-------------|-------------|-------------|---------------|
| 0.1 | 1 | 1 | Valid |
| 1 | 1 | 1 | Valid |
| 65535 | 65535 | 65535 | Valid |
| 0.65535 | 65535 | 65535 | Valid |
| 1.0 | 65536 | 65536 | Valid |
| 1.1 | 65537 | 65537 | Valid |
| 1.65535 | 131071 | 131071 | Valid |
| 65535.0 | 4294901760 | 4294901760 | Valid |
| 65535.1 | 4294901761 | 4294901761 | Valid |
| 65535.65535 | 4294967295 | 4294967295 | Valid |
| 0.65536 | | | Invalid |
| 65535.655536| | | Invalid |
| 65536.0 | | | Invalid |
| 65536.65535 | | | Invalid |
| | 4294967296 | | Invalid |
- `ip_address` (String) IPv4 address of the BGP neighbor
- `max_hop_count` (Number) Max hop count, if BGP multihop is enabled.
- `multihop` (Boolean) BGP multihop enabled or not.
- `password` (String) BGP protocol access password for this BGP neighbor, max 25 characters long.



<a id="nestedatt--config_ospf"></a>
### Nested Schema for `config_ospf`

Optional:

- `area` (String) OSPF area identifier; usually in the format of an IPv4 address (although not an address itself)
- `area_type` (String) OSPF area type; one of: "STANDARD", "STUB", "NSSA".
- `authentication_key` (String) OSPF authentication key.
- `authentication_key_id` (Number) title: Numeric OSPF authentication key identifier.
- `authentication_type` (String) OSPF authentication type; one of "Clear", "MD5".
- `cost` (Number) Explicit link cost for the interface.
- `dead_interval` (Number) OSPF router dead interval timer in seconds; must be the same for all the routers on the same network; default: 40 secs.
- `hello_interval` (Number) Period (in seconds) of OSPF Hello packet, sent by the OSPF router; must be the same for all the routers on the same network; default: 10 secs.
- `interface` (String) Name of the interface that is configured with external IP address of the host
- `preamble` (String) Any predefined OSPF configuration, with embedded new lines; the preamble will be prepended to the generated BGP configuration.
- `retransmit_interval` (Number) Period (in seconds) of retransmitting for OSPF Database Description and Link State Requests; default: 5 seconds.
- `transmit_delay` (Number) Estimated time to transmit link state advertisements; default: 1 sec.


<a id="nestedatt--config_ospfv3"></a>
### Nested Schema for `config_ospfv3`

Optional:

- `area` (String) OSPF area identifier; usually in the format of an IPv4 address (although not an address itself)
- `cost` (Number) Explicit link cost for the interface.
- `dead_interval` (Number) OSPF router dead interval timer in seconds; must be the same for all the routers on the same network; default: 40 sec.
- `hello_interval` (Number) Period (in seconds) of OSPF Hello packet, sent by the OSPF router; must be the same for all the routers on the same network; default: 10 secs.
- `interface` (String) Name of the interface that is configured with external IP address of the host
- `retransmit_interval` (Number) Period (in seconds) of retransmitting for OSPF Database Description and Link State Requests; default: 5 seconds.
- `transmit_delay` (Number) Estimated time to transmit link state advertisements; default: 1 sec.
52 changes: 52 additions & 0 deletions examples/resources/bloxone_anycast_host/resource.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
data "bloxone_infra_hosts" "anycast_hosts" {
filters = {
display_name = "my-host"
}
}

# Create an anycast config profile with onprem hosts
resource "bloxone_anycast_config" "example" {
anycast_ip_address = "10.10.10.1"
name = "Anycast_config_example"
service = "DNS"

}

# Adding an anycast host with BGP routing protocol
resource "bloxone_anycast_host" "example" {
id = one(data.bloxone_infra_hosts.anycast_hosts.results).legacy_id

# Adding the anycast config profile and enabling BGP routing protocol
anycast_config_refs = [
{
anycast_config_name = bloxone_anycast_config.test_onprem_hosts.name
routing_protocols = ["BGP", "OSPF"]
}
]

# Adding the BGP configuration
config_bgp = {
asn = "6500"
asn_text = "6500"
holddown_secs = 180
neighbors = [
{
asn = "6501"
ip_address = "10.20.0.3"
}
]
}

# Adding the OSPF configuration
config_ospf = {
area_type = "STANDARD"
area = "10.0.0.1"
authentication_type = "Clear"
interface = "eth0"
authentication_key = "YXV0aGV"
hello_interval = 10
dead_interval = 40
retransmit_interval = 5
transmit_delay = 1
}
}
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -76,3 +76,5 @@ require (
google.golang.org/grpc v1.57.1 // indirect
google.golang.org/protobuf v1.33.0 // indirect
)

//replace github.com/infobloxopen/bloxone-go-client => ../bloxone-go-client
2 changes: 1 addition & 1 deletion internal/acctest/acctest.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func RandomNameWithPrefix(prefix string) string {
}

func RandomIP() string {
return fmt.Sprintf("%d.%d.%d.%d", rand.Intn(256), rand.Intn(256), rand.Intn(256), rand.Intn(256))
return fmt.Sprintf("%d.%d.%d.%d", rand.Intn(255), rand.Intn(255), rand.Intn(255), rand.Intn(255))
}

func RandomName() string {
Expand Down
9 changes: 5 additions & 4 deletions internal/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,8 @@ import (

bloxoneclient "github.com/infobloxopen/bloxone-go-client/client"
"github.com/infobloxopen/bloxone-go-client/option"
"github.com/infobloxopen/terraform-provider-bloxone/internal/service/dfp"

"github.com/infobloxopen/terraform-provider-bloxone/internal/service/anycast"
"github.com/infobloxopen/terraform-provider-bloxone/internal/service/dfp"
"github.com/infobloxopen/terraform-provider-bloxone/internal/service/dns_config"
"github.com/infobloxopen/terraform-provider-bloxone/internal/service/dns_data"
"github.com/infobloxopen/terraform-provider-bloxone/internal/service/fw"
Expand Down Expand Up @@ -76,6 +75,7 @@ func (p *BloxOneProvider) Configure(ctx context.Context, req provider.ConfigureR
option.WithClientName(fmt.Sprintf("terraform/%s#%s", p.version, p.commit)),
option.WithAPIKey(data.APIKey.ValueString()),
option.WithCSPUrl(data.CSPUrl.ValueString()),
option.WithDebug(false),
)

resp.DataSourceData = client
Expand Down Expand Up @@ -128,10 +128,11 @@ func (p *BloxOneProvider) Resources(_ context.Context) []func() resource.Resourc

keys.NewTsigResource,

dfp.NewDfpResource,

anycast.NewAnycastHostResource,
anycast.NewAnycastConfigResource,

dfp.NewDfpResource,

fw.NewSecurityPolicyResource,
fw.NewAccessCodeResource,
fw.NewNamedListResource,
Expand Down
Loading

0 comments on commit 1b3471f

Please sign in to comment.