Skip to content

Commit

Permalink
Merge pull request #15 from fpt-corp/feat/fke
Browse files Browse the repository at this point in the history
Implement FKE & FDE
  • Loading branch information
namcv8 authored Oct 7, 2024
2 parents 9fff0e6 + 8c1d649 commit 7249547
Show file tree
Hide file tree
Showing 34 changed files with 5,069 additions and 28 deletions.
80 changes: 80 additions & 0 deletions commons/api_path.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,26 @@ var ApiPath = struct {
FindSubnetByName func(vpcId string) string
FindSubnet func(vpcId string, subnetId string) string
ListSubnets func(vpcId string) string

Subnet func(vpcId string) string
EdgeGatewayList func(vpcId string) string

DatabaseGet func(databaseId string) string
DatabaseCreate func() string
DatabaseDelete func(databaseId string) string
DatabaseStop func() string
DatabaseStart func() string

DedicatedFKEList func(vpcId string, page, pageSize int) string
DedicatedFKEGet func(vpcId string, clusterId string) string
DedicatedFKEUpgradeVersion func(vpcId string, clusterId string) string
DedicatedFKEManagement func(vpcId string, clusterId string) string

ManagedFKEList func(vpcId string, page int, pageSize int, infraType string) string
ManagedFKEGet func(vpcId string, platform string, clusterId string) string
ManagedFKEDelete func(vpcId string, platform string, clusterName string) string
ManagedFKECreate func(vpcId string, platform string) string
GetFKEOSVersion func(vpcId string, platform string) string
}{
SSH: "/v1/user/sshs",
Storage: func(vpcId string) string {
Expand Down Expand Up @@ -139,4 +159,64 @@ var ApiPath = struct {
ListSubnets: func(vpcId string) string {
return fmt.Sprintf("/v2/vpc/%s/networks", vpcId)
},

Subnet: func(vpcId string) string { return fmt.Sprintf("/v1/vmware/vpc/%s/network/subnets", vpcId) },

EdgeGatewayList: func(vpcId string) string {
return fmt.Sprintf("/v1/vmware/vpc/%s/edge_gateway/list", vpcId)
},

DatabaseGet: func(databaseId string) string {
return fmt.Sprintf("/v1/xplat/database/management/cluster/detail/%s", databaseId)
},
DatabaseCreate: func() string {
return "/v1/xplat/database/provision/create"
},
DatabaseDelete: func(databaseId string) string {
return fmt.Sprintf("/v1/xplat/database/provision/delete/%s", databaseId)
},
DatabaseStop: func() string {
return "/v1/xplat/database/management/cluster/stop"
},
DatabaseStart: func() string {
return "/v1/xplat/database/management/cluster/start"
},

DedicatedFKEList: func(vpcId string, page, pageSize int) string {
return fmt.Sprintf("/v1/xplat/fke/vpc/%s/kubernetes?page=%d&page_size=%d", vpcId, page, pageSize)
},
DedicatedFKEGet: func(vpcId string, clusterId string) string {
return fmt.Sprintf("/v1/xplat/fke/vpc/%s/cluster/%s?page=1&page_size=25", vpcId, clusterId)
},
DedicatedFKEUpgradeVersion: func(vpcId string, clusterId string) string {
return fmt.Sprintf("/v1/xplat/fke/vpc/%s/cluster/%s/upgrade-version", vpcId, clusterId)
},
DedicatedFKEManagement: func(vpcId string, clusterId string) string {
return fmt.Sprintf("/v1/xplat/fke/vpc/%s/kubernetes/%s/management", vpcId, clusterId)
},

ManagedFKEList: func(vpcId string, page int, pageSize int, infraType string) string {
return fmt.Sprintf("/v1/xplat/fke/vpc/%s/m-fke/%s/get-shoot-cluster/shoots?page=%d&page_size=%d", vpcId, infraType, page, pageSize)
},
ManagedFKEDelete: func(vpcId string, platform string, clusterName string) string {
return fmt.Sprintf(
"/v1/xplat/fke/vpc/%s/m-fke/%s/delete-shoot-cluster/shoots/%s",
vpcId, platform, clusterName,
)
},
ManagedFKECreate: func(vpcId string, platform string) string {
return fmt.Sprintf(
"/v1/xplat/fke/vpc/%s/m-fke/%s/create-cluster",
vpcId, platform,
)
},
ManagedFKEGet: func(vpcId string, platform string, clusterId string) string {
return fmt.Sprintf(
"/v1/xplat/fke/vpc/%s/m-fke/%s/get-shoot-specific/shoots/%s",
vpcId, platform, clusterId,
)
},
GetFKEOSVersion: func(vpcId string, platform string) string {
return fmt.Sprintf("/v1/xplat/fke/vpc/%s/m-fke/%s/get_k8s_versions", vpcId, platform)
},
}
24 changes: 12 additions & 12 deletions commons/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,12 @@ func NewClientWithURL(apiKey, apiUrl, region string, tenantName string) (*Client
return client, nil
}

func (c *Client) prepareClientURL(requestURL string) *url.URL {
func (c *Client) PrepareClientURL(requestURL string) *url.URL {
u, _ := url.Parse(c.BaseURL.String() + requestURL)
return u
}

func (c *Client) sendRequest(req *http.Request) ([]byte, error) {
func (c *Client) SendRequest(req *http.Request) ([]byte, error) {
req.Header.Set("Accept", "application/json")
req.Header.Set("User-Agent", c.UserAgent)
req.Header.Set("Content-Type", "application/json")
Expand Down Expand Up @@ -122,18 +122,18 @@ func (c *Client) sendRequest(req *http.Request) ([]byte, error) {

// SendGetRequest sends a correctly authenticated get request to the API server
func (c *Client) SendGetRequest(requestURL string) ([]byte, error) {
u := c.prepareClientURL(requestURL)
u := c.PrepareClientURL(requestURL)
req, err := http.NewRequest("GET", u.String(), nil)
if err != nil {
return nil, err
}

return c.sendRequest(req)
return c.SendRequest(req)
}

// SendPostRequest sends a correctly authenticated post request to the API server
func (c *Client) SendPostRequest(requestURL string, params interface{}) ([]byte, error) {
u := c.prepareClientURL(requestURL)
u := c.PrepareClientURL(requestURL)

// we create a new buffer and encode everything to json to send it in the request
jsonValue, _ := json.Marshal(params)
Expand All @@ -142,12 +142,12 @@ func (c *Client) SendPostRequest(requestURL string, params interface{}) ([]byte,
if err != nil {
return nil, err
}
return c.sendRequest(req)
return c.SendRequest(req)
}

// SendPutRequest sends a correctly authenticated put request to the API server
func (c *Client) SendPutRequest(requestURL string, params interface{}) ([]byte, error) {
u := c.prepareClientURL(requestURL)
u := c.PrepareClientURL(requestURL)

// we create a new buffer and encode everything to json to send it in the request
jsonValue, _ := json.Marshal(params)
Expand All @@ -156,23 +156,23 @@ func (c *Client) SendPutRequest(requestURL string, params interface{}) ([]byte,
if err != nil {
return nil, err
}
return c.sendRequest(req)
return c.SendRequest(req)
}

// SendDeleteRequest sends a correctly authenticated delete request to the API server
func (c *Client) SendDeleteRequest(requestURL string) ([]byte, error) {
u := c.prepareClientURL(requestURL)
u := c.PrepareClientURL(requestURL)
req, err := http.NewRequest("DELETE", u.String(), nil)
if err != nil {
return nil, err
}

return c.sendRequest(req)
return c.SendRequest(req)
}

// SendDeleteRequestWithBody sends a correctly authenticated delete request to the API server
func (c *Client) SendDeleteRequestWithBody(requestURL string, params interface{}) ([]byte, error) {
u := c.prepareClientURL(requestURL)
u := c.PrepareClientURL(requestURL)

// we create a new buffer and encode everything to json to send it in the request
jsonValue, _ := json.Marshal(params)
Expand All @@ -182,7 +182,7 @@ func (c *Client) SendDeleteRequestWithBody(requestURL string, params interface{}
return nil, err
}

return c.sendRequest(req)
return c.SendRequest(req)
}

// SetUserAgent sets the user agent for the client
Expand Down
48 changes: 48 additions & 0 deletions docs/data-sources/dedicated_kubernetes_engine_v1.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "fptcloud_dedicated_kubernetes_engine_v1 Data Source - terraform-provider-fptcloud"
subcategory: ""
description: |-
Retrieves information about dedicated FKE clusters
---

# fptcloud_dedicated_kubernetes_engine_v1 (Data Source)

Retrieves information about dedicated FKE clusters



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

### Required

- `cluster_id` (String) Cluster ID, as shown on the dashboard, usually has a length of 8 characters
- `vpc_id` (String) VPC ID

### Read-Only

- `cluster_name` (String) Cluster name
- `edge_id` (String) Edge ID
- `id` (String) UUID of the cluster
- `ip_private_firewall` (String) IP private firewall
- `ip_public_firewall` (String) IP public firewall
- `k8s_version` (String) Kubernetes version
- `lb_size` (String) Load balancer size
- `master_count` (Number) Number of master node
- `master_disk_size` (Number) Master node disk capacity in GB
- `master_type` (String) ID of the flavor of master node
- `max_pod_per_node` (Number) Max pods per node
- `network_id` (String) Network UUID
- `network_node_prefix` (Number) Network node prefix
- `nfs_disk_size` (Number) NFS disk size
- `nfs_status` (String) NFS status
- `node_dns` (String) DNS server of nodes
- `pod_network` (String) Pod network in CIDR notation
- `region_id` (String) Region ID
- `scale_max` (Number) Maximum number of nodes for autoscaling
- `scale_min` (Number) Minimum number of nodes for autoscaling
- `service_network` (String) Service network in CIDR notation
- `storage_policy` (String) Storage policy
- `worker_disk_size` (Number) Worker node disk capacity in GB
- `worker_type` (String) ID of the flavor of worker node
26 changes: 26 additions & 0 deletions docs/data-sources/edge_gateway.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "fptcloud_edge_gateway Data Source - terraform-provider-fptcloud"
subcategory: ""
description: |-
Retrieves information about FPT Cloud edge gateway
---

# fptcloud_edge_gateway (Data Source)

Retrieves information about FPT Cloud edge gateway



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

### Required

- `name` (String) Name of the compute edge_gateway
- `vpc_id` (String) VPC id

### Read-Only

- `edge_gateway_id` (String) Edge gateway id
- `id` (String) Identifier of the edge_gateway
53 changes: 53 additions & 0 deletions docs/data-sources/managed_kubernetes_engine_v1.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "fptcloud_managed_kubernetes_engine_v1 Data Source - terraform-provider-fptcloud"
subcategory: ""
description: |-
Manage managed FKE clusters.
---

# fptcloud_managed_kubernetes_engine_v1 (Data Source)

Manage managed FKE clusters.



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

### Required

- `cluster_name` (String)
- `vpc_id` (String)

### Read-Only

- `id` (String) The ID of this resource.
- `k8s_max_pod` (Number)
- `k8s_version` (String)
- `load_balancer_type` (String)
- `network_node_prefix` (Number)
- `pod_network` (String)
- `pod_prefix` (String)
- `pools` (Block List) (see [below for nested schema](#nestedblock--pools))
- `purpose` (String)
- `range_ip_lb_end` (String)
- `range_ip_lb_start` (String)
- `service_network` (String)
- `service_prefix` (String)

<a id="nestedblock--pools"></a>
### Nested Schema for `pools`

Read-Only:

- `auto_scale` (Boolean)
- `is_enable_auto_repair` (Boolean)
- `name` (String)
- `network_id` (String)
- `network_name` (String)
- `scale_max` (Number)
- `scale_min` (Number)
- `storage_profile` (String)
- `worker_disk_size` (Number)
- `worker_type` (String)
1 change: 1 addition & 0 deletions docs/data-sources/subnet.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,5 +81,6 @@ Read-Only:
- `edge_gateway` (Map of String)
- `gateway` (String)
- `id` (String)
- `network_id` (String)
- `name` (String)
- `network_name` (String)
49 changes: 49 additions & 0 deletions docs/resources/database.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "fptcloud_database Resource - terraform-provider-fptcloud"
subcategory: ""
description: |-
Provides a Fpt database cluster which can be used to store data.
---

# fptcloud_database (Resource)

Provides a Fpt database cluster which can be used to store data.



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

### Required

- `admin_password` (String) The admin password of the database cluster.
- `cluster_name` (String) The name of the database cluster.
- `data_disk_size` (Number) The size of the data disk in each node of the database cluster.
- `database_name` (String) The name of the database in the database cluster.
- `domain_name` (String) The domain name of the database cluster.
- `edge_id` (String) The edge Id of the database cluster.
- `edition` (String) The edition of the database cluster.
- `flavor` (String) The flavor of the database cluster.
- `is_cluster` (String) The cluster status of the database cluster.
- `is_ops` (String) Whether the database is OpenStack or VMware
- `is_public` (String) Whether the database is public or not.
- `master_count` (Number) The number of master nodes in the database cluster.
- `network_id` (String) The network Id of the database cluster.
- `node_core` (Number) The number of cores in each node of the database cluster.
- `node_cpu` (Number) The number of CPUs in each node of the database cluster.
- `node_ram` (Number) The amount of RAM in each node of the database cluster.
- `number_of_node` (Number) The number of nodes in the database cluster.
- `storage_profile` (String) The storage profile of the database cluster.
- `type_config` (String) The type of configuration of the database cluster (short-config or custom-config).
- `type_db` (String) The type of database of the database cluster
- `vdc_name` (String) The VDC name of the database cluster.
- `version` (String) The version of the database cluster.
- `vhost_name` (String) The name of the RabbitMQ database.
- `vm_network` (String) The VM network of the database cluster.
- `vpc_id` (String) The VPC Id of the database cluster.
- `worker_count` (Number) The number of worker nodes in the database cluster.

### Read-Only

- `id` (String) The Id of the database cluster.
21 changes: 21 additions & 0 deletions docs/resources/database_status.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "fptcloud_database_status Resource - terraform-provider-fptcloud"
subcategory: ""
description: |-
Provides a Fpt database cluster status to temporarily stop or start a database.
---

# fptcloud_database_status (Resource)

Provides a Fpt database cluster status to temporarily stop or start a database.



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

### Required

- `id` (String) The Id of the database cluster.
- `status` (String) The status of the database cluster, must be 'running' or 'stopped'.
Loading

0 comments on commit 7249547

Please sign in to comment.