Skip to content

Commit 036a91a

Browse files
committed
docs: Update formatting of Add new resource guide
1 parent dba1adb commit 036a91a

File tree

1 file changed

+68
-67
lines changed

1 file changed

+68
-67
lines changed

contributing/add_new_resource_guide.md

Lines changed: 68 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -1138,13 +1138,13 @@ Sometimes you need access to a resource that refers to the resource you're addin
11381138
func GetEBSVolumeRegistryItem() *schema.RegistryItem {
11391139
return &schema.RegistryItem{
11401140
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
11431143
ReferenceAttributes: []string{"aws_ebs_snapshot.volume_id"},
11441144
}
11451145
}
11461146
1147-
func NewEBSSnapshot(d *schema.ResourceData, u *schema.UsageData) *schema.Resource {
1147+
func NewEBSVolume(d *schema.ResourceData, u *schema.UsageData) *schema.Resource {
11481148
snapshotReverseRefs := d.References("aws_ebs_snapshot.volume_id") // Get the reference
11491149
// ...
11501150
}
@@ -1155,38 +1155,38 @@ Sometimes you need access to a resource that refers to the resource you're addin
11551155
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`.
11561156

11571157
```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+
}
11691169
```
11701170

11711171
```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+
}
11901190
```
11911191

11921192
### Google zone mappings
@@ -1219,7 +1219,7 @@ Unless the resource has global or zone-based pricing, the first line of the reso
12191219
12201220
func NewAzureRMAppServiceCertificateBinding(d *schema.ResourceData, u *schema.UsageData) *schema.Resource {
12211221
region := lookupRegion(d, []string{"certificate_id", "resource_group_name"})
1222-
...
1222+
// ...
12231223
}
12241224
```
12251225

@@ -1244,8 +1244,8 @@ These can simply be embedded into a struct field like so:
12441244

12451245
```go
12461246
type MyResource struct {
1247-
...
1248-
MonthlyDataProcessedGB *RegionsUsage `infracost_usage:"monthly_processed_gb"`
1247+
// ...
1248+
MonthlyDataProcessedGB *RegionsUsage `infracost_usage:"monthly_processed_gb"`
12491249
}
12501250
```
12511251

@@ -1262,12 +1262,13 @@ running:
12621262
12631263
```go
12641264
func (r *MyResource) BuildResource() *schema.Resource {
1265-
values := r.MonthlyDataProcessedGB.Values()
1265+
values := r.MonthlyDataProcessedGB.Values()
12661266

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+
// ...
12711272
}
12721273
```
12731274

@@ -1289,54 +1290,54 @@ Common usage structs are defined in the [`internal/resources/aws/util.go`](../in
12891290

12901291
```go
12911292
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
12951296
}
12961297
```
12971298

12981299
```go
12991300
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
13061307
}
13071308
```
13081309

13091310
```go
13101311
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.
13161317
}
13171318
```
1319+
13181320
#### Google
13191321

13201322
Common usage structs are defined in the [`internal/resources/google/util.go`](../internal/resources/google/util.go) file. You'll need to update:
13211323

1322-
13231324
```go
13241325
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
13311332
}
13321333
```
13331334

13341335
```go
13351336
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.
13411342
}
1342-
```
1343+
```

0 commit comments

Comments
 (0)