Skip to content

Commit

Permalink
Expose ProvisionedID from VPC and PeeringConnection (#174)
Browse files Browse the repository at this point in the history
These are required to peer VPC through AWS provider
  • Loading branch information
Khyme authored Mar 15, 2024
1 parent 8e13f12 commit 391244d
Show file tree
Hide file tree
Showing 9 changed files with 28 additions and 6 deletions.
1 change: 1 addition & 0 deletions docs/resources/peering_connection.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,6 @@ Schema for a peering connection. Import can be done with timescale_vpc_id,peer_a
- `error_message` (String)
- `id` (Number) Timescale internal ID for a peering connection
- `peer_cidr` (String) CIDR for the VPC to be paired
- `provisioned_id` (String) AWS ID of the peering connection (starts with pcx-...)
- `status` (String) Peering connection status
- `vpc_id` (String) AWS VPC ID of the timescale instance VPC
2 changes: 2 additions & 0 deletions internal/client/queries/create_vpc.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ mutation CreateVPC($projectId: ID!, $name: String!, $cidr: String!, $regionCode:
regionCode:$regionCode
}){
id
provisionedId
projectId
cidr
name
Expand All @@ -15,6 +16,7 @@ mutation CreateVPC($projectId: ID!, $name: String!, $cidr: String!, $regionCode:
peeringConnections {
id
vpcId
provisionedId
peerVpc {
id
accountId
Expand Down
2 changes: 2 additions & 0 deletions internal/client/queries/vpc_by_id.graphql
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
query GetVPCByID($vpcId: ID!) {
getVpc(vpcId: $vpcId) {
id
provisionedId
projectId
cidr
name
Expand All @@ -9,6 +10,7 @@
peeringConnections {
id
vpcId
provisionedId
peerVpc {
id
accountId
Expand Down
2 changes: 2 additions & 0 deletions internal/client/queries/vpc_by_name.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ query GetVPCByName($projectId: ID!, $name: String!) {
vpcName: $name,
}) {
id
provisionedId
projectId
cidr
name
Expand All @@ -12,6 +13,7 @@ query GetVPCByName($projectId: ID!, $name: String!) {
peeringConnections {
id
vpcId
provisionedId
peerVpc {
id
accountId
Expand Down
2 changes: 2 additions & 0 deletions internal/client/queries/vpcs.graphql
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
query GetAllVPCs($projectId: ID!) {
getAllVpcs(projectId: $projectId) {
id
provisionedId
projectId
cidr
name
Expand All @@ -9,6 +10,7 @@
peeringConnections {
id
vpcId
provisionedId
peerVpc {
id
accountId
Expand Down
11 changes: 6 additions & 5 deletions internal/client/vpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,12 @@ type VPC struct {
}

type PeeringConnection struct {
ID string `json:"id"`
VPCID string `json:"vpcId"`
Status string `json:"status"`
ErrorMessage string `json:"errorMessage"`
PeerVPC *PeerVPC `json:"peerVPC"`
ID string `json:"id"`
VPCID string `json:"vpcId"`
ProvisionedID string `json:"provisionedId"`
Status string `json:"status"`
ErrorMessage string `json:"errorMessage"`
PeerVPC *PeerVPC `json:"peerVPC"`
}

type PeerVPC struct {
Expand Down
10 changes: 10 additions & 0 deletions internal/provider/peering_conn_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ type peeringConnectionResource struct {
type peeringConnectionResourceModel struct {
ID types.Int64 `tfsdk:"id"`
VpcID types.String `tfsdk:"vpc_id"`
ProvisionedID types.String `tfsdk:"provisioned_id"`
Status types.String `tfsdk:"status"`
ErrorMessage types.String `tfsdk:"error_message"`
PeerVPCID types.String `tfsdk:"peer_vpc_id"`
Expand All @@ -58,6 +59,7 @@ var (
PeeringConnectionType = map[string]attr.Type{
"id": types.Int64Type,
"vpc_id": types.StringType,
"provisioned_id": types.StringType,
"status": types.StringType,
"error_message": types.StringType,
"peer_vpc_id": types.StringType,
Expand Down Expand Up @@ -125,6 +127,7 @@ func (r *peeringConnectionResource) Read(ctx context.Context, req resource.ReadR
}
pcm.ID = types.Int64Value(peeringConnID)
pcm.VpcID = types.StringValue(pc.VPCID)
pcm.ProvisionedID = types.StringValue(pc.ProvisionedID)
pcm.Status = types.StringValue(pc.Status)
pcm.PeerAccountID = state.PeerAccountID
pcm.PeerRegionCode = state.PeerRegionCode
Expand Down Expand Up @@ -276,6 +279,13 @@ func (r *peeringConnectionResource) Schema(_ context.Context, _ resource.SchemaR
stringplanmodifier.UseStateForUnknown(),
},
},
"provisioned_id": schema.StringAttribute{
Description: "AWS ID of the peering connection (starts with pcx-...)",
Computed: true,
PlanModifiers: []planmodifier.String{
stringplanmodifier.UseStateForUnknown(),
},
},
"status": schema.StringAttribute{
Description: "Peering connection status",
Computed: true,
Expand Down
2 changes: 2 additions & 0 deletions internal/provider/vpc_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ func (r *vpcResource) Read(ctx context.Context, req resource.ReadRequest, resp *
state.ID = types.Int64Value(vpcID)
state.Created = types.StringValue(vpc.Created)
state.ProjectID = types.StringValue(vpc.ProjectID)
state.ProvisionedID = types.StringValue(vpc.ProvisionedID)
state.CIDR = types.StringValue(vpc.CIDR)
state.RegionCode = types.StringValue(vpc.RegionCode)

Expand Down Expand Up @@ -144,6 +145,7 @@ func (r *vpcResource) Create(ctx context.Context, req resource.CreateRequest, re
plan.ID = types.Int64Value(vpcID)
plan.Created = types.StringValue(vpc.Created)
plan.ProjectID = types.StringValue(vpc.ProjectID)
plan.ProvisionedID = types.StringValue(vpc.ProvisionedID)
plan.CIDR = types.StringValue(vpc.CIDR)
plan.RegionCode = types.StringValue(vpc.RegionCode)
model := vpcToResource(vpc, plan)
Expand Down
2 changes: 1 addition & 1 deletion internal/provider/vpc_resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func TestVPCResource_Import(t *testing.T) {
{
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"created", "status"},
ImportStateVerifyIgnore: []string{"created", "status", "provisioned_id"},
ImportStateId: "import-test",
ResourceName: "timescale_vpcs.resource_import",
Config: getVPCConfig(t, config.WithName("import-test").WithCIDR("10.0.0.0/21").WithRegionCode("us-east-1")) + `
Expand Down

0 comments on commit 391244d

Please sign in to comment.