Skip to content

How do I get S3 bucket folder structure using Terratest? #173

Answered by denis256
rhoboat asked this question in Help
Discussion options

You must be logged in to vote

Hello,
try to use "%v" format key - it should provide formatted value.
Additional points:

  • bucketObjects value can be truncated which will require to do additional request
  • "Prefix" is optional and can be used to filter "subdirectories"

Simplified example:

	t.Parallel()
	region := "eu-west-1"
	s3BucketName := "acme-example-stage-eu-west-1-tf-state"
	s3Client, err := NewS3ClientE(t, region)
	if err != nil {
		t.Fatal(err)
	}
	listObjectsParams := &s3.ListObjectsV2Input{
		Bucket: aws.String(s3BucketName),
	}
	for {
		bucketObjects, err := s3Client.ListObjectsV2(listObjectsParams)
		if err != nil {
			t.Fatal(err)
		}
		fmt.Printf("%v\n", bucketObjects)
		if !*bucketObjects.IsTruncated {
		…

Replies: 2 comments 3 replies

Comment options

You must be logged in to vote
1 reply
@pandu-bhojaraj-mf
Comment options

Comment options

You must be logged in to vote
2 replies
@pandu-bhojaraj-mf
Comment options

@pandu-bhojaraj-mf
Comment options

Answer selected by denis256
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Help
Labels
3 participants