github.com/myhau/pulumi/pkg/v3@v3.70.2-0.20221116134521-f2775972e587/codegen/testing/test/testdata/aws-s3-folder-pp/aws-s3-folder.pp (about)

     1  // Create a bucket and expose a website index document
     2  resource siteBucket "aws:s3:Bucket" {
     3  	website = {
     4  		indexDocument = "index.html"
     5  	}
     6  }
     7  
     8  siteDir = "www" // directory for content files
     9  
    10  // For each file in the directory, create an S3 object stored in `siteBucket`
    11  resource files "aws:s3:BucketObject" {
    12      options {
    13  		range = readDir(siteDir)
    14      }
    15  
    16  	bucket = siteBucket.id // Reference the s3.Bucket object
    17  	key = range.value      // Set the key appropriately
    18  
    19  	source = fileAsset("${siteDir}/${range.value}") // use fileAsset to point to a file
    20  	contentType = range.value                       // set the MIME type of the file
    21  }
    22  
    23  // Set the access policy for the bucket so all objects are readable
    24  resource bucketPolicy "aws:s3:BucketPolicy" {
    25  	bucket = siteBucket.id // refer to the bucket created earlier
    26  
    27  	// The policy is JSON-encoded.
    28  	policy = toJSON({
    29  		Version = "2012-10-17"
    30  		Statement = [{
    31  			Effect = "Allow"
    32  			Principal = "*"
    33  			Action = [ "s3:GetObject" ]
    34  			Resource = [ "arn:aws:s3:::${siteBucket.id}/*" ]
    35  		}]
    36  	})
    37  }
    38  
    39  // Stack outputs
    40  output bucketName { value = siteBucket.bucket }
    41  output websiteUrl { value = siteBucket.websiteEndpoint }