Skip to content

Commit

Permalink
Implement VPC CRUD (#140)
Browse files Browse the repository at this point in the history
* Implement VPC shell import
Create global scenario test file
  • Loading branch information
Khyme authored Jan 17, 2024
1 parent 385c66a commit 990316f
Show file tree
Hide file tree
Showing 21 changed files with 1,109 additions and 140 deletions.
35 changes: 35 additions & 0 deletions docs/resources/vpcs.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "timescale_vpcs Resource - terraform-provider-timescale"
subcategory: ""
description: |-
---

# timescale_vpcs (Resource)





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

### Required

- `cidr` (String) The IPv4 CIDR block
- `region_code` (String) The region for this service. Currently supported regions are us-east-1, eu-west-1, us-west-2, eu-central-1, ap-southeast-2

### Optional

- `name` (String) VPC Name is the configurable name assigned to this vpc. If none is provided, a default will be generated by the provider.

### Read-Only

- `created` (String)
- `error_message` (String)
- `id` (Number) The ID of this resource.
- `project_id` (String)
- `provisioned_id` (String)
- `status` (String)
- `updated` (String)
27 changes: 27 additions & 0 deletions examples/resources/timescale_vpcs/vpcs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
terraform {
required_providers {
timescale = {
source = "registry.terraform.io/providers/timescale"
version = "~> 1.0"
}
}
}

variable "ts_access_token" {
type = string
}

variable "ts_project_id" {
type = string
}

provider "timescale" {
access_token = var.ts_access_token
project_id = var.ts_project_id
}

resource "timescale_vpcs" "new_vpc" {
name = "test-vpc"
cidr = "10.0.0.0/19"
region_code = "us-east-1"
}
20 changes: 16 additions & 4 deletions internal/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,30 @@ var (
GetAllServicesQuery string
//go:embed queries/get_service.graphql
GetServiceQuery string
//go:embed queries/vpcs.graphql
GetVPCsQuery string
//go:embed queries/products.graphql
ProductsQuery string
//go:embed queries/jwt_cc.graphql
JWTFromCCQuery string
//go:embed queries/set_replica_count.graphql
SetReplicaCountMutation string

// VCPs ///////////////////////////////
//go:embed queries/vpcs.graphql
GetVPCsQuery string
//go:embed queries/vpc_by_name.graphql
GetVPCByNameQuery string
//go:embed queries/vpc_by_id.graphql
GetVPCByIDQuery string
//go:embed queries/attach_service_to_vpc.graphql
AttachServiceToVPCMutation string
//go:embed queries/detach_service_from_vpc.graphql
DetachServiceFromVPCMutation string
//go:embed queries/set_replica_count.graphql
SetReplicaCountMutation string
//go:embed queries/create_vpc.graphql
CreateVPCMutation string
//go:embed queries/delete_vpc.graphql
DeleteVPCMutation string
//go:embed queries/rename_vpc.graphql
RenameVPCMutation string
)

type Client struct {
Expand Down
2 changes: 1 addition & 1 deletion internal/client/queries/attach_service_to_vpc.graphql
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
mutation AttachServiceToVpc($projectId: ID!, $serviceId: ID!, $vpcId: ID!) {
mutation AttachServiceToVPC($projectId: ID!, $serviceId: ID!, $vpcId: ID!) {
attachServiceToVpc (data:{
serviceId: $serviceId,
projectId: $projectId,
Expand Down
31 changes: 31 additions & 0 deletions internal/client/queries/create_vpc.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
mutation CreateVPC($projectId: ID!, $name: String!, $cidr: String!, $regionCode: String!) {
createVpc(data:{
projectId:$projectId,
name:$name,
cidr:$cidr,
cloudProvider: AWS,
regionCode:$regionCode
}){
id
projectId
cidr
name
created
updated
# peeringConnections {
# id
# vpcId
# peerVpc {
# id
# accountId
# regionCode
# cidr
# }
# errorMessage
# status
# }
errorMessage
status
regionCode
}
}
6 changes: 6 additions & 0 deletions internal/client/queries/delete_vpc.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
mutation DeleteVPC($projectId: ID!, $vpcId: ID!) {
deleteVpc (data:{
vpcId: $vpcId,
projectId: $projectId
})
}
2 changes: 1 addition & 1 deletion internal/client/queries/detach_service_from_vpc.graphql
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
mutation DetachServiceFromVpc($projectId: ID!, $serviceId: ID!, $vpcId: ID!) {
mutation DetachServiceFromVPC($projectId: ID!, $serviceId: ID!, $vpcId: ID!) {
detachServiceFromVpc (data:{
serviceId: $serviceId,
projectId: $projectId,
Expand Down
7 changes: 7 additions & 0 deletions internal/client/queries/rename_vpc.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
mutation RenameVPC($projectId: ID!, $forgeVpcId: ID!, $newName: String!) {
renameVpc (data:{
projectId: $projectId,
forgeVpcId: $forgeVpcId,
newName: $newName
})
}
25 changes: 25 additions & 0 deletions internal/client/queries/vpc_by_id.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
query GetVPC($vpcId: ID!) {
getVpc(vpcId: $vpcId) {
id
projectId
cidr
name
created
updated
# peeringConnections {
# id
# vpcId
# peerVpc {
# id
# accountId
# regionCode
# cidr
# }
# errorMessage
# status
# }
errorMessage
status
regionCode
}
}
28 changes: 28 additions & 0 deletions internal/client/queries/vpc_by_name.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
query GetVPCByName($projectId: ID!, $name: String!) {
getVpcByName (data:{
projectId: $projectId
vpcName: $name,
}) {
id
projectId
cidr
name
created
updated
# peeringConnections {
# id
# vpcId
# peerVpc {
# id
# accountId
# regionCode
# cidr
# }
# errorMessage
# status
# }
errorMessage
status
regionCode
}
}
6 changes: 3 additions & 3 deletions internal/client/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ type Service struct {
Resources []ResourceSpec `json:"resources"`
Created string `json:"created"`
ReplicaStatus string `json:"replicaStatus"`
VpcEndpoint *VpcEndpoint `json:"vpcEndpoint"`
VPCEndpoint *VPCEndpoint `json:"vpcEndpoint"`
ForkSpec *ForkSpec `json:"forkedFromId"`
}

Expand All @@ -33,10 +33,10 @@ type ServiceSpec struct {
Port int64 `json:"port"`
}

type VpcEndpoint struct {
type VPCEndpoint struct {
Host string `json:"host"`
Port int64 `json:"port"`
VpcId string `json:"vpcId"`
VPCId string `json:"vpcId"`
}

type ResourceSpec struct {
Expand Down
Loading

0 comments on commit 990316f

Please sign in to comment.