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

@ -287,6 +287,58 @@ func TestAppSlugValidation(t *testing.T) {
require.ErrorContains(t, err, "duplicate app slug")
}
func TestInstanceTypeAssociation(t *testing.T) {
t.Parallel()
type tc struct {
ResourceType string
InstanceTypeKey string
}
for _, tc := range []tc{{
ResourceType: "google_compute_instance",
InstanceTypeKey: "machine_type",
}, {
ResourceType: "aws_instance",
InstanceTypeKey: "instance_type",
}, {
ResourceType: "aws_spot_instance_request",
InstanceTypeKey: "instance_type",
}, {
ResourceType: "azurerm_linux_virtual_machine",
InstanceTypeKey: "size",
}, {
ResourceType: "azurerm_windows_virtual_machine",
InstanceTypeKey: "size",
}} {
tc := tc
t.Run(tc.ResourceType, func(t *testing.T) {
t.Parallel()
instanceType, err := cryptorand.String(12)
require.NoError(t, err)
resources, err := terraform.ConvertResources(&tfjson.StateModule{
Resources: []*tfjson.StateResource{{
Address: tc.ResourceType + ".dev",
Type: tc.ResourceType,
Name: "dev",
Mode: tfjson.ManagedResourceMode,
AttributeValues: map[string]interface{}{
tc.InstanceTypeKey: instanceType,
},
}},
// This is manually created to join the edges.
}, `digraph {
compound = "true"
newrank = "true"
subgraph "root" {
"[root] `+tc.ResourceType+`.dev" [label = "`+tc.ResourceType+`.dev", shape = "box"]
}
}`)
require.NoError(t, err)
require.Len(t, resources, 1)
require.Equal(t, resources[0].GetInstanceType(), instanceType)
})
}
}
func TestInstanceIDAssociation(t *testing.T) {
t.Parallel()
type tc struct {