diff --git a/client/mocks/mock_lightsail.go b/client/mocks/mock_lightsail.go index 647106f62..3a9c00932 100644 --- a/client/mocks/mock_lightsail.go +++ b/client/mocks/mock_lightsail.go @@ -175,6 +175,46 @@ func (mr *MockLightsailClientMockRecorder) GetInstances(arg0, arg1 interface{}, return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetInstances", reflect.TypeOf((*MockLightsailClient)(nil).GetInstances), varargs...) } +// GetLoadBalancerTlsCertificates mocks base method. +func (m *MockLightsailClient) GetLoadBalancerTlsCertificates(arg0 context.Context, arg1 *lightsail.GetLoadBalancerTlsCertificatesInput, arg2 ...func(*lightsail.Options)) (*lightsail.GetLoadBalancerTlsCertificatesOutput, error) { + m.ctrl.T.Helper() + varargs := []interface{}{arg0, arg1} + for _, a := range arg2 { + varargs = append(varargs, a) + } + ret := m.ctrl.Call(m, "GetLoadBalancerTlsCertificates", varargs...) + ret0, _ := ret[0].(*lightsail.GetLoadBalancerTlsCertificatesOutput) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// GetLoadBalancerTlsCertificates indicates an expected call of GetLoadBalancerTlsCertificates. +func (mr *MockLightsailClientMockRecorder) GetLoadBalancerTlsCertificates(arg0, arg1 interface{}, arg2 ...interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + varargs := append([]interface{}{arg0, arg1}, arg2...) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetLoadBalancerTlsCertificates", reflect.TypeOf((*MockLightsailClient)(nil).GetLoadBalancerTlsCertificates), varargs...) +} + +// GetLoadBalancers mocks base method. +func (m *MockLightsailClient) GetLoadBalancers(arg0 context.Context, arg1 *lightsail.GetLoadBalancersInput, arg2 ...func(*lightsail.Options)) (*lightsail.GetLoadBalancersOutput, error) { + m.ctrl.T.Helper() + varargs := []interface{}{arg0, arg1} + for _, a := range arg2 { + varargs = append(varargs, a) + } + ret := m.ctrl.Call(m, "GetLoadBalancers", varargs...) + ret0, _ := ret[0].(*lightsail.GetLoadBalancersOutput) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// GetLoadBalancers indicates an expected call of GetLoadBalancers. +func (mr *MockLightsailClientMockRecorder) GetLoadBalancers(arg0, arg1 interface{}, arg2 ...interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + varargs := append([]interface{}{arg0, arg1}, arg2...) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetLoadBalancers", reflect.TypeOf((*MockLightsailClient)(nil).GetLoadBalancers), varargs...) +} + // GetRelationalDatabaseSnapshots mocks base method. func (m *MockLightsailClient) GetRelationalDatabaseSnapshots(arg0 context.Context, arg1 *lightsail.GetRelationalDatabaseSnapshotsInput, arg2 ...func(*lightsail.Options)) (*lightsail.GetRelationalDatabaseSnapshotsOutput, error) { m.ctrl.T.Helper() diff --git a/client/services.go b/client/services.go index ff4f658f3..ad13195e7 100644 --- a/client/services.go +++ b/client/services.go @@ -381,6 +381,8 @@ type LightsailClient interface { 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) GetRelationalDatabaseSnapshots(ctx context.Context, params *lightsail.GetRelationalDatabaseSnapshotsInput, optFns ...func(*lightsail.Options)) (*lightsail.GetRelationalDatabaseSnapshotsOutput, error) + GetLoadBalancers(ctx context.Context, params *lightsail.GetLoadBalancersInput, optFns ...func(*lightsail.Options)) (*lightsail.GetLoadBalancersOutput, error) + GetLoadBalancerTlsCertificates(ctx context.Context, params *lightsail.GetLoadBalancerTlsCertificatesInput, optFns ...func(*lightsail.Options)) (*lightsail.GetLoadBalancerTlsCertificatesOutput, error) } //go:generate mockgen -package=mocks -destination=./mocks/mock_mq.go . MQClient diff --git a/docs/tables/aws_lightsail_load_balancer_instance_health_summary.md b/docs/tables/aws_lightsail_load_balancer_instance_health_summary.md new file mode 100644 index 000000000..c52b2e041 --- /dev/null +++ b/docs/tables/aws_lightsail_load_balancer_instance_health_summary.md @@ -0,0 +1,10 @@ + +# Table: aws_lightsail_load_balancer_instance_health_summary +Describes information about the health of the instance +## Columns +| Name | Type | Description | +| ------------- | ------------- | ----- | +|load_balancer_cq_id|uuid|Unique CloudQuery ID of aws_lightsail_load_balancers table (FK)| +|instance_health|text|Describes the overall instance health| +|instance_health_reason|text|More information about the instance health| +|instance_name|text|The name of the Lightsail instance for which you are requesting health check data| diff --git a/docs/tables/aws_lightsail_load_balancer_tls_certificate_summaries.md b/docs/tables/aws_lightsail_load_balancer_tls_certificate_summaries.md new file mode 100644 index 000000000..70f0448ec --- /dev/null +++ b/docs/tables/aws_lightsail_load_balancer_tls_certificate_summaries.md @@ -0,0 +1,9 @@ + +# Table: aws_lightsail_load_balancer_tls_certificate_summaries +Provides a summary of SSL/TLS certificate metadata +## Columns +| Name | Type | Description | +| ------------- | ------------- | ----- | +|load_balancer_cq_id|uuid|Unique CloudQuery ID of aws_lightsail_load_balancers table (FK)| +|is_attached|boolean|When true, the SSL/TLS certificate is attached to the Lightsail load balancer| +|name|text|The name of the SSL/TLS certificate| diff --git a/docs/tables/aws_lightsail_load_balancer_tls_certificates.md b/docs/tables/aws_lightsail_load_balancer_tls_certificates.md new file mode 100644 index 000000000..761c4ec14 --- /dev/null +++ b/docs/tables/aws_lightsail_load_balancer_tls_certificates.md @@ -0,0 +1,34 @@ + +# Table: aws_lightsail_load_balancer_tls_certificates +Describes a load balancer SSL/TLS certificate +## Columns +| Name | Type | Description | +| ------------- | ------------- | ----- | +|load_balancer_cq_id|uuid|Unique CloudQuery ID of aws_lightsail_load_balancers table (FK)| +|arn|text|The Amazon Resource Name (ARN) of the SSL/TLS certificate| +|created_at|timestamp without time zone|The time when you created your SSL/TLS certificate| +|domain_name|text|The domain name for your SSL/TLS certificate| +|domain_validation_records|jsonb|An array of LoadBalancerTlsCertificateDomainValidationRecord objects describing the records| +|failure_reason|text|The validation failure reason, if any, of the certificate| +|is_attached|boolean|When true, the SSL/TLS certificate is attached to the Lightsail load balancer| +|issued_at|timestamp without time zone|The time when the SSL/TLS certificate was issued| +|issuer|text|The issuer of the certificate| +|key_algorithm|text|The algorithm used to generate the key pair (the public and private key)| +|load_balancer_name|text|The load balancer name where your SSL/TLS certificate is attached| +|availability_zone|text|The Availability Zone| +|region_name|text|The AWS Region name| +|name|text|The name of the SSL/TLS certificate (eg, my-certificate)| +|not_after|timestamp without time zone|The timestamp when the SSL/TLS certificate expires| +|not_before|timestamp without time zone|The timestamp when the SSL/TLS certificate is first valid| +|renewal_summary_domain_validation_options|jsonb|Contains information about the validation of each domain name in the certificate, as it pertains to Lightsail's managed renewal| +|renewal_summary_renewal_status|text|The renewal status of the certificate| +|resource_type|text|The resource type (eg, LoadBalancerTlsCertificate) * Instance - A Lightsail instance (a virtual private server) * StaticIp - A static IP address * KeyPair - The key pair used to connect to a Lightsail instance * InstanceSnapshot - A Lightsail instance snapshot * Domain - A DNS zone * PeeredVpc - A peered VPC * LoadBalancer - A Lightsail load balancer * LoadBalancerTlsCertificate - An SSL/TLS certificate associated with a Lightsail load balancer * Disk - A Lightsail block storage disk * DiskSnapshot - A block storage disk snapshot| +|revocation_reason|text|The reason the certificate was revoked| +|revoked_at|timestamp without time zone|The timestamp when the certificate was revoked| +|serial|text|The serial number of the certificate| +|signature_algorithm|text|The algorithm that was used to sign the certificate| +|status|text|The validation status of the SSL/TLS certificate| +|subject|text|The name of the entity that is associated with the public key contained in the certificate| +|subject_alternative_names|text[]|An array of strings that specify the alternate domains (eg, example2com) and subdomains (eg, blogexamplecom) for the certificate| +|support_code|text|The support code| +|tags|jsonb|The tag keys and optional values for the resource| diff --git a/docs/tables/aws_lightsail_load_balancers.md b/docs/tables/aws_lightsail_load_balancers.md new file mode 100644 index 000000000..9d668553e --- /dev/null +++ b/docs/tables/aws_lightsail_load_balancers.md @@ -0,0 +1,25 @@ + +# Table: aws_lightsail_load_balancers +Describes a load balancer +## 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 load balancer| +|configuration_options|jsonb|A string to string map of the configuration options for your load balancer Valid values are listed below| +|created_at|timestamp without time zone|The date when your load balancer was created| +|dns_name|text|The DNS name of your Lightsail load balancer| +|health_check_path|text|The path you specified to perform your health checks| +|https_redirection_enabled|boolean|A Boolean value that indicates whether HTTPS redirection is enabled for the load balancer| +|instance_port|integer|The port where the load balancer will direct traffic to your Lightsail instances| +|ip_address_type|text|The IP address type of the load balancer| +|availability_zone|text|The Availability Zone| +|name|text|The name of the load balancer (eg, my-load-balancer)| +|protocol|text|The protocol you have enabled for your load balancer| +|public_ports|integer[]|An array of public port settings for your load balancer| +|resource_type|text|Type of the lightsail resource| +|state|text|The status of your load balancer| +|support_code|text|The support code| +|tags|jsonb|The tag keys and optional values for the resource| +|tls_policy_name|text|The name of the TLS security policy for the load balancer| diff --git a/resources/provider/provider.go b/resources/provider/provider.go index e97ddf7d8..0126fec74 100644 --- a/resources/provider/provider.go +++ b/resources/provider/provider.go @@ -195,6 +195,7 @@ func Provider() *provider.Provider { "lightsail.database_snapshots": lightsail.DatabaseSnapshots(), "lightsail.disks": lightsail.Disks(), "lightsail.instances": lightsail.Instances(), + "lightsail.load_balancers": lightsail.LoadBalancers(), "lightsail.static_ips": lightsail.StaticIps(), "mq.brokers": mq.Brokers(), "organizations.accounts": organizations.Accounts(), diff --git a/resources/services/lightsail/gen.hcl b/resources/services/lightsail/gen.hcl index 5ed919055..c38a897e1 100644 --- a/resources/services/lightsail/gen.hcl +++ b/resources/services/lightsail/gen.hcl @@ -363,4 +363,80 @@ resource "aws" "lightsail" "database_snapshots" { column "region_name" { skip = true } +} + + +resource "aws" "lightsail" "load_balancers" { + path = "github.com/aws/aws-sdk-go-v2/service/lightsail/types.LoadBalancer" + 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 "tags" { + type = "json" + generate_resolver = true + } + + column "public_ports" { + generate_resolver = true + } + + column "location" { + skip_prefix = true + } + + column "region_name" { + skip = true + } + + column "resource_type"{ + description = "Type of the lightsail resource" + } + + user_relation "aws" "lightsail" "tls_certificates" { + path = "github.com/aws/aws-sdk-go-v2/service/lightsail/types.LoadBalancerTlsCertificate" + column "tags" { + type = "json" + generate_resolver = true + } + + column "renewal_summary_domain_validation_options" { + type = "json" + } + + column "location" { + skip_prefix = true + } + + + column "domain_validation_records" { + type = "json" + } + } } \ No newline at end of file diff --git a/resources/services/lightsail/load_balancers.go b/resources/services/lightsail/load_balancers.go new file mode 100644 index 000000000..86467ee6f --- /dev/null +++ b/resources/services/lightsail/load_balancers.go @@ -0,0 +1,408 @@ +package lightsail + +import ( + "context" + + "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/service/lightsail" + "github.com/aws/aws-sdk-go-v2/service/lightsail/types" + "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 load_balancers --config gen.hcl --output . +func LoadBalancers() *schema.Table { + return &schema.Table{ + Name: "aws_lightsail_load_balancers", + Description: "Describes a load balancer", + Resolver: fetchLightsailLoadBalancers, + 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 load balancer", + Type: schema.TypeString, + }, + { + Name: "configuration_options", + Description: "A string to string map of the configuration options for your load balancer Valid values are listed below", + Type: schema.TypeJSON, + }, + { + Name: "created_at", + Description: "The date when your load balancer was created", + Type: schema.TypeTimestamp, + }, + { + Name: "dns_name", + Description: "The DNS name of your Lightsail load balancer", + Type: schema.TypeString, + }, + { + Name: "health_check_path", + Description: "The path you specified to perform your health checks", + Type: schema.TypeString, + }, + { + Name: "https_redirection_enabled", + Description: "A Boolean value that indicates whether HTTPS redirection is enabled for the load balancer", + Type: schema.TypeBool, + }, + { + Name: "instance_port", + Description: "The port where the load balancer will direct traffic to your Lightsail instances", + Type: schema.TypeInt, + }, + { + Name: "ip_address_type", + Description: "The IP address type of the load balancer", + Type: schema.TypeString, + }, + { + Name: "availability_zone", + Description: "The Availability Zone", + Type: schema.TypeString, + Resolver: schema.PathResolver("Location.AvailabilityZone"), + }, + { + Name: "name", + Description: "The name of the load balancer (eg, my-load-balancer)", + Type: schema.TypeString, + }, + { + Name: "protocol", + Description: "The protocol you have enabled for your load balancer", + Type: schema.TypeString, + }, + { + Name: "public_ports", + Description: "An array of public port settings for your load balancer", + Type: schema.TypeIntArray, + Resolver: resolveLoadBalancersPublicPorts, + }, + { + Name: "resource_type", + Description: "Type of the lightsail resource", + Type: schema.TypeString, + }, + { + Name: "state", + Description: "The status of your load balancer", + Type: schema.TypeString, + }, + { + Name: "support_code", + Description: "The support code", + Type: schema.TypeString, + }, + { + Name: "tags", + Description: "The tag keys and optional values for the resource", + Type: schema.TypeJSON, + Resolver: resolveLoadBalancersTags, + }, + { + Name: "tls_policy_name", + Description: "The name of the TLS security policy for the load balancer", + Type: schema.TypeString, + }, + }, + Relations: []*schema.Table{ + { + Name: "aws_lightsail_load_balancer_instance_health_summary", + Description: "Describes information about the health of the instance", + Resolver: fetchLightsailLoadBalancerInstanceHealthSummaries, + Columns: []schema.Column{ + { + Name: "load_balancer_cq_id", + Description: "Unique CloudQuery ID of aws_lightsail_load_balancers table (FK)", + Type: schema.TypeUUID, + Resolver: schema.ParentIdResolver, + }, + { + Name: "instance_health", + Description: "Describes the overall instance health", + Type: schema.TypeString, + }, + { + Name: "instance_health_reason", + Description: "More information about the instance health", + Type: schema.TypeString, + }, + { + Name: "instance_name", + Description: "The name of the Lightsail instance for which you are requesting health check data", + Type: schema.TypeString, + }, + }, + }, + { + Name: "aws_lightsail_load_balancer_tls_certificate_summaries", + Description: "Provides a summary of SSL/TLS certificate metadata", + Resolver: fetchLightsailLoadBalancerTlsCertificateSummaries, + IgnoreInTests: true, + Columns: []schema.Column{ + { + Name: "load_balancer_cq_id", + Description: "Unique CloudQuery ID of aws_lightsail_load_balancers table (FK)", + Type: schema.TypeUUID, + Resolver: schema.ParentIdResolver, + }, + { + Name: "is_attached", + Description: "When true, the SSL/TLS certificate is attached to the Lightsail load balancer", + Type: schema.TypeBool, + }, + { + Name: "name", + Description: "The name of the SSL/TLS certificate", + Type: schema.TypeString, + }, + }, + }, + { + Name: "aws_lightsail_load_balancer_tls_certificates", + Description: "Describes a load balancer SSL/TLS certificate", + Resolver: fetchLightsailLoadBalancerTlsCertificates, + IgnoreInTests: true, + Columns: []schema.Column{ + { + Name: "load_balancer_cq_id", + Description: "Unique CloudQuery ID of aws_lightsail_load_balancers table (FK)", + Type: schema.TypeUUID, + Resolver: schema.ParentIdResolver, + }, + { + Name: "arn", + Description: "The Amazon Resource Name (ARN) of the SSL/TLS certificate", + Type: schema.TypeString, + }, + { + Name: "created_at", + Description: "The time when you created your SSL/TLS certificate", + Type: schema.TypeTimestamp, + }, + { + Name: "domain_name", + Description: "The domain name for your SSL/TLS certificate", + Type: schema.TypeString, + }, + { + Name: "domain_validation_records", + Description: "An array of LoadBalancerTlsCertificateDomainValidationRecord objects describing the records", + Type: schema.TypeJSON, + }, + { + Name: "failure_reason", + Description: "The validation failure reason, if any, of the certificate", + Type: schema.TypeString, + }, + { + Name: "is_attached", + Description: "When true, the SSL/TLS certificate is attached to the Lightsail load balancer", + Type: schema.TypeBool, + }, + { + Name: "issued_at", + Description: "The time when the SSL/TLS certificate was issued", + Type: schema.TypeTimestamp, + }, + { + Name: "issuer", + Description: "The issuer of the certificate", + Type: schema.TypeString, + }, + { + Name: "key_algorithm", + Description: "The algorithm used to generate the key pair (the public and private key)", + Type: schema.TypeString, + }, + { + Name: "load_balancer_name", + Description: "The load balancer name where your SSL/TLS certificate is attached", + Type: schema.TypeString, + }, + { + Name: "availability_zone", + Description: "The Availability Zone", + Type: schema.TypeString, + Resolver: schema.PathResolver("Location.AvailabilityZone"), + }, + { + Name: "region_name", + Description: "The AWS Region name", + Type: schema.TypeString, + Resolver: schema.PathResolver("Location.RegionName"), + }, + { + Name: "name", + Description: "The name of the SSL/TLS certificate (eg, my-certificate)", + Type: schema.TypeString, + }, + { + Name: "not_after", + Description: "The timestamp when the SSL/TLS certificate expires", + Type: schema.TypeTimestamp, + }, + { + Name: "not_before", + Description: "The timestamp when the SSL/TLS certificate is first valid", + Type: schema.TypeTimestamp, + }, + { + Name: "renewal_summary_domain_validation_options", + Description: "Contains information about the validation of each domain name in the certificate, as it pertains to Lightsail's managed renewal", + Type: schema.TypeJSON, + Resolver: schema.PathResolver("RenewalSummary.DomainValidationOptions"), + }, + { + Name: "renewal_summary_renewal_status", + Description: "The renewal status of the certificate", + Type: schema.TypeString, + Resolver: schema.PathResolver("RenewalSummary.RenewalStatus"), + }, + { + Name: "resource_type", + Description: "The resource type (eg, LoadBalancerTlsCertificate) * Instance - A Lightsail instance (a virtual private server) * StaticIp - A static IP address * KeyPair - The key pair used to connect to a Lightsail instance * InstanceSnapshot - A Lightsail instance snapshot * Domain - A DNS zone * PeeredVpc - A peered VPC * LoadBalancer - A Lightsail load balancer * LoadBalancerTlsCertificate - An SSL/TLS certificate associated with a Lightsail load balancer * Disk - A Lightsail block storage disk * DiskSnapshot - A block storage disk snapshot", + Type: schema.TypeString, + }, + { + Name: "revocation_reason", + Description: "The reason the certificate was revoked", + Type: schema.TypeString, + }, + { + Name: "revoked_at", + Description: "The timestamp when the certificate was revoked", + Type: schema.TypeTimestamp, + }, + { + Name: "serial", + Description: "The serial number of the certificate", + Type: schema.TypeString, + }, + { + Name: "signature_algorithm", + Description: "The algorithm that was used to sign the certificate", + Type: schema.TypeString, + }, + { + Name: "status", + Description: "The validation status of the SSL/TLS certificate", + Type: schema.TypeString, + }, + { + Name: "subject", + Description: "The name of the entity that is associated with the public key contained in the certificate", + Type: schema.TypeString, + }, + { + Name: "subject_alternative_names", + Description: "An array of strings that specify the alternate domains (eg, example2com) and subdomains (eg, blogexamplecom) for the certificate", + Type: schema.TypeStringArray, + }, + { + Name: "support_code", + Description: "The support code", + Type: schema.TypeString, + }, + { + Name: "tags", + Description: "The tag keys and optional values for the resource", + Type: schema.TypeJSON, + Resolver: resolveLoadBalancerTLSCertificatesTags, + }, + }, + }, + }, + } +} + +// ==================================================================================================================== +// Table Resolver Functions +// ==================================================================================================================== + +func fetchLightsailLoadBalancers(ctx context.Context, meta schema.ClientMeta, parent *schema.Resource, res chan<- interface{}) error { + var input lightsail.GetLoadBalancersInput + c := meta.(*client.Client) + svc := c.Services().Lightsail + for { + response, err := svc.GetLoadBalancers(ctx, &input, func(options *lightsail.Options) { + options.Region = c.Region + }) + if err != nil { + return diag.WrapError(err) + } + res <- response.LoadBalancers + if aws.ToString(response.NextPageToken) == "" { + break + } + input.PageToken = response.NextPageToken + } + return nil +} +func resolveLoadBalancersPublicPorts(ctx context.Context, meta schema.ClientMeta, resource *schema.Resource, c schema.Column) error { + r := resource.Item.(types.LoadBalancer) + ports := make([]int, 0, len(r.PublicPorts)) + for _, p := range r.PublicPorts { + ports = append(ports, int(p)) + } + return diag.WrapError(resource.Set(c.Name, ports)) +} +func resolveLoadBalancersTags(ctx context.Context, meta schema.ClientMeta, resource *schema.Resource, c schema.Column) error { + r := resource.Item.(types.LoadBalancer) + tags := make(map[string]string) + client.TagsIntoMap(r.Tags, tags) + return diag.WrapError(resource.Set(c.Name, tags)) +} +func fetchLightsailLoadBalancerInstanceHealthSummaries(ctx context.Context, meta schema.ClientMeta, parent *schema.Resource, res chan<- interface{}) error { + r := parent.Item.(types.LoadBalancer) + res <- r.InstanceHealthSummary + return nil +} +func fetchLightsailLoadBalancerTlsCertificateSummaries(ctx context.Context, meta schema.ClientMeta, parent *schema.Resource, res chan<- interface{}) error { + r := parent.Item.(types.LoadBalancer) + res <- r.TlsCertificateSummaries + return nil +} +func fetchLightsailLoadBalancerTlsCertificates(ctx context.Context, meta schema.ClientMeta, parent *schema.Resource, res chan<- interface{}) error { + r := parent.Item.(types.LoadBalancer) + input := lightsail.GetLoadBalancerTlsCertificatesInput{ + LoadBalancerName: r.Name, + } + c := meta.(*client.Client) + svc := c.Services().Lightsail + response, err := svc.GetLoadBalancerTlsCertificates(ctx, &input, func(options *lightsail.Options) { + options.Region = c.Region + }) + if err != nil { + if c.IsNotFoundError(err) { + return nil + } + return diag.WrapError(err) + } + res <- response.TlsCertificates + return nil +} +func resolveLoadBalancerTLSCertificatesTags(ctx context.Context, meta schema.ClientMeta, resource *schema.Resource, c schema.Column) error { + r := resource.Item.(types.LoadBalancerTlsCertificate) + tags := make(map[string]string) + client.TagsIntoMap(r.Tags, tags) + return diag.WrapError(resource.Set(c.Name, tags)) +} diff --git a/resources/services/lightsail/load_balancers_mock_test.go b/resources/services/lightsail/load_balancers_mock_test.go new file mode 100644 index 000000000..978914588 --- /dev/null +++ b/resources/services/lightsail/load_balancers_mock_test.go @@ -0,0 +1,44 @@ +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 buildLoadBalancers(t *testing.T, ctrl *gomock.Controller) client.Services { + mock := mocks.NewMockLightsailClient(ctrl) + + var lb lightsail.GetLoadBalancersOutput + if err := faker.FakeData(&lb); err != nil { + t.Fatal(err) + } + lb.NextPageToken = nil + + mock.EXPECT().GetLoadBalancers( + gomock.Any(), + &lightsail.GetLoadBalancersInput{}, + gomock.Any(), + ).Return(&lb, nil) + + var lbc lightsail.GetLoadBalancerTlsCertificatesOutput + if err := faker.FakeData(&lbc); err != nil { + t.Fatal(err) + } + + mock.EXPECT().GetLoadBalancerTlsCertificates( + gomock.Any(), + gomock.Any(), + gomock.Any(), + ).Return(&lbc, nil) + + return client.Services{Lightsail: mock} +} + +func TestLoadBalancers(t *testing.T) { + client.AwsMockTestHelper(t, LoadBalancers(), buildLoadBalancers, client.TestOptions{}) +}