77 "regexp"
88 "strings"
99 "testing"
10+ "time"
1011
1112 "github.com/gruntwork-io/terratest/modules/terraform"
1213 teststructure "github.com/gruntwork-io/terratest/modules/test-structure"
@@ -78,13 +79,30 @@ func GetTerraformVersionConstraint(t *testing.T, srcDir string) string {
7879 return constraint
7980}
8081
82+ func newTerraformOptions (t * testing.T ) * terraform.Options {
83+ t .Helper ()
84+
85+ // Start with default retryable errors as a baseline.
86+ opts := terraform .WithDefaultRetryableErrors (t , & terraform.Options {})
87+
88+ // Add a pattern to cover off this corner case.
89+ opts .RetryableTerraformErrors [".*text file busy.*" ] = "os: StartProcess ETXTBSY race on Unix systems - " +
90+ "https://github.com/golang/go/issues/22315"
91+
92+ // Set some additional options to govern the retry behaviour.
93+ opts .MaxRetries = 3
94+ opts .TimeBetweenRetries = time .Second * 5
95+
96+ return opts
97+ }
98+
8199func TerraformVersionsTest (t * testing.T , srcDir string , variables map [string ]interface {}, environment_variables map [string ]string ) {
82100 constraint := GetTerraformVersionConstraint (t , srcDir )
83101 available := GetAvailableVersions (t , "terraform" )
84102 versions := GetMatchingVersions (t , constraint , available )
85103
86104 for _ , version := range versions {
87- var tfOptions = & terraform. Options {}
105+ tfOptions := newTerraformOptions ( t )
88106
89107 if len (variables ) > 0 {
90108 tfOptions .Vars = variables
@@ -112,7 +130,7 @@ func AwsProviderVersionsTest(t *testing.T, srcDir string, variables map[string]i
112130 versions := GetMatchingVersions (t , constraint , available )
113131
114132 for _ , version := range versions {
115- var tfOptions = & terraform. Options {}
133+ tfOptions := newTerraformOptions ( t )
116134
117135 if len (variables ) > 0 {
118136 tfOptions .Vars = variables
@@ -140,7 +158,7 @@ func CloudflareProviderVersionsTest(t *testing.T, srcDir string, variables map[s
140158 testVers := GetMatchingVersions (t , constraint , available )
141159
142160 for _ , version := range testVers {
143- var tfOptions = & terraform. Options {}
161+ tfOptions := newTerraformOptions ( t )
144162
145163 if len (variables ) > 0 {
146164 tfOptions .Vars = variables
@@ -167,7 +185,7 @@ func DatadogProviderVersionsTest(t *testing.T, srcDir string, variables map[stri
167185 testVers := GetMatchingVersions (t , constraint , available )
168186
169187 for _ , version := range testVers {
170- var tfOptions = & terraform. Options {}
188+ tfOptions := newTerraformOptions ( t )
171189
172190 if len (variables ) > 0 {
173191 tfOptions .Vars = variables
@@ -193,7 +211,7 @@ func OpsgenieProviderVersionsTest(t *testing.T, srcDir string, variables map[str
193211 testVers := []string {"0.6.10" , "0.6.11" , "0.6.14" , "0.6.15" , "0.6.16" , "0.6.17" , "0.6.18" , "0.6.19" , "0.6.20" } // testing for specific versions as https://api.releases.hashicorp.com/v1/releases/terraform-provider-opsgenie is not showing anything newer than 0.6.11 currently
194212
195213 for _ , version := range testVers {
196- var tfOptions = & terraform. Options {}
214+ tfOptions := newTerraformOptions ( t )
197215
198216 if len (variables ) > 0 {
199217 tfOptions .Vars = variables
@@ -220,7 +238,7 @@ func GcpProviderVersionsTest(t *testing.T, srcDir string, variables map[string]i
220238 testVers := GetMatchingVersions (t , constraint , available )
221239
222240 for _ , version := range testVers {
223- var tfOptions = & terraform. Options {}
241+ tfOptions := newTerraformOptions ( t )
224242
225243 if len (variables ) > 0 {
226244 tfOptions .Vars = variables
0 commit comments