-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add cidr data source and functions (#4)
- Loading branch information
Showing
42 changed files
with
1,421 additions
and
509 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,13 @@ | ||
default: testacc | ||
|
||
# Run acceptance tests | ||
.PHONY: testacc | ||
testacc: | ||
TF_ACC=1 go test ./... -v $(TESTARGS) -timeout 120m | ||
|
||
generate: | ||
go generate ./... | ||
|
||
lint: | ||
golangci-lint run --fix | ||
|
||
# Run acceptance tests | ||
.PHONY: generate lint testacc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
--- | ||
# generated by https://github.com/hashicorp/terraform-plugin-docs | ||
page_title: "netparse_cidr Data Source - netparse" | ||
subcategory: "" | ||
description: |- | ||
Parses an IP address and prefix length in CIDR notation. It uses the net/netip https://pkg.go.dev/net/netip#Prefix.Masked go package to parse the CDIR. For more details in CIDR notation, see RFC 4632 https://rfc-editor.org/rfc/rfc4632.html and RFC 4291 https://rfc-editor.org/rfc/rfc4291.html. | ||
--- | ||
|
||
# netparse_cidr (Data Source) | ||
|
||
Parses an IP address and prefix length in CIDR notation. It uses the [net/netip](https://pkg.go.dev/net/netip#Prefix.Masked) go package to parse the CDIR. For more details in CIDR notation, see [RFC 4632](https://rfc-editor.org/rfc/rfc4632.html) and [RFC 4291](https://rfc-editor.org/rfc/rfc4291.html). | ||
|
||
## Example Usage | ||
|
||
```terraform | ||
data "netparse_cidr" "example1" { | ||
cidr = "192.0.2.1/24" | ||
} | ||
output "cidr1" { | ||
value = data.netparse_cidr.example | ||
# { | ||
# cidr = "192.0.2.1/24" | ||
# ip = "192.0.2.1" | ||
# network = "192.0.2.0/24" | ||
# } | ||
} | ||
data "netparse_cidr" "example2" { | ||
cidr = "192.0.2.1/24" | ||
} | ||
output "cidr2" { | ||
value = data.netparse_cidr.example | ||
# { | ||
# cidr = "2001:db8:a0b:12f0::1/32" | ||
# ip = "2001:db8:a0b:12f0::1" | ||
# network = "2001:db8::/32" | ||
# } | ||
} | ||
``` | ||
|
||
<!-- schema generated by tfplugindocs --> | ||
## Schema | ||
|
||
### Required | ||
|
||
- `cidr` (String) The IP address and prefix length in CIDR notation. | ||
|
||
### Read-Only | ||
|
||
- `ip` (String) The IP address. | ||
- `network` (String) The IP network. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,14 +3,60 @@ | |
page_title: "netparse_url Data Source - netparse" | ||
subcategory: "" | ||
description: |- | ||
Parses URL components from a URL string. For more details on the URL components, see What is a URL? https://developer.mozilla.org/en-US/docs/Learn/Common_questions/What_is_a_URL. | ||
Parses URL components from a URL string. It uses the net/url https://pkg.go.dev/net/url go package to parse the URL. For more details on the URL components, see What is a URL? https://developer.mozilla.org/en-US/docs/Learn/Common_questions/What_is_a_URL and WHATWG URL Standard https://url.spec.whatwg.org/#api. | ||
--- | ||
|
||
# netparse_url (Data Source) | ||
|
||
Parses URL components from a URL string. For more details on the URL components, see [What is a URL?](https://developer.mozilla.org/en-US/docs/Learn/Common_questions/What_is_a_URL). | ||
Parses URL components from a URL string. It uses the [net/url](https://pkg.go.dev/net/url) go package to parse the URL. For more details on the URL components, see [What is a URL?](https://developer.mozilla.org/en-US/docs/Learn/Common_questions/What_is_a_URL) and [WHATWG URL Standard](https://url.spec.whatwg.org/#api). | ||
|
||
## Example Usage | ||
|
||
```terraform | ||
# Get the host from the URL | ||
data "netparse_url" "example" { | ||
url = "https://abc:[email protected]:45/path/to/somewhere?foo=bar&baz=qux#231" | ||
} | ||
output "url" { | ||
value = data.netparse_url.example | ||
# { | ||
# url = "https://abc:[email protected]:45/path/to/somewhere?foo=bar&baz=qux#231" | ||
# authority = "abc:[email protected]:45" | ||
# credentials = "abc:def" | ||
# fragment = "231" | ||
# hash = "#231" | ||
# host = "example.com" | ||
# password = "def" | ||
# path = "/path/to/somewhere" | ||
# port = 45 | ||
# protocol = "https:" | ||
# query = "foo=bar&baz=qux" | ||
# scheme = "https" | ||
# search = "?foo=bar&baz=qux" | ||
# username = "abc" | ||
# } | ||
} | ||
# Then get the domain from the host | ||
data "netparse_domain" "example" { | ||
host = data.netparse_url.example.host | ||
} | ||
output "domain" { | ||
value = data.netparse_domain.example | ||
# { | ||
# host = "example.com" | ||
# domain = "example.com" | ||
# manager = "ICANN" | ||
# sld = "example" | ||
# subdomain = "" | ||
# tld = "com" | ||
# } | ||
} | ||
``` | ||
|
||
<!-- schema generated by tfplugindocs --> | ||
## Schema | ||
|
@@ -21,16 +67,16 @@ Parses URL components from a URL string. For more details on the URL components, | |
|
||
### Read-Only | ||
|
||
- `authority` (String) The concatenation of the username, password, host, and port. It's separated from the scheme by :// . For example: user1:[email protected]:3000 for http://user1:[email protected]:3000 . | ||
- `credentials` (String) The concatenation of the username and password. For example: user1:123 for https://user1:[email protected] . | ||
- `fragment` (String) The URL component after the search. For example: section for https://example.com/path/to/resource?key=value#section . | ||
- `hash` (String) The concatenation of a # with the fragment. For example: #section for https://example.com/path/to/resource?key=value#section . | ||
- `host` (String) The domain part of the authority. For example: example.com for https://example.com . | ||
- `password` (String, Sensitive) The second component of the URL credentials. For example: 123 for https://user1:[email protected] . | ||
- `path` (String) The URL component after the authority. For example: /path/to/resource for https://example.com/path/to/resource . | ||
- `port` (String) The last component of the URL authority. For example: 443 for https://example.com:443 . | ||
- `protocol` (String) The concatenation of the scheme and the port. For example: http:, https:, ftp:, sftp:, file:, etc. | ||
- `query` (String) The URL component of the search starting at the ? and before the fragment. For example: key=value for https://example.com/path/to/resource?key=value#section . | ||
- `scheme` (String) The protocol used to access the domain. For example: http, https, ftp, sftp, file, etc. | ||
- `search` (String) The URL component after the path. For example: ?key=value for https://example.com/path/to/resource?key=value . | ||
- `username` (String, Sensitive) The first component of the URL credentials. For example: user1 for https://user1:[email protected] . | ||
- `authority` (String) The concatenation of the username, password, host, and port. It's separated from the scheme by `://`. | ||
- `credentials` (String) The concatenation of the username and password. | ||
- `fragment` (String) The component after the search. | ||
- `hash` (String) The concatenation of a `#` with the fragment. | ||
- `host` (String) The domain part of the authority. | ||
- `password` (String, Sensitive) The second component of the credentials. | ||
- `path` (String) The component after the authority. | ||
- `port` (String) The last component of the authority. | ||
- `protocol` (String) The concatenation of the protocol scheme and `:`. | ||
- `query` (String) A substring of the search component, after the `?` and before the fragment. | ||
- `scheme` (String) The protocol scheme used to access the domain. | ||
- `search` (String) The component after the path. | ||
- `username` (String, Sensitive) The first component of the credentials. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
--- | ||
# generated by https://github.com/hashicorp/terraform-plugin-docs | ||
page_title: "contains_ip function - netparse" | ||
subcategory: "" | ||
description: |- | ||
Checks if an IP address is within a network. | ||
--- | ||
|
||
# function: contains_ip | ||
|
||
Checks if an IP address is within a network. | ||
|
||
## Example Usage | ||
|
||
```terraform | ||
locals { | ||
example1 = provider::netparse::contains_ip("192.0.2.0/24", "192.0.2.1") # true | ||
example2 = provider::netparse::contains_ip("192.0.2.0/24", "192.1.0.0") # false | ||
} | ||
``` | ||
|
||
## Signature | ||
|
||
<!-- signature generated by tfplugindocs --> | ||
```text | ||
contains_ip(ip string, network string) bool | ||
``` | ||
|
||
## Arguments | ||
|
||
<!-- arguments generated by tfplugindocs --> | ||
1. `ip` (String) The IP address. | ||
1. `network` (String) The IP network. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
--- | ||
# generated by https://github.com/hashicorp/terraform-plugin-docs | ||
page_title: "parse_cidr function - netparse" | ||
subcategory: "" | ||
description: |- | ||
Parses an IP address and prefix length in CIDR notation. It uses the net/netip https://pkg.go.dev/net/netip#Prefix.Masked go package to parse the CDIR. For more details in CIDR notation, see RFC 4632 https://rfc-editor.org/rfc/rfc4632.html and RFC 4291 https://rfc-editor.org/rfc/rfc4291.html. The functionality is equivalent to the netparse_cidr data source. | ||
--- | ||
|
||
# function: parse_cidr | ||
|
||
Parses an IP address and prefix length in CIDR notation. It uses the [net/netip](https://pkg.go.dev/net/netip#Prefix.Masked) go package to parse the CDIR. For more details in CIDR notation, see [RFC 4632](https://rfc-editor.org/rfc/rfc4632.html) and [RFC 4291](https://rfc-editor.org/rfc/rfc4291.html). The functionality is equivalent to the `netparse_cidr` data source. | ||
|
||
## Example Usage | ||
|
||
```terraform | ||
output "domain" { | ||
value = provider::netparse::parse_cidr("192.0.2.1/24") | ||
# { | ||
# ip = "192.0.2.1" | ||
# network = "192.0.2.0/24" | ||
# } | ||
} | ||
``` | ||
|
||
## Signature | ||
|
||
<!-- signature generated by tfplugindocs --> | ||
```text | ||
parse_cidr(cidr string) object | ||
``` | ||
|
||
## Arguments | ||
|
||
<!-- arguments generated by tfplugindocs --> | ||
1. `cidr` (String) The IP address and prefix length in CIDR notation. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.