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

feat: Added lightsail static ips #1248

Merged
merged 4 commits into from
Jul 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions client/mocks/mock_lightsail.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions client/services.go
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,7 @@ type LightsailClient interface {
GetDiskSnapshots(ctx context.Context, params *lightsail.GetDiskSnapshotsInput, optFns ...func(*lightsail.Options)) (*lightsail.GetDiskSnapshotsOutput, error)
GetAlarms(ctx context.Context, params *lightsail.GetAlarmsInput, optFns ...func(*lightsail.Options)) (*lightsail.GetAlarmsOutput, error)
GetCertificates(ctx context.Context, params *lightsail.GetCertificatesInput, optFns ...func(*lightsail.Options)) (*lightsail.GetCertificatesOutput, error)
GetStaticIps(ctx context.Context, params *lightsail.GetStaticIpsInput, optFns ...func(*lightsail.Options)) (*lightsail.GetStaticIpsOutput, error)
}

//go:generate mockgen -package=mocks -destination=./mocks/mock_mq.go . MQClient
Expand Down
17 changes: 17 additions & 0 deletions docs/tables/aws_lightsail_static_ips.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@

# Table: aws_lightsail_static_ips
Describes a static IP
## Columns
| Name | Type | Description |
| ------------- | ------------- | ----- |
|account_id|text|The AWS Account ID of the resource.|
|region|text|The AWS Region of the resource.|
|arn|text|The Amazon Resource Name (ARN) of the static IP (eg, arn:aws:lightsail:us-east-2:123456789101:StaticIp/9cbb4a9e-f8e3-4dfe-b57e-12345EXAMPLE)|
|attached_to|text|The instance where the static IP is attached (eg, Amazon_Linux-1GB-Ohio-1)|
|created_at|timestamp without time zone|The timestamp when the static IP was created (eg, 1479735304222)|
|ip_address|text|The static IP address|
|is_attached|boolean|A Boolean value indicating whether the static IP is attached|
|availability_zone|text|The Availability Zone|
|name|text|The name of the static IP (eg, StaticIP-Ohio-EXAMPLE)|
|resource_type|text|The resource type (usually StaticIp)|
|support_code|text|The support code|
1 change: 1 addition & 0 deletions resources/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ func Provider() *provider.Provider {
"lightsail.certificates": lightsail.Certificates(),
"lightsail.disks": lightsail.Disks(),
"lightsail.instances": lightsail.Instances(),
"lightsail.static_ips": lightsail.StaticIps(),
"mq.brokers": mq.Brokers(),
"organizations.accounts": organizations.Accounts(),
"qldb.ledgers": qldb.Ledgers(),
Expand Down
43 changes: 42 additions & 1 deletion resources/services/lightsail/gen.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -275,4 +275,45 @@ resource "aws" "lightsail" "certificates" {
skip_prefix = true
}
}
}
}

resource "aws" "lightsail" "static_ips" {
path = "github.com/aws/aws-sdk-go-v2/service/lightsail/types.StaticIp"
ignoreError "IgnoreAccessDenied" {
path = "github.com/cloudquery/cq-provider-aws/client.IgnoreAccessDeniedServiceDisabled"
}
multiplex "AwsAccountRegion" {
path = "github.com/cloudquery/cq-provider-aws/client.ServiceAccountRegionMultiplexer"
params = ["lightsail"]
}
deleteFilter "AccountRegionFilter" {
path = "github.com/cloudquery/cq-provider-aws/client.DeleteAccountRegionFilter"
}
options {
primary_keys = [
"arn"
]
}
userDefinedColumn "account_id" {
type = "string"
description = "The AWS Account ID of the resource."
resolver "resolveAWSAccount" {
path = "github.com/cloudquery/cq-provider-aws/client.ResolveAWSAccount"
}
}
userDefinedColumn "region" {
type = "string"
description = "The AWS Region of the resource."
resolver "resolveAWSRegion" {
path = "github.com/cloudquery/cq-provider-aws/client.ResolveAWSRegion"
}
}

column "location" {
skip_prefix = true
}

column "region_name" {
skip = true
}
}
108 changes: 108 additions & 0 deletions resources/services/lightsail/static_ips.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
package lightsail

import (
"context"

"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/service/lightsail"
"github.com/cloudquery/cq-provider-aws/client"
"github.com/cloudquery/cq-provider-sdk/provider/diag"
"github.com/cloudquery/cq-provider-sdk/provider/schema"
)

//go:generate cq-gen --resource static_ips --config gen.hcl --output .
func StaticIps() *schema.Table {
return &schema.Table{
Name: "aws_lightsail_static_ips",
Description: "Describes a static IP",
Resolver: fetchLightsailStaticIps,
Multiplex: client.ServiceAccountRegionMultiplexer("lightsail"),
IgnoreError: client.IgnoreAccessDeniedServiceDisabled,
DeleteFilter: client.DeleteAccountRegionFilter,
Options: schema.TableCreationOptions{PrimaryKeys: []string{"arn"}},
Columns: []schema.Column{
{
Name: "account_id",
Description: "The AWS Account ID of the resource.",
Type: schema.TypeString,
Resolver: client.ResolveAWSAccount,
},
{
Name: "region",
Description: "The AWS Region of the resource.",
Type: schema.TypeString,
Resolver: client.ResolveAWSRegion,
},
{
Name: "arn",
Description: "The Amazon Resource Name (ARN) of the static IP (eg, arn:aws:lightsail:us-east-2:123456789101:StaticIp/9cbb4a9e-f8e3-4dfe-b57e-12345EXAMPLE)",
Type: schema.TypeString,
},
{
Name: "attached_to",
Description: "The instance where the static IP is attached (eg, Amazon_Linux-1GB-Ohio-1)",
Type: schema.TypeString,
},
{
Name: "created_at",
Description: "The timestamp when the static IP was created (eg, 1479735304222)",
Type: schema.TypeTimestamp,
},
{
Name: "ip_address",
Description: "The static IP address",
Type: schema.TypeString,
},
{
Name: "is_attached",
Description: "A Boolean value indicating whether the static IP is attached",
Type: schema.TypeBool,
},
{
Name: "availability_zone",
Description: "The Availability Zone",
Type: schema.TypeString,
Resolver: schema.PathResolver("Location.AvailabilityZone"),
},
{
Name: "name",
Description: "The name of the static IP (eg, StaticIP-Ohio-EXAMPLE)",
Type: schema.TypeString,
},
{
Name: "resource_type",
Description: "The resource type (usually StaticIp)",
Type: schema.TypeString,
},
{
Name: "support_code",
Description: "The support code",
Type: schema.TypeString,
},
},
}
}

// ====================================================================================================================
// Table Resolver Functions
// ====================================================================================================================

func fetchLightsailStaticIps(ctx context.Context, meta schema.ClientMeta, parent *schema.Resource, res chan<- interface{}) error {
var input lightsail.GetStaticIpsInput
c := meta.(*client.Client)
svc := c.Services().Lightsail
for {
response, err := svc.GetStaticIps(ctx, &input, func(options *lightsail.Options) {
options.Region = c.Region
})
if err != nil {
return diag.WrapError(err)
}
res <- response.StaticIps
if aws.ToString(response.NextPageToken) == "" {
break
}
input.PageToken = response.NextPageToken
}
return nil
}
29 changes: 29 additions & 0 deletions resources/services/lightsail/static_ips_mock_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package lightsail

import (
"testing"

"github.com/aws/aws-sdk-go-v2/service/lightsail"
"github.com/cloudquery/cq-provider-aws/client"
"github.com/cloudquery/cq-provider-aws/client/mocks"
"github.com/cloudquery/faker/v3"
"github.com/golang/mock/gomock"
)

func buildStaticIps(t *testing.T, ctrl *gomock.Controller) client.Services {
mock := mocks.NewMockLightsailClient(ctrl)

var ips lightsail.GetStaticIpsOutput
if err := faker.FakeData(&ips); err != nil {
t.Fatal(err)
}
ips.NextPageToken = nil

mock.EXPECT().GetStaticIps(gomock.Any(), &lightsail.GetStaticIpsInput{}, gomock.Any()).Return(&ips, nil)

return client.Services{Lightsail: mock}
}

func TestStaticIps(t *testing.T) {
client.AwsMockTestHelper(t, StaticIps(), buildStaticIps, client.TestOptions{})
}