Skip to content

Commit d3678a9

Browse files
committed
Fixed incorrect default worker pool lookup
1 parent a427b17 commit d3678a9

File tree

2 files changed

+15
-8
lines changed

2 files changed

+15
-8
lines changed

cmd/internal/converters/worker_pool_converter.go

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -288,19 +288,16 @@ func (c WorkerPoolConverter) toHcl(pool octopus.WorkerPool, _ bool, lookup bool,
288288

289289
// Fallback is used when the default worker pool, usually called "Hosted Ubuntu" or "Hosted Windows", is not found.
290290
// An empty string falls back to the default worker pool.
291-
fallback := ""
291+
// Note this string is used inside an interpolation, which is why it is wrapped in quotes.
292+
fallback := "\"\""
292293

293294
if forceLookup {
294295
c.createDynamicWorkerPoolLookupResource(resourceName,
295-
"workerpool_"+sanitizer.SanitizeName(fallback),
296+
fallback,
296297
&thisResource,
297298
pool,
298299
stateless)
299300

300-
dependencies.AddResource(*c.createStandAloneLookupResource(
301-
"workerpool_"+sanitizer.SanitizeName(fallback),
302-
fallback))
303-
304301
} else {
305302
if c.GenerateImportScripts && !stateless {
306303
c.toBashImport(octopusdeployDynamicWorkerPoolResourceType, resourceName, pool.Name, dependencies)
@@ -431,6 +428,12 @@ func (c WorkerPoolConverter) createStaticWorkerPoolResource(resourceName string,
431428
// to an on-premise instance, or vice versa.
432429
func (c WorkerPoolConverter) createStandAloneLookupResource(resourceName string, resourceDisplayName string) *data.ResourceDetails {
433430

431+
// Resource names might be empty - a default worker pool is just an empty string.
432+
// There is no need to create a data source for it.
433+
if resourceDisplayName == "" {
434+
return nil
435+
}
436+
434437
thisResource := data.ResourceDetails{}
435438
thisResource.FileName = "space_population/" + resourceName + ".tf"
436439
thisResource.Name = resourceDisplayName
@@ -476,13 +479,13 @@ func (c WorkerPoolConverter) createStaticWorkerPoolLookupResource(resourceName s
476479
}
477480
}
478481

479-
func (c WorkerPoolConverter) createDynamicWorkerPoolLookupResource(resourceName string, fallbackResourceName string, thisResource *data.ResourceDetails, pool octopus.WorkerPool, stateless bool) {
482+
func (c WorkerPoolConverter) createDynamicWorkerPoolLookupResource(resourceName string, fallbackDataLookup string, thisResource *data.ResourceDetails, pool octopus.WorkerPool, stateless bool) {
480483
if stateless {
481484
// Stateless modules try to use the dynamic worker pool first, and if that fails, use the static worker pool
482485
// This allows a module created on a cloud instance to be used in an on-premise instance.
483486
thisResource.Lookup = "${length(data." + octopusdeployWorkerPoolsDataType + "." + resourceName + ".worker_pools) != 0 " +
484487
"? data." + octopusdeployWorkerPoolsDataType + "." + resourceName + ".worker_pools[0].id " +
485-
": data." + octopusdeployWorkerPoolsDataType + "." + fallbackResourceName + ".worker_pools[0].id}"
488+
": " + fallbackDataLookup + "}"
486489
} else {
487490
thisResource.Lookup = "${data." + octopusdeployWorkerPoolsDataType + "." + resourceName + ".worker_pools[0].id}"
488491
}

cmd/internal/data/export_map.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,10 @@ func (c *ResourceDetailsCollection) AddResource(resources ...ResourceDetails) {
129129
c.Resources = []ResourceDetails{}
130130
}
131131

132+
if resources == nil {
133+
return
134+
}
135+
132136
/*
133137
When running with multiple goroutines it is possible to have a race condition where a call to HasResource
134138
returns false, indicating that a converter should go ahead and process the resource. But by the time

0 commit comments

Comments
 (0)