From 391244d0b4b62b2cb0ebe70723ca4d0b6f41dbae Mon Sep 17 00:00:00 2001 From: Kim Date: Fri, 15 Mar 2024 17:21:55 +0100 Subject: [PATCH] Expose ProvisionedID from VPC and PeeringConnection (#174) These are required to peer VPC through AWS provider --- docs/resources/peering_connection.md | 1 + internal/client/queries/create_vpc.graphql | 2 ++ internal/client/queries/vpc_by_id.graphql | 2 ++ internal/client/queries/vpc_by_name.graphql | 2 ++ internal/client/queries/vpcs.graphql | 2 ++ internal/client/vpc.go | 11 ++++++----- internal/provider/peering_conn_resource.go | 10 ++++++++++ internal/provider/vpc_resource.go | 2 ++ internal/provider/vpc_resource_test.go | 2 +- 9 files changed, 28 insertions(+), 6 deletions(-) diff --git a/docs/resources/peering_connection.md b/docs/resources/peering_connection.md index 9f1d0ce..a33cab3 100644 --- a/docs/resources/peering_connection.md +++ b/docs/resources/peering_connection.md @@ -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 diff --git a/internal/client/queries/create_vpc.graphql b/internal/client/queries/create_vpc.graphql index 0a85839..996bc8d 100644 --- a/internal/client/queries/create_vpc.graphql +++ b/internal/client/queries/create_vpc.graphql @@ -7,6 +7,7 @@ mutation CreateVPC($projectId: ID!, $name: String!, $cidr: String!, $regionCode: regionCode:$regionCode }){ id + provisionedId projectId cidr name @@ -15,6 +16,7 @@ mutation CreateVPC($projectId: ID!, $name: String!, $cidr: String!, $regionCode: peeringConnections { id vpcId + provisionedId peerVpc { id accountId diff --git a/internal/client/queries/vpc_by_id.graphql b/internal/client/queries/vpc_by_id.graphql index c6ae8b7..1463310 100644 --- a/internal/client/queries/vpc_by_id.graphql +++ b/internal/client/queries/vpc_by_id.graphql @@ -1,6 +1,7 @@ query GetVPCByID($vpcId: ID!) { getVpc(vpcId: $vpcId) { id + provisionedId projectId cidr name @@ -9,6 +10,7 @@ peeringConnections { id vpcId + provisionedId peerVpc { id accountId diff --git a/internal/client/queries/vpc_by_name.graphql b/internal/client/queries/vpc_by_name.graphql index a3cf38f..afbbb17 100644 --- a/internal/client/queries/vpc_by_name.graphql +++ b/internal/client/queries/vpc_by_name.graphql @@ -4,6 +4,7 @@ query GetVPCByName($projectId: ID!, $name: String!) { vpcName: $name, }) { id + provisionedId projectId cidr name @@ -12,6 +13,7 @@ query GetVPCByName($projectId: ID!, $name: String!) { peeringConnections { id vpcId + provisionedId peerVpc { id accountId diff --git a/internal/client/queries/vpcs.graphql b/internal/client/queries/vpcs.graphql index 5981e14..4669fb7 100644 --- a/internal/client/queries/vpcs.graphql +++ b/internal/client/queries/vpcs.graphql @@ -1,6 +1,7 @@ query GetAllVPCs($projectId: ID!) { getAllVpcs(projectId: $projectId) { id + provisionedId projectId cidr name @@ -9,6 +10,7 @@ peeringConnections { id vpcId + provisionedId peerVpc { id accountId diff --git a/internal/client/vpc.go b/internal/client/vpc.go index 74f85cd..0ddfe92 100644 --- a/internal/client/vpc.go +++ b/internal/client/vpc.go @@ -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 { diff --git a/internal/provider/peering_conn_resource.go b/internal/provider/peering_conn_resource.go index c26dff2..f0d78b0 100644 --- a/internal/provider/peering_conn_resource.go +++ b/internal/provider/peering_conn_resource.go @@ -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"` @@ -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, @@ -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 @@ -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, diff --git a/internal/provider/vpc_resource.go b/internal/provider/vpc_resource.go index 507618c..39842d7 100644 --- a/internal/provider/vpc_resource.go +++ b/internal/provider/vpc_resource.go @@ -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) @@ -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) diff --git a/internal/provider/vpc_resource_test.go b/internal/provider/vpc_resource_test.go index 26042dd..620504e 100644 --- a/internal/provider/vpc_resource_test.go +++ b/internal/provider/vpc_resource_test.go @@ -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")) + `