Skip to content

Commit

Permalink
Feat edge application edge functions #minor (#74)
Browse files Browse the repository at this point in the history
* feat: Resource support to edge applications edge functions instance #minor

* doc: Doc support to edge applications edge functions instance #minor
  • Loading branch information
diegoazion authored Jul 10, 2023
1 parent f9fa390 commit ce17091
Show file tree
Hide file tree
Showing 11 changed files with 1,001 additions and 0 deletions.
50 changes: 50 additions & 0 deletions docs/data-sources/edge_application_edge_function_instance.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "azion_edge_application_edge_function_instance Data Source - terraform-provider-azion"
subcategory: ""
description: |-
---

# azion_edge_application_edge_function_instance (Data Source)



## Example Usage

```terraform
data "azion_edge_application_edge_function_instance" "example" {
edge_application_id = <edge_application_id>
results = {
id = <edge_functions_instance>
}
}
```

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

### Required

- `edge_application_id` (Number) Numeric identifier of the Edge Application
- `results` (Attributes) (see [below for nested schema](#nestedatt--results))

### Read-Only

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

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

Required:

- `id` (Number) The function identifier.

Read-Only:

- `args` (String) Code of the function.
- `edge_function_id` (Number) The function identifier.
- `name` (String) Name of the function.


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

# azion_edge_application_edge_functions_instance (Data Source)



## Example Usage

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

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

### Required

- `edge_application_id` (Number) Numeric identifier of the Edge Application

### Optional

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

### Read-Only

- `counter` (Number) The total number of edge function instances.
- `id` (String) Numeric 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:

- `args` (String) Code of the function.
- `edge_function_id` (Number) Name of the function.
- `id` (Number) The function identifier.
- `name` (String) Language of the function.


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

# azion_edge_application_edge_functions_instance (Resource)



## Example Usage

```terraform
resource "azion_edge_application_edge_functions_instance" "example" {
edge_application_id = <edge_application_id>
results = {
name = "Terraform Example"
"edge_function_id": <edge_function_id>,
"args": jsonencode(
{ "key" = "Value",
"Example" = "example"
})
}
}
```

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

### Required

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

### 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--results"></a>
### Nested Schema for `results`

Required:

- `edge_function_id` (Number) The edge function identifier.
- `name` (String) Name of the function.

Optional:

- `args` (String) JSON arguments of the function.

Read-Only:

- `id` (Number) The edge function instance identifier.

## Import

Import is supported using the following syntax:

```shell
terraform import azion_edge_application_edge_functions_instance.example <edge_application_id>/<edge_function_instance_id>
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
data "azion_edge_application_edge_function_instance" "example" {
edge_application_id = <edge_application_id>
results = {
id = <edge_functions_instance>
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
data "azion_edge_application_edge_functions_instance" "example" {
edge_application_id = "<edge_application_id>"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
terraform import azion_edge_application_edge_functions_instance.example <edge_application_id>/<edge_function_instance_id>
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
resource "azion_edge_application_edge_functions_instance" "example" {
edge_application_id = <edge_application_id>
results = {
name = "Terraform Example"
"edge_function_id": <edge_function_id>,
"args": jsonencode(
{ "key" = "Value",
"Example" = "example"
})
}
}
153 changes: 153 additions & 0 deletions internal/data_source_edge_application_edge_function_instance.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
package provider

import (
"context"
"io"

"github.com/hashicorp/terraform-plugin-framework/path"

"github.com/aziontech/terraform-provider-azion/internal/utils"
"github.com/hashicorp/terraform-plugin-framework/datasource"
"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
"github.com/hashicorp/terraform-plugin-framework/types"
)

var (
_ datasource.DataSource = &EdgeApplicationEdgeFunctionInstanceDataSource{}
_ datasource.DataSourceWithConfigure = &EdgeApplicationEdgeFunctionInstanceDataSource{}
)

func dataSourceAzionEdgeApplicationEdgeFunctionInstance() datasource.DataSource {
return &EdgeApplicationEdgeFunctionInstanceDataSource{}
}

type EdgeApplicationEdgeFunctionInstanceDataSource struct {
client *apiClient
}

type EdgeFunctionInstanceDataSourceModel struct {
ID types.String `tfsdk:"id"`
ApplicationID types.Int64 `tfsdk:"edge_application_id"`
SchemaVersion types.Int64 `tfsdk:"schema_version"`
Results EdgeFunctionInstanceResponse `tfsdk:"results"`
}

type GetEdgeFunctionInstanceResponseLinks struct {
Previous types.String `tfsdk:"previous"`
Next types.String `tfsdk:"next"`
}

type EdgeFunctionInstanceResponse struct {
ID types.Int64 `tfsdk:"id"`
EdgeFunctionID types.Int64 `tfsdk:"edge_function_id"`
Name types.String `tfsdk:"name"`
Args types.String `tfsdk:"args"`
}

func (d *EdgeApplicationEdgeFunctionInstanceDataSource) Configure(_ context.Context, req datasource.ConfigureRequest, _ *datasource.ConfigureResponse) {
if req.ProviderData == nil {
return
}
d.client = req.ProviderData.(*apiClient)
}

func (d *EdgeApplicationEdgeFunctionInstanceDataSource) Metadata(ctx context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) {
resp.TypeName = req.ProviderTypeName + "_edge_application_edge_function_instance"
}

func (d *EdgeApplicationEdgeFunctionInstanceDataSource) Schema(_ context.Context, _ datasource.SchemaRequest, resp *datasource.SchemaResponse) {
resp.Schema = schema.Schema{
Attributes: map[string]schema.Attribute{
"id": schema.StringAttribute{
Description: "Numeric identifier of the data source.",
Computed: true,
},
"edge_application_id": schema.Int64Attribute{
Description: "Numeric identifier of the Edge Application",
Required: true,
},
"schema_version": schema.Int64Attribute{
Description: "Schema Version.",
Computed: true,
},
"results": schema.SingleNestedAttribute{
Required: true,
Attributes: map[string]schema.Attribute{
"id": schema.Int64Attribute{
Description: "The function identifier.",
Required: true,
},
"edge_function_id": schema.Int64Attribute{
Description: "The function identifier.",
Computed: true,
},
"name": schema.StringAttribute{
Description: "Name of the function.",
Computed: true,
},
"args": schema.StringAttribute{
Description: "Code of the function.",
Computed: true,
},
},
},
},
}
}

func (d *EdgeApplicationEdgeFunctionInstanceDataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) {
var EdgeApplicationId types.Int64
diagsEdgeApplicationId := req.Config.GetAttribute(ctx, path.Root("edge_application_id"), &EdgeApplicationId)
resp.Diagnostics.Append(diagsEdgeApplicationId...)
if resp.Diagnostics.HasError() {
return
}

var EdgeFunctionInstanceId types.Int64
diagsEdgeFunctionInstanceId := req.Config.GetAttribute(ctx, path.Root("results").AtName("id"), &EdgeFunctionInstanceId)
resp.Diagnostics.Append(diagsEdgeFunctionInstanceId...)
if resp.Diagnostics.HasError() {
return
}
edgeFunctionInstancesResponse, response, err := d.client.edgeApplicationsApi.EdgeApplicationsEdgeFunctionsInstancesApi.EdgeApplicationsEdgeApplicationIdFunctionsInstancesFunctionsInstancesIdGet(ctx, EdgeApplicationId.ValueInt64(), EdgeFunctionInstanceId.ValueInt64()).Execute()
if err != nil {
bodyBytes, erro := io.ReadAll(response.Body)
if erro != nil {
resp.Diagnostics.AddError(
err.Error(),
"err",
)
}
bodyString := string(bodyBytes)
resp.Diagnostics.AddError(
err.Error(),
bodyString,
)
return
}

jsonArgsStr, err := utils.ConvertInterfaceToString(edgeFunctionInstancesResponse.Results.GetArgs())
if err != nil {
resp.Diagnostics.AddError(
err.Error(),
"err",
)
}
edgeApplicationsEdgeFunctionsInstanceState := EdgeFunctionInstanceDataSourceModel{
ApplicationID: EdgeApplicationId,
SchemaVersion: types.Int64Value(edgeFunctionInstancesResponse.SchemaVersion),
Results: EdgeFunctionInstanceResponse{
ID: types.Int64Value(edgeFunctionInstancesResponse.Results.GetId()),
EdgeFunctionID: types.Int64Value(edgeFunctionInstancesResponse.Results.GetEdgeFunctionId()),
Name: types.StringValue(edgeFunctionInstancesResponse.Results.GetName()),
Args: types.StringValue(jsonArgsStr),
},
}

edgeApplicationsEdgeFunctionsInstanceState.ID = types.StringValue("Get By ID Edge Applications Edge Functions Instances")
diags := resp.State.Set(ctx, &edgeApplicationsEdgeFunctionsInstanceState)
resp.Diagnostics.Append(diags...)
if resp.Diagnostics.HasError() {
return
}
}
Loading

0 comments on commit ce17091

Please sign in to comment.