Skip to content

Commit

Permalink
Merge pull request #52 from ans-group/vpc-client
Browse files Browse the repository at this point in the history
add support for VPC clients
  • Loading branch information
0x4c6565 authored Sep 8, 2023
2 parents 07d0b74 + 3e74125 commit 62c01bb
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 3 deletions.
2 changes: 2 additions & 0 deletions docs/data-sources/ecloud_vpc.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,13 @@ data "ecloud_vpc" "vpc-1" {

- `vpc_id`: ID of VPC
- `region_id`: ID of VPC region
- `client_id`: ID of VPC client
- `name`: Name of VPC

## Attributes Reference

`id` is set to VPC ID

- `region_id`: ID of VPC region
- `client_id`: ID of VPC client
- `name`: Name of VPC
1 change: 1 addition & 0 deletions docs/resources/ecloud_vpc.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@ resource "ecloud_vpc" "vpc-1" {

- `region_id`: (Required) ID of VPC region
- `name`: Name of VPC
- `client_id`: ID of VPC client
- `advanced_networking`: Whether advanced networking is enabled or disabled for the VPC. Can only be set during VPC creation. When enabled, network policies and rules can be applied to restrict East-West traffic flow between networks.
9 changes: 9 additions & 0 deletions ecloud/data_source_vpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package ecloud
import (
"errors"
"fmt"
"strconv"

"github.com/ans-group/sdk-go/pkg/connection"
ecloudservice "github.com/ans-group/sdk-go/pkg/service/ecloud"
Expand All @@ -22,6 +23,10 @@ func dataSourceVPC() *schema.Resource {
Type: schema.TypeString,
Optional: true,
},
"client_id": {
Type: schema.TypeInt,
Optional: true,
},
"name": {
Type: schema.TypeString,
Optional: true,
Expand All @@ -41,6 +46,9 @@ func dataSourceVPCRead(d *schema.ResourceData, meta interface{}) error {
if regionID, ok := d.GetOk("region_id"); ok {
params.WithFilter(*connection.NewAPIRequestFiltering("region_id", connection.EQOperator, []string{regionID.(string)}))
}
if clientID, ok := d.GetOk("client_id"); ok {
params.WithFilter(*connection.NewAPIRequestFiltering("client_id", connection.EQOperator, []string{strconv.Itoa(clientID.(int))}))
}
if name, ok := d.GetOk("name"); ok {
params.WithFilter(*connection.NewAPIRequestFiltering("name", connection.EQOperator, []string{name.(string)}))
}
Expand All @@ -60,6 +68,7 @@ func dataSourceVPCRead(d *schema.ResourceData, meta interface{}) error {

d.SetId(vpcs[0].ID)
d.Set("region_id", vpcs[0].RegionID)
d.Set("client_id", vpcs[0].ClientID)
d.Set("name", vpcs[0].Name)

return nil
Expand Down
5 changes: 5 additions & 0 deletions ecloud/resource_vpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ func resourceVPC() *schema.Resource {
Type: schema.TypeString,
Optional: true,
},
"client_id": {
Type: schema.TypeInt,
Optional: true,
},
"advanced_networking": {
Type: schema.TypeBool,
Optional: true,
Expand All @@ -47,6 +51,7 @@ func resourceVPCCreate(d *schema.ResourceData, meta interface{}) error {
createReq := ecloudservice.CreateVPCRequest{
RegionID: d.Get("region_id").(string),
Name: d.Get("name").(string),
ClientID: d.Get("client_id").(int),
AdvancedNetworking: ptr.Bool(d.Get("advanced_networking").(bool)),
}
log.Printf("[DEBUG] Created CreateVPCRequest: %+v", createReq)
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/ukfast/terraform-provider-ecloud
go 1.18

require (
github.com/ans-group/sdk-go v1.16.6
github.com/ans-group/sdk-go v1.16.7
github.com/hashicorp/terraform-plugin-sdk/v2 v2.16.0
github.com/stretchr/testify v1.8.1
)
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ github.com/agext/levenshtein v1.2.2/go.mod h1:JEDfjyjHDjOF/1e4FlBE/PkbqA9OfWu2ki
github.com/anmitsu/go-shlex v0.0.0-20161002113705-648efa622239/go.mod h1:2FmKhYUyUczH0OGQWaF5ceTx0UBShxjsH6f8oGKYe2c=
github.com/ans-group/go-durationstring v1.2.0 h1:UJIuQATkp0t1rBvZsHRwki33YHV9E+Ulro+3NbMB7MM=
github.com/ans-group/go-durationstring v1.2.0/go.mod h1:QGF9Mdpq9058QXaut8r55QWu6lcHX6i/GvF1PZVkV6o=
github.com/ans-group/sdk-go v1.16.6 h1:WPdKk8Ze8SDh2afStBWmaLdufPhLxYgGdEKThIboD24=
github.com/ans-group/sdk-go v1.16.6/go.mod h1:p1vrXBxHPvMOGlS4sFUSgeLeKAl9vIe/lJ6UaExe49A=
github.com/ans-group/sdk-go v1.16.7 h1:oVk5ZQA66MBRadIligP8qETbWRcq0iPBTC+bACc/Yl8=
github.com/ans-group/sdk-go v1.16.7/go.mod h1:p1vrXBxHPvMOGlS4sFUSgeLeKAl9vIe/lJ6UaExe49A=
github.com/antihax/optional v1.0.0/go.mod h1:uupD/76wgC+ih3iEmQUL+0Ugr19nfwCT1kdvxnR2qWY=
github.com/apparentlymart/go-cidr v1.1.0 h1:2mAhrMoF+nhXqxTzSZMUzDHkLjmIHC+Zzn4tdgBZjnU=
github.com/apparentlymart/go-cidr v1.1.0/go.mod h1:EBcsNrHc3zQeuaeCeCtQruQm+n9/YjEn/vI25Lg7Gwc=
Expand Down

0 comments on commit 62c01bb

Please sign in to comment.