Skip to content

Commit 3cb3b74

Browse files
committed
Fixup provisioner
1 parent a4bbb6e commit 3cb3b74

19 files changed

+365
-315
lines changed

provisioner/terraform/resources.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ type agentMetadata struct {
1818
Key string `mapstructure:"key"`
1919
DisplayName string `mapstructure:"display_name"`
2020
Cmd string `mapstructure:"cmd"`
21-
Interval string `mapstructure:"interval"`
21+
Interval int64 `mapstructure:"interval"`
2222
}
2323

2424
// A mapping of attributes on the "coder_agent" resource.
@@ -148,6 +148,16 @@ func ConvertState(modules []*tfjson.StateModule, rawGraph string) (*State, error
148148
loginBeforeReady = attrs.LoginBeforeReady
149149
}
150150

151+
var metadata []*proto.Agent_Metadata
152+
for _, item := range attrs.Metadata {
153+
metadata = append(metadata, &proto.Agent_Metadata{
154+
Key: item.Key,
155+
DisplayName: item.DisplayName,
156+
Cmd: item.Cmd,
157+
Interval: item.Interval,
158+
})
159+
}
160+
151161
agent := &proto.Agent{
152162
Name: tfResource.Name,
153163
Id: attrs.ID,
@@ -163,6 +173,7 @@ func ConvertState(modules []*tfjson.StateModule, rawGraph string) (*State, error
163173
StartupScriptTimeoutSeconds: attrs.StartupScriptTimeoutSeconds,
164174
ShutdownScript: attrs.ShutdownScript,
165175
ShutdownScriptTimeoutSeconds: attrs.ShutdownScriptTimeoutSeconds,
176+
Metadata: metadata,
166177
}
167178
switch attrs.Auth {
168179
case "token":

provisioner/terraform/resources_test.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,22 @@ func TestConvertResources(t *testing.T) {
220220
Value: "squirrel",
221221
Sensitive: true,
222222
}},
223+
Agents: []*proto.Agent{{
224+
Name: "main",
225+
Auth: &proto.Agent_Token{},
226+
OperatingSystem: "linux",
227+
Architecture: "amd64",
228+
Metadata: []*proto.Agent_Metadata{{
229+
Key: "process_count",
230+
DisplayName: "Process Count",
231+
Cmd: "ps -ef | wc -l",
232+
Interval: 1,
233+
}},
234+
ShutdownScriptTimeoutSeconds: 300,
235+
StartupScriptTimeoutSeconds: 300,
236+
LoginBeforeReady: true,
237+
ConnectionTimeoutSeconds: 120,
238+
}},
223239
}},
224240
},
225241
// Tests that resources with the same id correctly get metadata applied

provisioner/terraform/testdata/calling-module/calling-module.tfstate.json

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

provisioner/terraform/testdata/chaining-resources/chaining-resources.tfstate.json

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

provisioner/terraform/testdata/conflicting-resources/conflicting-resources.tfstate.json

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

provisioner/terraform/testdata/git-auth-providers/git-auth-providers.tfstate.json

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

provisioner/terraform/testdata/instance-id/instance-id.tfstate.json

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

provisioner/terraform/testdata/mapped-apps/mapped-apps.tfstate.json

Lines changed: 7 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

provisioner/terraform/testdata/multiple-agents/multiple-agents.tfstate.json

Lines changed: 7 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)