Skip to content

Commit 3995f7d

Browse files
dylanratcliffeactions-user
authored andcommitted
Track terraform type for mappings (#795)
This will allow us to more easily figure out resources we should prioritise GitOrigin-RevId: b42d0e02e277eeb7e1474a1d32b6d0e0aa0239f6
1 parent 5e452b9 commit 3995f7d

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

tfutils/plan_mapper.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,12 @@ const (
4646
const KnownAfterApply = `(known after apply)`
4747

4848
type PlannedChangeMapResult struct {
49-
// The name of the resource in the Terraform plan
49+
// The full name of the resource in the Terraform plan
5050
TerraformName string
5151

52+
// The terraform resource type
53+
TerraformType string
54+
5255
// The status of the mapping
5356
Status MapStatus
5457

@@ -200,6 +203,7 @@ func MappedItemDiffsFromPlan(ctx context.Context, planJson []byte, fileName stri
200203
log.WithContext(ctx).WithFields(lf).WithField("terraform-address", resourceChange.Address).Debug("Skipping unmapped resource")
201204
results.Results = append(results.Results, PlannedChangeMapResult{
202205
TerraformName: resourceChange.Address,
206+
TerraformType: resourceChange.Type,
203207
Status: MapStatusUnsupported,
204208
Message: "unsupported",
205209
MappedItemDiff: &sdp.MappedItemDiff{
@@ -243,6 +247,7 @@ func MappedItemDiffsFromPlan(ctx context.Context, planJson []byte, fileName stri
243247
attribute.String("ovm.climap.status", result.Status.String()),
244248
attribute.String("ovm.climap.message", result.Message),
245249
attribute.String("ovm.climap.terraform-name", result.TerraformName),
250+
attribute.String("ovm.climap.terraform-type", result.TerraformType),
246251
))
247252
case MapStatusSuccess:
248253
// Don't include these
@@ -263,6 +268,7 @@ func mapResourceToQuery(itemDiff *sdp.ItemDiff, terraformResource *Resource, map
263268
if len(mappings) == 0 {
264269
return PlannedChangeMapResult{
265270
TerraformName: terraformResource.Address,
271+
TerraformType: terraformResource.Type,
266272
Status: MapStatusUnsupported,
267273
Message: "unsupported",
268274
MappedItemDiff: &sdp.MappedItemDiff{
@@ -300,6 +306,7 @@ func mapResourceToQuery(itemDiff *sdp.ItemDiff, terraformResource *Resource, map
300306

301307
return PlannedChangeMapResult{
302308
TerraformName: terraformResource.Address,
309+
TerraformType: terraformResource.Type,
303310
Status: MapStatusSuccess,
304311
Message: "mapped",
305312
MappedItemDiff: &sdp.MappedItemDiff{
@@ -317,6 +324,7 @@ func mapResourceToQuery(itemDiff *sdp.ItemDiff, terraformResource *Resource, map
317324
// If we get to this point, we haven't found a mapping
318325
return PlannedChangeMapResult{
319326
TerraformName: terraformResource.Address,
327+
TerraformType: terraformResource.Type,
320328
Status: MapStatusNotEnoughInfo,
321329
Message: fmt.Sprintf("missing mapping attribute: %v", strings.Join(attemptedMappings, ", ")),
322330
MappedItemDiff: &sdp.MappedItemDiff{

0 commit comments

Comments
 (0)