Skip to content
This repository has been archived by the owner on Aug 16, 2022. It is now read-only.

Commit

Permalink
feat: Add partition info to regions (#898)
Browse files Browse the repository at this point in the history
  • Loading branch information
irmatov authored May 17, 2022
1 parent 3a77950 commit 76d4587
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 1 deletion.
1 change: 1 addition & 0 deletions docs/tables/aws_regions.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ Describes a Region.
|endpoint|text|The Region service endpoint.|
|opt_in_status|text|The Region opt-in status|
|region|text|The name of the Region.|
|partition|text|AWS partition|
2 changes: 2 additions & 0 deletions resources/provider/migrations/postgres/32_v0.11.7.down.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-- Resource: aws.regions
ALTER TABLE IF EXISTS "aws_regions" DROP COLUMN IF EXISTS "partition";
2 changes: 2 additions & 0 deletions resources/provider/migrations/postgres/32_v0.11.7.up.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-- Resource: aws.regions
ALTER TABLE IF EXISTS "aws_regions" ADD COLUMN IF NOT EXISTS "partition" text;
2 changes: 2 additions & 0 deletions resources/provider/migrations/timescale/32_v0.11.7.down.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-- Resource: aws.regions
ALTER TABLE IF EXISTS "aws_regions" DROP COLUMN IF EXISTS "partition";
2 changes: 2 additions & 0 deletions resources/provider/migrations/timescale/32_v0.11.7.up.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-- Resource: aws.regions
ALTER TABLE IF EXISTS "aws_regions" ADD COLUMN IF NOT EXISTS "partition" text;
11 changes: 10 additions & 1 deletion resources/services/ec2/regions.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,12 @@ func AwsRegions() *schema.Table {
Type: schema.TypeString,
Resolver: schema.PathResolver("RegionName"),
},
{
Name: "partition",
Description: "AWS partition",
Type: schema.TypeString,
Resolver: resolveRegionPartition,
},
},
}
}
Expand All @@ -68,7 +74,6 @@ func fetchRegions(ctx context.Context, meta schema.ClientMeta, parent *schema.Re
return nil
}
func resolveRegionEnabled(ctx context.Context, meta schema.ClientMeta, resource *schema.Resource, c schema.Column) error {

region := resource.Item.(types.Region)
switch *region.OptInStatus {
case "opt-in-not-required", "opted-in":
Expand All @@ -78,3 +83,7 @@ func resolveRegionEnabled(ctx context.Context, meta schema.ClientMeta, resource
}
return nil
}
func resolveRegionPartition(ctx context.Context, meta schema.ClientMeta, resource *schema.Resource, c schema.Column) error {
cl := meta.(*client.Client)
return diag.WrapError(resource.Set(c.Name, cl.Partition))
}
1 change: 1 addition & 0 deletions resources/services/ec2/regions_mock_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ func buildRegionsMock(t *testing.T, ctrl *gomock.Controller) client.Services {
t.Fatal(err)
}
r.OptInStatus = aws.String("opted-in")
r.RegionName = aws.String("us-east-1")
m.EXPECT().DescribeRegions(gomock.Any(), gomock.Any(), gomock.Any()).Return(
&ec2.DescribeRegionsOutput{
Regions: []ec2Types.Region{r},
Expand Down

0 comments on commit 76d4587

Please sign in to comment.