internal/awscloud: fix cloud-init userdata for secure instance
The conditional only checked if the cloudwatch group was set, and if it wasn't, the hostname variable wouldn't be set either. So the executor would try to look for a hostname but not find any.
This commit is contained in:
parent
beebf3cec8
commit
791ec07bc2
2 changed files with 33 additions and 6 deletions
|
|
@ -22,12 +22,18 @@ type SecureInstance struct {
|
|||
func SecureInstanceUserData(cloudWatchGroup, hostname string) string {
|
||||
additionalFiles := ""
|
||||
|
||||
if cloudWatchGroup != "" {
|
||||
additionalFiles += fmt.Sprintf(` - path: /tmp/cloud_init_vars
|
||||
if cloudWatchGroup != "" || hostname != "" {
|
||||
additionalFiles += ` - path: /tmp/cloud_init_vars
|
||||
content: |
|
||||
OSBUILD_EXECUTOR_CLOUDWATCH_GROUP='%s'
|
||||
OSBUILD_EXECUTOR_HOSTNAME='%s'
|
||||
`, cloudWatchGroup, hostname)
|
||||
`
|
||||
}
|
||||
if cloudWatchGroup != "" {
|
||||
additionalFiles += fmt.Sprintf(` OSBUILD_EXECUTOR_CLOUDWATCH_GROUP='%s'
|
||||
`, cloudWatchGroup)
|
||||
}
|
||||
if hostname != "" {
|
||||
additionalFiles += fmt.Sprintf(` OSBUILD_EXECUTOR_HOSTNAME='%s'
|
||||
`, hostname)
|
||||
}
|
||||
|
||||
return fmt.Sprintf(`#cloud-config
|
||||
|
|
|
|||
|
|
@ -33,7 +33,28 @@ write_files:
|
|||
OSBUILD_EXECUTOR_HOSTNAME='test-hostname'
|
||||
`,
|
||||
},
|
||||
}
|
||||
{
|
||||
Hostname: "test-hostname",
|
||||
ExpectedUserData: `#cloud-config
|
||||
write_files:
|
||||
- path: /tmp/worker-run-executor-service
|
||||
content: ''
|
||||
- path: /tmp/cloud_init_vars
|
||||
content: |
|
||||
OSBUILD_EXECUTOR_HOSTNAME='test-hostname'
|
||||
`,
|
||||
},
|
||||
{
|
||||
CloudWatchGroup: "test-group",
|
||||
ExpectedUserData: `#cloud-config
|
||||
write_files:
|
||||
- path: /tmp/worker-run-executor-service
|
||||
content: ''
|
||||
- path: /tmp/cloud_init_vars
|
||||
content: |
|
||||
OSBUILD_EXECUTOR_CLOUDWATCH_GROUP='test-group'
|
||||
`,
|
||||
}}
|
||||
|
||||
for idx, tc := range testCases {
|
||||
t.Run(fmt.Sprintf("Test case %d", idx), func(t *testing.T) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue