diff --git a/terraform/context.go b/terraform/context.go index 5637083ce0..2a438787f0 100644 --- a/terraform/context.go +++ b/terraform/context.go @@ -138,7 +138,17 @@ func NewContext(opts *ContextOpts) (*Context, tfdiags.Diagnostics) { // Determine parallelism, default to 10. We do this both to limit // CPU pressure but also to have an extra guard against rate throttling // from providers. + // We throw an error in case of negative parallelism par := opts.Parallelism + if par < 0 { + diags = diags.Append(tfdiags.Sourceless( + tfdiags.Error, + "Invalid parallelism value", + fmt.Sprintf("The parallelism must be a positive value. Not %d.", par), + )) + return nil, diags + } + if par == 0 { par = 10 } diff --git a/terraform/util.go b/terraform/util.go index 5428cd5a0a..7966b58dd2 100644 --- a/terraform/util.go +++ b/terraform/util.go @@ -12,8 +12,8 @@ type Semaphore chan struct{} // NewSemaphore creates a semaphore that allows up // to a given limit of simultaneous acquisitions func NewSemaphore(n int) Semaphore { - if n == 0 { - panic("semaphore with limit 0") + if n <= 0 { + panic("semaphore with limit <=0") } ch := make(chan struct{}, n) return Semaphore(ch)