-
Notifications
You must be signed in to change notification settings - Fork 523
/
glue_crawler.go
75 lines (66 loc) 路 2.38 KB
/
glue_crawler.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package aws
import (
"github.com/shopspring/decimal"
"github.com/infracost/infracost/internal/resources"
"github.com/infracost/infracost/internal/schema"
)
// GlueCrawler struct represents a serverless AWS Glue crawler. A Glue crawler crawls defined data sources and sends them
// into a Glue data catalog, ready for a Glue job to transform and merge into a main dataset/lake.
//
// GlueCrawler is just one resource of the wider AWS Glue service, which provides a number of different serverless services
// to build a robust data analytics pipeline.
//
// Resource information: https://aws.amazon.com/glue/
// Pricing information: https://aws.amazon.com/glue/pricing/
type GlueCrawler struct {
Address string
Region string
MonthlyHours *float64 `infracost_usage:"monthly_hours"`
}
func (r *GlueCrawler) CoreType() string {
return "GlueCrawler"
}
func (r *GlueCrawler) UsageSchema() []*schema.UsageItem {
return []*schema.UsageItem{
{Key: "monthly_hours", DefaultValue: 0, ValueType: schema.Float64},
}
}
// PopulateUsage parses the u schema.UsageData into the GlueCrawler.
// It uses the `infracost_usage` struct tags to populate data into the GlueCrawler.
func (r *GlueCrawler) PopulateUsage(u *schema.UsageData) {
resources.PopulateArgsWithUsage(r, u)
}
// BuildResource builds a schema.Resource from a valid GlueCrawler struct. GlueCrawler has just one schema.CostComponent
// associated with it:
//
// 1. Hours - GlueCrawler is charged per hour that the crawler is run.
//
// This method is called after the resource is initialised by an IaC provider. See providers folder for more information.
func (r *GlueCrawler) BuildResource() *schema.Resource {
var quantity *decimal.Decimal
if r.MonthlyHours != nil {
quantity = decimalPtr(decimal.NewFromFloat(*r.MonthlyHours))
}
return &schema.Resource{
Name: r.Address,
UsageSchema: r.UsageSchema(),
CostComponents: []*schema.CostComponent{
{
Name: "Duration",
Unit: "hours",
UnitMultiplier: decimal.NewFromInt(1),
MonthlyQuantity: quantity,
ProductFilter: &schema.ProductFilter{
VendorName: vendorName,
Region: strPtr(r.Region),
Service: strPtr("AWSGlue"),
ProductFamily: strPtr("AWS Glue"),
AttributeFilters: []*schema.AttributeFilter{
{Key: "operation", ValueRegex: strPtr("/^crawlerrun$/i")},
},
},
UsageBased: true,
},
},
}
}