Skip to content

Commit

Permalink
Merge pull request #11 from Edge-Center/CLOUD-188_metadata
Browse files Browse the repository at this point in the history
Resources metadata
  • Loading branch information
anaxaim authored Mar 23, 2023
2 parents c2481a2 + 46fb964 commit 62becc9
Show file tree
Hide file tree
Showing 31 changed files with 672 additions and 66 deletions.
2 changes: 1 addition & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
run:
timeout: 10m
go: "1.19"
go: "1.20"

issues:
max-per-linter: 0
Expand Down
12 changes: 12 additions & 0 deletions docs/data-sources/floatingip.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ output "view" {

### Optional

- `metadata_k` (String)
- `metadata_kv` (Map of String)
- `port_id` (String)
- `project_id` (Number)
- `project_name` (String)
Expand All @@ -55,7 +57,17 @@ output "view" {

- `fixed_ip_address` (String)
- `id` (String) The ID of this resource.
- `metadata_read_only` (List of Object) (see [below for nested schema](#nestedatt--metadata_read_only))
- `router_id` (String)
- `status` (String)

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

Read-Only:

- `key` (String)
- `read_only` (Boolean)
- `value` (String)


12 changes: 12 additions & 0 deletions docs/data-sources/image.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ output "view" {
### Optional

- `is_baremetal` (Boolean) set to true if need to get baremetal image
- `metadata_k` (String)
- `metadata_kv` (Map of String)
- `project_id` (Number)
- `project_name` (String)
- `region_id` (Number)
Expand All @@ -55,9 +57,19 @@ output "view" {

- `description` (String)
- `id` (String) The ID of this resource.
- `metadata_read_only` (List of Object) (see [below for nested schema](#nestedatt--metadata_read_only))
- `min_disk` (Number)
- `min_ram` (Number)
- `os_distro` (String)
- `os_version` (String)

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

Read-Only:

- `key` (String)
- `read_only` (Boolean)
- `value` (String)


13 changes: 13 additions & 0 deletions docs/data-sources/loadbalancer.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ output "view" {

### Optional

- `metadata_k` (String)
- `metadata_kv` (Map of String)
- `project_id` (Number)
- `project_name` (String)
- `region_id` (Number)
Expand All @@ -54,6 +56,7 @@ output "view" {

- `id` (String) The ID of this resource.
- `listener` (List of Object) (see [below for nested schema](#nestedatt--listener))
- `metadata_read_only` (List of Object) (see [below for nested schema](#nestedatt--metadata_read_only))
- `vip_address` (String)
- `vip_port_id` (String)

Expand All @@ -68,3 +71,13 @@ Read-Only:
- `protocol_port` (Number)


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

Read-Only:

- `key` (String)
- `read_only` (Boolean)
- `value` (String)


12 changes: 12 additions & 0 deletions docs/data-sources/loadbalancerv2.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ output "view" {

### Optional

- `metadata_k` (String)
- `metadata_kv` (Map of String)
- `project_id` (Number)
- `project_name` (String)
- `region_id` (Number)
Expand All @@ -53,8 +55,18 @@ output "view" {
### Read-Only

- `id` (String) The ID of this resource.
- `metadata_read_only` (List of Object) (see [below for nested schema](#nestedatt--metadata_read_only))
- `security_group_id` (String) Load balancer security group ID
- `vip_address` (String)
- `vip_port_id` (String)

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

Read-Only:

- `key` (String)
- `read_only` (Boolean)
- `value` (String)


12 changes: 12 additions & 0 deletions docs/data-sources/volume.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ output "view" {

### Optional

- `metadata_k` (String)
- `metadata_kv` (Map of String)
- `project_id` (Number)
- `project_name` (String)
- `region_id` (Number)
Expand All @@ -53,7 +55,17 @@ output "view" {
### Read-Only

- `id` (String) The ID of this resource.
- `metadata_read_only` (List of Object) (see [below for nested schema](#nestedatt--metadata_read_only))
- `size` (Number)
- `type_name` (String) Available value is 'standard', 'ssd_hiiops', 'cold', 'ultra'. Defaults to standard

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

Read-Only:

- `key` (String)
- `read_only` (Boolean)
- `value` (String)


14 changes: 14 additions & 0 deletions docs/resources/floatingip.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ provider "edgecenter" {
resource "edgecenter_floatingip" "floating_ip" {
project_id = 1
region_id = 1
metadata_map = {
tag1 = "tag1_value"
}
// fixed_ip_address = "192.168.10.39" // instance`s interface ip
// port_id = "5c992875-f653-4b7b-af5b-1dc3019e5ffa" //instance`s interface port_id
}
Expand All @@ -32,6 +35,7 @@ resource "edgecenter_floatingip" "floating_ip" {

- `fixed_ip_address` (String)
- `last_updated` (String)
- `metadata_map` (Map of String)
- `port_id` (String)
- `project_id` (Number)
- `project_name` (String)
Expand All @@ -43,10 +47,20 @@ resource "edgecenter_floatingip" "floating_ip" {
- `created_at` (String)
- `floating_ip_address` (String)
- `id` (String) The ID of this resource.
- `metadata_read_only` (List of Object) (see [below for nested schema](#nestedatt--metadata_read_only))
- `router_id` (String)
- `status` (String)
- `updated_at` (String)

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

Read-Only:

- `key` (String)
- `read_only` (Boolean)
- `value` (String)

## Import

Import is supported using the following syntax:
Expand Down
12 changes: 12 additions & 0 deletions docs/resources/loadbalancer.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ resource "edgecenter_loadbalancer" "lb" {

- `flavor` (String)
- `last_updated` (String)
- `metadata_map` (Map of String)
- `project_id` (Number)
- `project_name` (String)
- `region_id` (Number)
Expand All @@ -57,6 +58,7 @@ resource "edgecenter_loadbalancer" "lb" {
### Read-Only

- `id` (String) The ID of this resource.
- `metadata_read_only` (List of Object) (see [below for nested schema](#nestedatt--metadata_read_only))
- `vip_address` (String) Load balancer IP address

<a id="nestedblock--listener"></a>
Expand Down Expand Up @@ -90,6 +92,16 @@ Optional:
- `create` (String)
- `delete` (String)


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

Read-Only:

- `key` (String)
- `read_only` (Boolean)
- `value` (String)

## Import

Import is supported using the following syntax:
Expand Down
15 changes: 15 additions & 0 deletions docs/resources/loadbalancerv2.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ resource "edgecenter_loadbalancerv2" "lb" {
region_id = 1
name = "test"
flavor = "lb1-1-2"
metadata_map = {
tag1 = "tag1_value"
}
}
```

Expand All @@ -36,6 +39,7 @@ resource "edgecenter_loadbalancerv2" "lb" {

- `flavor` (String)
- `last_updated` (String)
- `metadata_map` (Map of String)
- `project_id` (Number)
- `project_name` (String)
- `region_id` (Number)
Expand All @@ -48,6 +52,7 @@ resource "edgecenter_loadbalancerv2" "lb" {
### Read-Only

- `id` (String) The ID of this resource.
- `metadata_read_only` (List of Object) (see [below for nested schema](#nestedatt--metadata_read_only))
- `security_group_id` (String) Load balancer security group ID
- `vip_address` (String) Load balancer IP address

Expand All @@ -59,6 +64,16 @@ Optional:
- `create` (String)
- `delete` (String)


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

Read-Only:

- `key` (String)
- `read_only` (Boolean)
- `value` (String)

## Import

Import is supported using the following syntax:
Expand Down
1 change: 0 additions & 1 deletion docs/resources/network.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ provider "edgecenter" {
resource "edgecenter_network" "network" {
name = "network_example"
mtu = 1450
type = "vxlan"
region_id = 1
project_id = 1
Expand Down
14 changes: 14 additions & 0 deletions docs/resources/volume.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ resource "edgecenter_volume" "volume" {
size = 1
region_id = 1
project_id = 1
metadata_map = {
tag1 = "tag1_value"
}
}
```

Expand All @@ -37,6 +40,7 @@ resource "edgecenter_volume" "volume" {

- `image_id` (String) Mandatory if volume is created from image
- `last_updated` (String)
- `metadata_map` (Map of String)
- `project_id` (Number)
- `project_name` (String)
- `region_id` (Number)
Expand All @@ -48,6 +52,16 @@ resource "edgecenter_volume" "volume" {
### Read-Only

- `id` (String) The ID of this resource.
- `metadata_read_only` (List of Object) (see [below for nested schema](#nestedatt--metadata_read_only))

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

Read-Only:

- `key` (String)
- `read_only` (Boolean)
- `value` (String)

## Import

Expand Down
53 changes: 52 additions & 1 deletion edgecenter/data_source_edgecenter_floatingip.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"

"github.com/Edge-Center/edgecentercloud-go/edgecenter/floatingip/v1/floatingips"
"github.com/Edge-Center/edgecentercloud-go/edgecenter/utils"
)

func dataSourceFloatingIP() *schema.Resource {
Expand Down Expand Up @@ -79,6 +80,37 @@ func dataSourceFloatingIP() *schema.Resource {
Type: schema.TypeString,
Optional: true,
},
"metadata_k": {
Type: schema.TypeString,
Optional: true,
},
"metadata_kv": {
Type: schema.TypeMap,
Optional: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
"metadata_read_only": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"key": {
Type: schema.TypeString,
Computed: true,
},
"value": {
Type: schema.TypeString,
Computed: true,
},
"read_only": {
Type: schema.TypeBool,
Computed: true,
},
},
},
},
},
}
}
Expand All @@ -95,7 +127,21 @@ func dataSourceFloatingIPRead(ctx context.Context, d *schema.ResourceData, m int
}

ipAddr := d.Get("floating_ip_address").(string)
ips, err := floatingips.ListAll(client)
metaOpts := &floatingips.ListOpts{}

if metadataK, ok := d.GetOk("metadata_k"); ok {
metaOpts.MetadataK = metadataK.(string)
}

if metadataRaw, ok := d.GetOk("metadata_kv"); ok {
meta, err := utils.MapInterfaceToMapString(metadataRaw)
if err != nil {
return diag.FromErr(err)
}
metaOpts.MetadataKV = meta
}

ips, err := floatingips.ListAll(client, *metaOpts)
if err != nil {
return diag.FromErr(err)
}
Expand Down Expand Up @@ -128,6 +174,11 @@ func dataSourceFloatingIPRead(ctx context.Context, d *schema.ResourceData, m int
d.Set("router_id", floatingIP.RouterID)
d.Set("floating_ip_address", floatingIP.FloatingIPAddress.String())

metadataReadOnly := PrepareMetadataReadonly(floatingIP.Metadata)
if err := d.Set("metadata_read_only", metadataReadOnly); err != nil {
return diag.FromErr(err)
}

log.Println("[DEBUG] Finish FloatingIP reading")

return diags
Expand Down
Loading

0 comments on commit 62becc9

Please sign in to comment.