You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the bug
Not sure if it's a bug.. but let me explain what I am doing.. we have a test case to test terraform module with different parameters, we have list of parameters in csv file which has to iterate and generate tfvars and pass the tfvars to goscript to test terraform module. For example we have two different tfvars which it has to run and test using below script.. script is working fine but tfvars value for both test is same.. initially I thought it could be python issue which not iterating properly but we can see the correct parameters values in pipeline after python script runs even on go script both the tfvars run like generated_0.tfvars and generated_1.tfvars is running but generated_1.tfvars has same value as generated_0.tfvars.. please let me know if I'm missing something or is go script is not picking the value?
To Reproduce
Steps to reproduce the behavior, code snippets and examples which can be used to reproduce the issue.
// paste code snippets herepackage test
import (
"os""testing""fmt""log""io/ioutil""github.com/aws/aws-sdk-go/aws""github.com/aws/aws-sdk-go/aws/session""github.com/aws/aws-sdk-go/service/s3""github.com/gruntwork-io/terratest/modules/terraform""github.com/stretchr/testify/assert"
)
funcTestTerraformS3BucketCreation(t*testing.T) {
t.Parallel()
// Get the .tfvars file from the environment variabletfvarsFile:=os.Getenv("TFVARS_FILE")
iftfvarsFile=="" {
t.Fatalf("TFVARS_FILE environment variable is not set")
}
fmt.Printf("Running Terraform test with %s\n", tfvarsFile)
// Configure Terraform optionsterraformOptions:=&terraform.Options{
TerraformDir: "../", // Path to Terraform directoryVarFiles: []string{tfvarsFile}, // Use the generated .tfvars file
}
// Ensure Terraform destroy runs at the end of the testdeferterraform.Destroy(t, terraformOptions)
// Run Terraform Init and Apply, and capture any errorsterraformApplyErr:=terraform.InitAndApplyE(t, terraformOptions)
// Validate that Terraform apply succeeded and save the resultvarvalidationResultstringifterraformApplyErr!=nil {
validationResult=fmt.Sprintf("Terraform apply failed for %s: %s\n", tfvarsFile, terraformApplyErr)
writeValidationResultToFile(tfvarsFile, validationResult)
t.Fatalf(validationResult) // Fail the test immediately if Terraform apply fails
}
validationResult=fmt.Sprintf("Terraform apply succeeded for %s\n", tfvarsFile)
// Fetch the bucket name from the Terraform outputbucketName:=terraform.Output(t, terraformOptions, "bucket_name")
assert.NotEmpty(t, bucketName, "Bucket name output should not be empty")
// Validate the S3 bucket exists in AWSs3ValidationResult:=validateS3BucketExists(t, bucketName)
validationResult+=s3ValidationResult// Write validation result to a file in the root of the repowriteValidationResultToFile(tfvarsFile, validationResult)
}
// Function to validate if the S3 bucket exists in AWSfuncvalidateS3BucketExists(t*testing.T, bucketNamestring) string {
// Create a new session in the default region (you can change the region if necessary)sess, err:=session.NewSession(&aws.Config{
Region: aws.String("us-west-2"),
})
iferr!=nil {
t.Fatalf("Failed to create AWS session: %s", err)
}
// Create an S3 service clientsvc:=s3.New(sess)
// Check if the bucket exists by sending a HeadBucket request_, err=svc.HeadBucket(&s3.HeadBucketInput{
Bucket: aws.String(bucketName),
})
iferr!=nil {
returnfmt.Sprintf("S3 Bucket %s does NOT exist: %s\n", bucketName, err)
}
fmt.Printf("S3 Bucket %s exists\n", bucketName)
returnfmt.Sprintf("S3 Bucket %s exists\n", bucketName)
}
// Function to write validation result to a filefuncwriteValidationResultToFile(tfvarsFilestring, validationResultstring) {
// Use the tfvars file name for the validation result file namefileName:=fmt.Sprintf("validation_results_%s.txt", tfvarsFile)
// Write the validation result to a file in the root directoryerr:=ioutil.WriteFile("../"+fileName, []byte(validationResult), 0644)
iferr!=nil {
log.Fatalf("Failed to write validation result to file: %s", err)
}
fmt.Printf("Validation result written to %s\n", fileName)
}
Expected behavior
A clear and concise description of what you expected to happen.
Nice to have
Terminal output
Screenshots
Versions
Terratest version:
Environment details (Ubuntu 20.04, Windows 10, etc.):
Additional context
Add any other context about the problem here.
The text was updated successfully, but these errors were encountered:
Describe the bug
Not sure if it's a bug.. but let me explain what I am doing.. we have a test case to test terraform module with different parameters, we have list of parameters in csv file which has to iterate and generate tfvars and pass the tfvars to goscript to test terraform module. For example we have two different tfvars which it has to run and test using below script.. script is working fine but tfvars value for both test is same.. initially I thought it could be python issue which not iterating properly but we can see the correct parameters values in pipeline after python script runs even on go script both the tfvars run like generated_0.tfvars and generated_1.tfvars is running but generated_1.tfvars has same value as generated_0.tfvars.. please let me know if I'm missing something or is go script is not picking the value?
To Reproduce
Steps to reproduce the behavior, code snippets and examples which can be used to reproduce the issue.
Expected behavior
A clear and concise description of what you expected to happen.
Nice to have
Versions
Additional context
Add any other context about the problem here.
The text was updated successfully, but these errors were encountered: