@@ -1138,13 +1138,13 @@ Sometimes you need access to a resource that refers to the resource you're addin
1138
1138
func GetEBSVolumeRegistryItem() *schema.RegistryItem {
1139
1139
return &schema.RegistryItem{
1140
1140
Name: "aws_ebs_volume",
1141
- RFunc: NewEBSSnapshot ,
1142
- // This only works if aws_ebs_snapshot has defined "volume_id" as a ReferenceAttribute
1141
+ RFunc: NewEBSVolume ,
1142
+ // This only works if aws_ebs_snapshot has defined "volume_id" as a ReferenceAttribute
1143
1143
ReferenceAttributes: []string{"aws_ebs_snapshot.volume_id"},
1144
1144
}
1145
1145
}
1146
1146
1147
- func NewEBSSnapshot (d *schema.ResourceData, u *schema.UsageData) *schema.Resource {
1147
+ func NewEBSVolume (d *schema.ResourceData, u *schema.UsageData) *schema.Resource {
1148
1148
snapshotReverseRefs := d.References("aws_ebs_snapshot.volume_id") // Get the reference
1149
1149
// ...
1150
1150
}
@@ -1155,38 +1155,38 @@ Sometimes you need access to a resource that refers to the resource you're addin
1155
1155
By default, references are matched using an AWS ARN or the id field (`d.Get("id")`). Sometimes cloud providers use name or another field for references. In this case you can provide a 'custom reference id function' that generates additional ids used to match references. In this example, a custom id is needed because `aws_appautoscaling_target.resource_id` contains a `table/<name>` string when referencing an `aws_dynamodb_table`.
1156
1156
1157
1157
` ` ` go
1158
- func getAppAutoscalingTargetRegistryItem() *schema.RegistryItem {
1159
- return &schema.RegistryItem{
1160
- Name: "aws_appautoscaling_target",
1161
- RFunc: NewAppAutoscalingTargetResource,
1162
- ReferenceAttributes: []string{"resource_id"},
1163
- }
1164
- }
1165
-
1166
- func NewAppAutoscalingTargetResource(d *schema.ResourceData, u *schema.UsageData) *schema.Resource {
1167
- ...
1168
- }
1158
+ func getAppAutoscalingTargetRegistryItem() *schema.RegistryItem {
1159
+ return &schema.RegistryItem{
1160
+ Name: "aws_appautoscaling_target",
1161
+ RFunc: NewAppAutoscalingTargetResource,
1162
+ ReferenceAttributes: []string{"resource_id"},
1163
+ }
1164
+ }
1165
+
1166
+ func NewAppAutoscalingTargetResource(d *schema.ResourceData, u *schema.UsageData) *schema.Resource {
1167
+ // ...
1168
+ }
1169
1169
` ` `
1170
1170
1171
1171
` ` ` go
1172
- func getDynamoDBTableRegistryItem() *schema.RegistryItem {
1173
- return &schema.RegistryItem{
1174
- Name: "aws_dynamodb_table",
1175
- RFunc: NewDynamoDBTableResource,
1176
- CustomRefIDFunc: func (d *schema.ResourceData) []string {
1177
- // returns an id that will match the custom format used by aws_appautoscaling_target.resource_id
1178
- name := d.Get("name").String()
1179
- if name != "" {
1180
- return []string{"table/" + name}
1181
- }
1182
- return nil
1183
- },
1184
- }
1185
- }
1186
-
1187
- func NewAppAutoscalingTargetResource(d *schema.ResourceData, u *schema.UsageData) *schema.Resource {
1188
- ...
1189
- }
1172
+ func getDynamoDBTableRegistryItem() *schema.RegistryItem {
1173
+ return &schema.RegistryItem{
1174
+ Name: "aws_dynamodb_table",
1175
+ RFunc: NewDynamoDBTableResource,
1176
+ CustomRefIDFunc: func (d *schema.ResourceData) []string {
1177
+ // returns an id that will match the custom format used by aws_appautoscaling_target.resource_id
1178
+ name := d.Get("name").String()
1179
+ if name != "" {
1180
+ return []string{"table/" + name}
1181
+ }
1182
+ return nil
1183
+ },
1184
+ }
1185
+ }
1186
+
1187
+ func NewAppAutoscalingTargetResource(d *schema.ResourceData, u *schema.UsageData) *schema.Resource {
1188
+ // ...
1189
+ }
1190
1190
` ` `
1191
1191
1192
1192
# ## Google zone mappings
@@ -1219,7 +1219,7 @@ Unless the resource has global or zone-based pricing, the first line of the reso
1219
1219
1220
1220
func NewAzureRMAppServiceCertificateBinding(d *schema.ResourceData, u *schema.UsageData) *schema.Resource {
1221
1221
region := lookupRegion(d, []string{"certificate_id", "resource_group_name"})
1222
- ...
1222
+ // ...
1223
1223
}
1224
1224
` ` `
1225
1225
@@ -1244,8 +1244,8 @@ These can simply be embedded into a struct field like so:
1244
1244
1245
1245
` ` ` go
1246
1246
type MyResource struct {
1247
- ...
1248
- MonthlyDataProcessedGB *RegionsUsage ` infracost_usage:"monthly_processed_gb"`
1247
+ // ...
1248
+ MonthlyDataProcessedGB *RegionsUsage ` infracost_usage:"monthly_processed_gb"`
1249
1249
}
1250
1250
```
1251
1251
@@ -1262,12 +1262,13 @@ running:
1262
1262
1263
1263
` ` ` go
1264
1264
func (r *MyResource) BuildResource() *schema.Resource {
1265
- values := r.MonthlyDataProcessedGB.Values()
1265
+ values := r.MonthlyDataProcessedGB.Values()
1266
1266
1267
- for _, v := range values {
1268
- fmt.Println("%s => %2.f", v.Key, v.Value)
1269
- }
1270
- ...
1267
+ for _, v := range values {
1268
+ fmt.Println("%s => %2.f", v.Key, v.Value)
1269
+ }
1270
+
1271
+ // ...
1271
1272
}
1272
1273
```
1273
1274
@@ -1289,54 +1290,54 @@ Common usage structs are defined in the [`internal/resources/aws/util.go`](../in
1289
1290
1290
1291
``` go
1291
1292
var RegionMapping = map [string ]string {
1292
- " us-gov-west-1" : " AWS GovCloud (US-West)" ,
1293
- // Add the new region here with the aws code mapping to the region name
1294
- // as defined here: https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/using-regions-availability-zones.html
1293
+ " us-gov-west-1" : " AWS GovCloud (US-West)" ,
1294
+ // Add the new region here with the aws code mapping to the region name
1295
+ // as defined here: https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/using-regions-availability-zones.html
1295
1296
}
1296
1297
```
1297
1298
1298
1299
``` go
1299
1300
type RegionsUsage struct {
1300
- USGovWest1 *float64 ` infracost_usage:"us_gov_west_1"`
1301
- // Add your new region here with the infracost_usage struct tag
1302
- // representing an underscored version of the aws region code
1303
- // e.g: eu-west-1 => eu_west_1.
1304
- //
1305
- // The struct field type must be *float
1301
+ USGovWest1 *float64 ` infracost_usage:"us_gov_west_1"`
1302
+ // Add your new region here with the infracost_usage struct tag
1303
+ // representing an underscored version of the aws region code
1304
+ // e.g: eu-west-1 => eu_west_1.
1305
+ //
1306
+ // The struct field type must be *float
1306
1307
}
1307
1308
```
1308
1309
1309
1310
``` go
1310
1311
var RegionUsageSchema = []*schema.UsageItem {
1311
- {Key: " us_gov_west_1" , DefaultValue: 0 , ValueType: schema.Float64 },
1312
- // Finally, add your new region to the usage schema.
1313
- // Set the Key as the underscored code of the region (as outlined
1314
- // in the prior RegionsUsage struct). Then set DefaultValue as 0
1315
- // and the ValueType to schema.Float64.
1312
+ {Key: " us_gov_west_1" , DefaultValue: 0 , ValueType: schema.Float64 },
1313
+ // Finally, add your new region to the usage schema.
1314
+ // Set the Key as the underscored code of the region (as outlined
1315
+ // in the prior RegionsUsage struct). Then set DefaultValue as 0
1316
+ // and the ValueType to schema.Float64.
1316
1317
}
1317
1318
```
1319
+
1318
1320
#### Google
1319
1321
1320
1322
Common usage structs are defined in the [ ` internal/resources/google/util.go ` ] ( ../internal/resources/google/util.go ) file. You'll need to update:
1321
1323
1322
-
1323
1324
``` go
1324
1325
type RegionsUsage struct {
1325
- AsiaEast1 *float64 ` infracost_usage:"asia_east1"`
1326
- // Add your new region here with the infracost_usage struct tag
1327
- // representing an underscored version of the google location code
1328
- // e.g: eu-west-1 => eu_west_1.
1329
- //
1330
- // The struct field type must be *float
1326
+ AsiaEast1 *float64 ` infracost_usage:"asia_east1"`
1327
+ // Add your new region here with the infracost_usage struct tag
1328
+ // representing an underscored version of the google location code
1329
+ // e.g: eu-west-1 => eu_west_1.
1330
+ //
1331
+ // The struct field type must be *float
1331
1332
}
1332
1333
```
1333
1334
1334
1335
``` go
1335
1336
var RegionUsageSchema = []*schema.UsageItem {
1336
- {ValueType: schema.Float64 , DefaultValue: 0 , Key: " asia_east1" },
1337
- // Finally, add your new region to the usage schema.
1338
- // Set the Key as the underscored code of the location (as outlined
1339
- // in the prior RegionsUsage struct). Then set DefaultValue as 0
1340
- // and the ValueType to schema.Float64.
1337
+ {ValueType: schema.Float64 , DefaultValue: 0 , Key: " asia_east1" },
1338
+ // Finally, add your new region to the usage schema.
1339
+ // Set the Key as the underscored code of the location (as outlined
1340
+ // in the prior RegionsUsage struct). Then set DefaultValue as 0
1341
+ // and the ValueType to schema.Float64.
1341
1342
}
1342
- ```
1343
+ ```
0 commit comments