Skip to content

Commit

Permalink
Feat edge application origins (#73)
Browse files Browse the repository at this point in the history
* feat: creating support to edge application Origins #minor

* feat: doc supporting to edge application #minor
  • Loading branch information
diegoazion authored Jul 5, 2023
1 parent ae21217 commit f9fa390
Show file tree
Hide file tree
Showing 19 changed files with 1,517 additions and 36 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ examples/.terraform.lock.hcl
.terraform.*
*.tfstate
terraform.tfstate.backup
terraform-provider-azion
terraform-provider-azion
/.idea/aws.xml
72 changes: 72 additions & 0 deletions docs/data-sources/edge_application_origin.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "azion_edge_application_origin Data Source - terraform-provider-azion"
subcategory: ""
description: |-
---

# azion_edge_application_origin (Data Source)



## Example Usage

```terraform
data "azion_edge_application_origin" "example" {
edge_application_id = "<edge_application_id>"
origin = {
origin_key = "<origin_key>"
}
}
```

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

### Required

- `edge_application_id` (Number) The edge application identifier.
- `origin` (Attributes) (see [below for nested schema](#nestedatt--origin))

### Read-Only

- `id` (String) Identifier of the data source.
- `schema_version` (Number) Schema Version.

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

Required:

- `origin_key` (String) Origin key.

Read-Only:

- `addresses` (Attributes List) (see [below for nested schema](#nestedatt--origin--addresses))
- `connection_timeout` (Number) Connection timeout in seconds.
- `hmac_access_key` (String) HMAC access key.
- `hmac_authentication` (Boolean) Whether HMAC authentication is enabled.
- `hmac_region_name` (String) HMAC region name.
- `hmac_secret_key` (String) HMAC secret key.
- `host_header` (String) Host header value.
- `is_origin_redirection_enabled` (Boolean) Whether origin redirection is enabled.
- `method` (String) HTTP method used by the origin.
- `name` (String) Name of the origin.
- `origin_id` (Number) The origin identifier to target for the resource.
- `origin_path` (String) Path of the origin.
- `origin_protocol_policy` (String) Origin protocol policy.
- `origin_type` (String) Type of the origin.
- `timeout_between_bytes` (Number) Timeout between bytes in seconds.

<a id="nestedatt--origin--addresses"></a>
### Nested Schema for `origin.addresses`

Read-Only:

- `address` (String) Address of the origin.
- `is_active` (Boolean) Status of the origin.
- `server_role` (String) Server role of the origin.
- `weight` (String) Weight of the origin.


83 changes: 83 additions & 0 deletions docs/data-sources/edge_applications_origins.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "azion_edge_applications_origins Data Source - terraform-provider-azion"
subcategory: ""
description: |-
---

# azion_edge_applications_origins (Data Source)



## Example Usage

```terraform
data "azion_edge_applications_origins" "example" {
edge_application_id = "<edge_application_id>"
}
```

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

### Required

- `edge_application_id` (Number) The edge application identifier.

### Optional

- `page` (Number) The page number of edge applications.
- `page_size` (Number) The Page Size number of edge applications.

### Read-Only

- `counter` (Number) The total number of edge applications.
- `id` (String) Identifier of the data source.
- `links` (Attributes) (see [below for nested schema](#nestedatt--links))
- `results` (Attributes List) (see [below for nested schema](#nestedatt--results))
- `schema_version` (Number) Schema Version.
- `total_pages` (Number) The total number of pages.

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

Read-Only:

- `next` (String)
- `previous` (String)


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

Read-Only:

- `addresses` (Attributes List) (see [below for nested schema](#nestedatt--results--addresses))
- `connection_timeout` (Number) Connection timeout in seconds.
- `hmac_access_key` (String) HMAC access key.
- `hmac_authentication` (Boolean) Whether HMAC authentication is enabled.
- `hmac_region_name` (String) HMAC region name.
- `hmac_secret_key` (String) HMAC secret key.
- `host_header` (String) Host header value.
- `is_origin_redirection_enabled` (Boolean) Whether origin redirection is enabled.
- `method` (String) HTTP method used by the origin.
- `name` (String) Name of the origin.
- `origin_id` (Number) The origin identifier to target for the resource.
- `origin_key` (String) Origin key.
- `origin_path` (String) Path of the origin.
- `origin_protocol_policy` (String) Origin protocol policy.
- `origin_type` (String) Type of the origin.
- `timeout_between_bytes` (Number) Timeout between bytes in seconds.

<a id="nestedatt--results--addresses"></a>
### Nested Schema for `results.addresses`

Read-Only:

- `address` (String) Address of the origin.
- `is_active` (Boolean) Status of the origin.
- `server_role` (String) Server role of the origin.
- `weight` (String) Weight of the origin.


104 changes: 104 additions & 0 deletions docs/resources/edge_application_origin.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "azion_edge_application_origin Resource - terraform-provider-azion"
subcategory: ""
description: |-
---

# azion_edge_application_origin (Resource)



## Example Usage

```terraform
resource "azion_edge_application_origin" "example" {
edge_application_id = <edge_application_id>
origin = {
name = "Terraform Example"
origin_type = "single_origin"
addresses: [
{
"address": "terraform.org"
}
],
origin_protocol_policy: "http",
host_header: "$${host}",
origin_path: "/requests",
hmac_authentication: false,
hmac_region_name: "",
hmac_access_key: "",
hmac_secret_key: ""
}
}
```

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

### Required

- `edge_application_id` (Number) The edge application identifier.
- `origin` (Attributes) Origin configuration. (see [below for nested schema](#nestedatt--origin))

### Read-Only

- `id` (String) The ID of this resource.
- `last_updated` (String) Timestamp of the last Terraform update of the resource.
- `schema_version` (Number)

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

Required:

- `addresses` (Attributes List) (see [below for nested schema](#nestedatt--origin--addresses))
- `host_header` (String) Host header value that will be delivered to the origin.
~> **Note about Host Header**
Accepted values: `${host}`(default) and must be specified with `$${host}`
- `name` (String) Origin name.

Optional:

- `connection_timeout` (Number) Connection timeout in seconds.
- `hmac_access_key` (String) HMAC access key.
- `hmac_authentication` (Boolean) Whether HMAC authentication is enabled.
- `hmac_region_name` (String) HMAC region name.
- `hmac_secret_key` (String) HMAC secret key.
- `origin_path` (String) Path of the origin.
- `origin_protocol_policy` (String) Protocols for connection to the origin.
~> **Note about Origin Protocol Policy**
Accepted values: `preserve`(default), `http` and `https`
- `origin_type` (String) Identifies the source of a record.
~> **Note about Origin Type**
Accepted values: `single_origin`(default), `load_balancer` and `live_ingest`
- `timeout_between_bytes` (Number) Timeout between bytes in seconds.

Read-Only:

- `is_origin_redirection_enabled` (Boolean) Whether origin redirection is enabled.
- `method` (String) HTTP method used by the origin.
- `origin_id` (Number) Origin identifier.
- `origin_key` (String) Origin key.

<a id="nestedatt--origin--addresses"></a>
### Nested Schema for `origin.addresses`

Required:

- `address` (String) Address of the origin.

Optional:

- `is_active` (Boolean) Status of the origin.
- `server_role` (String) Server role of the origin.
- `weight` (String) Weight of the origin.

## Import

Import is supported using the following syntax:

```shell
terraform import azion_edge_application_origin.example <edge_application_id>/<origin_key>
```
5 changes: 4 additions & 1 deletion docs/resources/edge_function.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
page_title: "azion_edge_function Resource - terraform-provider-azion"
subcategory: ""
description: |-
~> Note about Json_Args
Parameter json_args must be specified with jsonencode function
~> Note about Code
Parameter code may be specified with local_file in - https://registry.terraform.io/providers/hashicorp/local/latest/docs/resources/file
---

# azion_edge_function (Resource)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
data "azion_edge_application_origin" "example" {
edge_application_id = "<edge_application_id>"
origin = {
origin_key = "<origin_key>"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
data "azion_edge_applications_origins" "example" {
edge_application_id = "<edge_application_id>"
}
1 change: 1 addition & 0 deletions examples/resources/azion_edge_application_origin/import.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
terraform import azion_edge_application_origin.example <edge_application_id>/<origin_key>
19 changes: 19 additions & 0 deletions examples/resources/azion_edge_application_origin/resource.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
resource "azion_edge_application_origin" "example" {
edge_application_id = <edge_application_id>
origin = {
name = "Terraform Example"
origin_type = "single_origin"
addresses: [
{
"address": "terraform.org"
}
],
origin_protocol_policy: "http",
host_header: "$${host}",
origin_path: "/requests",
hmac_authentication: false,
hmac_region_name: "",
hmac_access_key: "",
hmac_secret_key: ""
}
}
20 changes: 10 additions & 10 deletions internal/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,16 @@ type apiClient struct {
edgefunctionsConfig *edgefunctions.Configuration
edgefunctionsApi *edgefunctions.APIClient

edgeAplicationsConfig *edgeapplications.Configuration
edgeAplicationsApi *edgeapplications.APIClient
edgeApplicationsConfig *edgeapplications.Configuration
edgeApplicationsApi *edgeapplications.APIClient
}

func Client(APIToken string, userAgent string) *apiClient {
client := &apiClient{
idnsConfig: idns.NewConfiguration(),
domainsConfig: domains.NewConfiguration(),
edgefunctionsConfig: edgefunctions.NewConfiguration(),
edgeAplicationsConfig: edgeapplications.NewConfiguration(),
idnsConfig: idns.NewConfiguration(),
domainsConfig: domains.NewConfiguration(),
edgefunctionsConfig: edgefunctions.NewConfiguration(),
edgeApplicationsConfig: edgeapplications.NewConfiguration(),
}

envApiEntrypoint := os.Getenv("AZION_API_ENTRYPOINT")
Expand All @@ -52,10 +52,10 @@ func Client(APIToken string, userAgent string) *apiClient {
client.edgefunctionsConfig.UserAgent = userAgent
client.edgefunctionsApi = edgefunctions.NewAPIClient(client.edgefunctionsConfig)

client.edgeAplicationsConfig.AddDefaultHeader("Authorization", "token "+APIToken)
client.edgeAplicationsConfig.AddDefaultHeader("Accept", "application/json; version=3")
client.edgeAplicationsConfig.UserAgent = userAgent
client.edgeAplicationsApi = edgeapplications.NewAPIClient(client.edgeAplicationsConfig)
client.edgeApplicationsConfig.AddDefaultHeader("Authorization", "token "+APIToken)
client.edgeApplicationsConfig.AddDefaultHeader("Accept", "application/json; version=3")
client.edgeApplicationsConfig.UserAgent = userAgent
client.edgeApplicationsApi = edgeapplications.NewAPIClient(client.edgeApplicationsConfig)

return client
}
3 changes: 2 additions & 1 deletion internal/data_source_edge_application_main_settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,8 @@ func (e *EdgeApplicationDataSource) Read(ctx context.Context, req datasource.Rea
return
}

edgeApplicationsResponse, response, err := e.client.edgeAplicationsApi.EdgeApplicationsMainSettingsApi.EdgeApplicationsIdGet(ctx, getEdgeApplicationId.ValueString()).Execute()
edgeApplicationsResponse, response, err := e.client.edgeApplicationsApi.EdgeApplicationsMainSettingsApi.EdgeApplicationsIdGet(ctx, getEdgeApplicationId.ValueString()).Execute()

if err != nil {
bodyBytes, erro := io.ReadAll(response.Body)
if erro != nil {
Expand Down
Loading

0 comments on commit f9fa390

Please sign in to comment.