Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/m vpc #457

Merged
merged 11 commits into from
Jun 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 67 additions & 0 deletions client/v3/v3_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,11 @@ type Service interface {
DeleteAddressGroup(uuid string) error
CreateAddressGroup(request *AddressGroupInput) (*Reference, error)
UpdateAddressGroup(uuid string, body *AddressGroupInput) error
CreateVPC(ctx context.Context, createRequest *VPCIntentInput) (*VPCIntentResponse, error)
GetVPC(ctx context.Context, uuid string) (*VPCIntentResponse, error)
DeleteVPC(ctx context.Context, uuid string) (*DeleteResponse, error)
UpdateVPC(ctx context.Context, uuid string, body *VPCIntentInput) (*VPCIntentResponse, error)
ListVPC(ctx context.Context, getEntitiesRequest *DSMetadata) (*VPCListIntentResponse, error)
}

/*CreateVM Creates a VM
Expand Down Expand Up @@ -2428,3 +2433,65 @@ func (op Operations) UpdateAddressGroup(uuid string, body *AddressGroupInput) er

return op.client.Do(ctx, req, nil)
}

func (op Operations) CreateVPC(ctx context.Context, request *VPCIntentInput) (*VPCIntentResponse, error) {
req, err := op.client.NewRequest(ctx, http.MethodPost, "/vpcs", request)
vpcIntentResponse := new(VPCIntentResponse)

if err != nil {
return nil, err
}

return vpcIntentResponse, op.client.Do(ctx, req, vpcIntentResponse)
}

func (op Operations) GetVPC(ctx context.Context, uuid string) (*VPCIntentResponse, error) {
path := fmt.Sprintf("/vpcs/%s", uuid)

req, err := op.client.NewRequest(ctx, http.MethodGet, path, nil)
vpcIntentResponse := new(VPCIntentResponse)

if err != nil {
return nil, err
}

return vpcIntentResponse, op.client.Do(ctx, req, vpcIntentResponse)
}

func (op Operations) DeleteVPC(ctx context.Context, uuid string) (*DeleteResponse, error) {
path := fmt.Sprintf("/vpcs/%s", uuid)

req, err := op.client.NewRequest(ctx, http.MethodDelete, path, nil)
deleteResponse := new(DeleteResponse)

if err != nil {
return nil, err
}

return deleteResponse, op.client.Do(ctx, req, deleteResponse)
}

func (op Operations) UpdateVPC(ctx context.Context, uuid string, body *VPCIntentInput) (*VPCIntentResponse, error) {
path := fmt.Sprintf("/vpcs/%s", uuid)
req, err := op.client.NewRequest(ctx, http.MethodPut, path, body)
vpcIntentResponse := new(VPCIntentResponse)

if err != nil {
return nil, err
}

return vpcIntentResponse, op.client.Do(ctx, req, vpcIntentResponse)
}

func (op Operations) ListVPC(ctx context.Context, getEntitiesRequest *DSMetadata) (*VPCListIntentResponse, error) {
path := "/vpcs/list"

req, err := op.client.NewRequest(ctx, http.MethodPost, path, getEntitiesRequest)
vpcListIntentResponse := new(VPCListIntentResponse)

if err != nil {
return nil, err
}

return vpcListIntentResponse, op.client.Do(ctx, req, vpcListIntentResponse)
}
66 changes: 66 additions & 0 deletions client/v3/v3_structs.go
Original file line number Diff line number Diff line change
Expand Up @@ -2600,3 +2600,69 @@ type AddressGroupListResponse struct {
Metadata *ListMetadataOutput `json:"metadata,omitempty"`
Entities []*AddressGroupListEntry `json:"entities,omitempty"`
}

type ActiveGatewayNode struct {
HostReference *Reference `json:"host_reference,omitempty"`
IPAddress *string `json:"ip_address,omitempty"`
}

type CommonDomainNameServerIPList struct {
IP *string `json:"ip,omitempty"`
}

type ExternalSubnetList struct {
ExternalSubnetReference *Reference `json:"external_subnet_reference,omitempty"`
ExternalIPList []*string `json:"external_ip_list,omitempty"`
ActiveGatewayNode *ActiveGatewayNode `json:"active_gateway_node,omitempty"`
}

type ExternallyRoutablePrefixList struct {
IP *string `json:"ip,omitempty"`
PrefixLength *int `json:"prefix_length,omitempty"`
}

type VpcResources struct {
ExternalSubnetList []*ExternalSubnetList `json:"external_subnet_list,omitempty"`
ExternallyRoutablePrefixList []*ExternallyRoutablePrefixList `json:"externally_routable_prefix_list,omitempty"`
CommonDomainNameServerIPList []*CommonDomainNameServerIPList `json:"common_domain_name_server_ip_list,omitempty"`
}

type VPC struct {
Name *string `json:"name,omitempty"`
Resources *VpcResources `json:"resources,omitempty"`
}

type VPCIntentInput struct {
APIVersion *string `json:"api_version,omitempty" mapstructure:"api_version,omitempty"`

Metadata *Metadata `json:"metadata" mapstructure:"metadata"`

Spec *VPC `json:"spec" mapstructure:"spec"`
}

type VPCDefStatus struct {
State *string `json:"state,omitempty" mapstructure:"state,omitempty"`
Name *string `json:"name,omitempty"`

ExecutionContext *ExecutionContext `json:"execution_context,omitempty" mapstructure:"execution_context,omitempty"`

Resources *VpcResources `json:"resources,omitempty"`

ExternalSubnetListStatus []*ExternalSubnetList `json:"external_subnet_list,omitempty"`
}

type VPCIntentResponse struct {
APIVersion *string `json:"api_version,omitempty" mapstructure:"api_version,omitempty"`

Metadata *Metadata `json:"metadata" mapstructure:"metadata"`

Spec *VPC `json:"spec" mapstructure:"spec"`

Status *VPCDefStatus `json:"status"`
}

type VPCListIntentResponse struct {
APIVersion *string `json:"api_version"`
Metadata *ListMetadataOutput `json:"metadata"`
Entities []*VPCIntentResponse `json:"entities"`
}
92 changes: 92 additions & 0 deletions examples/vpc/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
terraform{
required_providers{
nutanix = {
source = "nutanix/nutanix"
version = "1.6.0"
}
}
}
provider "nutanix" {
username = "admin"
password = "Nutanix/123456"
endpoint = "10.xx.xx.xx"
insecure = true
port = 9440
}


#pull all clusters data
data "nutanix_clusters" "clusters"{}

#create local variable pointing to desired cluster
locals {
cluster1 = [
for cluster in data.nutanix_clusters.clusters.entities :
cluster.metadata.uuid if cluster.service_list[0] != "PRISM_CENTRAL"
][0]
}

#creating subnet
resource "nutanix_subnet" "acc" {
name = "vpc-sub"
description = "Description of my unit test VLAN updated"
subnet_type = "VLAN"
cluster_uuid = local.cluster1
vlan_id = 121
subnet_ip = "10.xx.xx.xx"
default_gateway_ip = "10.xx.xx.xx"
prefix_length = 24

is_external = true
enable_nat = false
ip_config_pool_list_ranges = ["10.xx.xx.xx 10.xx.xx.xx"]

}

// creating VPC

resource "nutanix_vpc" "test1" {
name = "testtNew-1"

// Ext Subnet Reference
external_subnet_reference_uuid = [
resource.nutanix_subnet.acc.id
]

common_domain_name_server_ip_list{
ip = "x.x.x.x"
}

externally_routable_prefix_list{
ip= "192.xx.x.xx"
prefix_length= 24
}

}


// dataSources for VPC


//dataSource to get details for an entity

data "nutanix_vpc" "vpc"{
// vpc uuid required to get VPC entity
vpc_uuid = ""
}

output "vpcOut1" {
value = data.nutanix_vpc.vpc
}


// dataSource to all vpc present

data "nutanix_vpc_list" "vpclist"{
// Optional paramters are length and offset
length = 10
}

output "vpcOut2" {
value = data.nutanix_vpc_list.vpclist
}
Loading