MCPcopy Create free account
hub / github.com/coder/coder / TestInstanceIDAssociation

Function TestInstanceIDAssociation

provisioner/terraform/resources_test.go:1614–1684  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

1612}
1613
1614func TestInstanceIDAssociation(t *testing.T) {
1615 t.Parallel()
1616 type tc struct {
1617 Auth string
1618 ResourceType string
1619 InstanceIDKey string
1620 }
1621 for _, tc := range []tc{{
1622 Auth: "google-instance-identity",
1623 ResourceType: "google_compute_instance",
1624 InstanceIDKey: "instance_id",
1625 }, {
1626 Auth: "aws-instance-identity",
1627 ResourceType: "aws_instance",
1628 InstanceIDKey: "id",
1629 }, {
1630 Auth: "aws-instance-identity",
1631 ResourceType: "aws_spot_instance_request",
1632 InstanceIDKey: "spot_instance_id",
1633 }, {
1634 Auth: "azure-instance-identity",
1635 ResourceType: "azurerm_linux_virtual_machine",
1636 InstanceIDKey: "virtual_machine_id",
1637 }, {
1638 Auth: "azure-instance-identity",
1639 ResourceType: "azurerm_windows_virtual_machine",
1640 InstanceIDKey: "virtual_machine_id",
1641 }} {
1642 t.Run(tc.ResourceType, func(t *testing.T) {
1643 t.Parallel()
1644 ctx, logger := ctxAndLogger(t)
1645 instanceID, err := cryptorand.String(12)
1646 require.NoError(t, err)
1647 state, err := terraform.ConvertState(ctx, []*tfjson.StateModule{{
1648 Resources: []*tfjson.StateResource{{
1649 Address: "coder_agent.dev",
1650 Type: "coder_agent",
1651 Name: "dev",
1652 Mode: tfjson.ManagedResourceMode,
1653 AttributeValues: map[string]interface{}{
1654 "arch": "amd64",
1655 "auth": tc.Auth,
1656 },
1657 }, {
1658 Address: tc.ResourceType + ".dev",
1659 Type: tc.ResourceType,
1660 Name: "dev",
1661 Mode: tfjson.ManagedResourceMode,
1662 DependsOn: []string{"coder_agent.dev"},
1663 AttributeValues: map[string]interface{}{
1664 tc.InstanceIDKey: instanceID,
1665 },
1666 }},
1667 // This is manually created to join the edges.
1668 }}, `digraph {
1669 compound = "true"
1670 newrank = "true"
1671 subgraph "root" {

Callers

nothing calls this directly

Calls 7

StringFunction · 0.92
ConvertStateFunction · 0.92
ctxAndLoggerFunction · 0.85
RunMethod · 0.65
LenMethod · 0.45
EqualMethod · 0.45
GetInstanceIdMethod · 0.45

Tested by

no test coverage detected