feat: Extract instance type when provisioning VMs (#4839)

This should help us identify what instances our users consume.
This commit is contained in:
Kyle Carberry
2022-11-01 14:51:57 -07:00
committed by GitHub
parent 26a920a740
commit a672ae8c7d
12 changed files with 260 additions and 152 deletions

View File

@ -382,12 +382,13 @@ func ConvertResources(module *tfjson.StateModule, rawGraph string) ([]*proto.Res
}
resources = append(resources, &proto.Resource{
Name: resource.Name,
Type: resource.Type,
Agents: agents,
Hide: resourceHidden[label],
Icon: resourceIcon[label],
Metadata: resourceMetadata[label],
Name: resource.Name,
Type: resource.Type,
Agents: agents,
Hide: resourceHidden[label],
Icon: resourceIcon[label],
Metadata: resourceMetadata[label],
InstanceType: applyInstanceType(resource),
})
}
@ -405,6 +406,31 @@ type graphResource struct {
Depth uint
}
// applyInstanceType sets the instance type on an agent if it matches
// one of the special resource types that we track.
func applyInstanceType(resource *tfjson.StateResource) string {
key, isValid := map[string]string{
"google_compute_instance": "machine_type",
"aws_instance": "instance_type",
"aws_spot_instance_request": "instance_type",
"azurerm_linux_virtual_machine": "size",
"azurerm_windows_virtual_machine": "size",
}[resource.Type]
if !isValid {
return ""
}
instanceTypeRaw, isValid := resource.AttributeValues[key]
if !isValid {
return ""
}
instanceType, isValid := instanceTypeRaw.(string)
if !isValid {
return ""
}
return instanceType
}
// applyAutomaticInstanceID checks if the resource is one of a set of *magical* IDs
// that automatically index their identifier for automatic authentication.
func applyAutomaticInstanceID(resource *tfjson.StateResource, agents []*proto.Agent) {