github.com/danp/terraform@v0.9.5-0.20170426144147-39d740081351/builtin/providers/aws/resource_aws_s3_bucket_object_test.go (about)

     1  // make testacc TEST=./builtin/providers/aws/ TESTARGS='-run=TestAccAWSS3BucketObject_'
     2  package aws
     3  
     4  import (
     5  	"fmt"
     6  	"io/ioutil"
     7  	"os"
     8  	"reflect"
     9  	"sort"
    10  	"testing"
    11  
    12  	"github.com/hashicorp/terraform/helper/acctest"
    13  	"github.com/hashicorp/terraform/helper/resource"
    14  	"github.com/hashicorp/terraform/terraform"
    15  
    16  	"github.com/aws/aws-sdk-go/aws"
    17  	"github.com/aws/aws-sdk-go/service/s3"
    18  )
    19  
    20  func TestAccAWSS3BucketObject_source(t *testing.T) {
    21  	tmpFile, err := ioutil.TempFile("", "tf-acc-s3-obj-source")
    22  	if err != nil {
    23  		t.Fatal(err)
    24  	}
    25  	defer os.Remove(tmpFile.Name())
    26  
    27  	rInt := acctest.RandInt()
    28  	// first write some data to the tempfile just so it's not 0 bytes.
    29  	err = ioutil.WriteFile(tmpFile.Name(), []byte("{anything will do }"), 0644)
    30  	if err != nil {
    31  		t.Fatal(err)
    32  	}
    33  	var obj s3.GetObjectOutput
    34  
    35  	resource.Test(t, resource.TestCase{
    36  		PreCheck:     func() { testAccPreCheck(t) },
    37  		Providers:    testAccProviders,
    38  		CheckDestroy: testAccCheckAWSS3BucketObjectDestroy,
    39  		Steps: []resource.TestStep{
    40  			resource.TestStep{
    41  				Config: testAccAWSS3BucketObjectConfigSource(rInt, tmpFile.Name()),
    42  				Check:  testAccCheckAWSS3BucketObjectExists("aws_s3_bucket_object.object", &obj),
    43  			},
    44  		},
    45  	})
    46  }
    47  
    48  func TestAccAWSS3BucketObject_content(t *testing.T) {
    49  	rInt := acctest.RandInt()
    50  	var obj s3.GetObjectOutput
    51  
    52  	resource.Test(t, resource.TestCase{
    53  		PreCheck:     func() { testAccPreCheck(t) },
    54  		Providers:    testAccProviders,
    55  		CheckDestroy: testAccCheckAWSS3BucketObjectDestroy,
    56  		Steps: []resource.TestStep{
    57  			resource.TestStep{
    58  				PreConfig: func() {},
    59  				Config:    testAccAWSS3BucketObjectConfigContent(rInt),
    60  				Check:     testAccCheckAWSS3BucketObjectExists("aws_s3_bucket_object.object", &obj),
    61  			},
    62  		},
    63  	})
    64  }
    65  
    66  func TestAccAWSS3BucketObject_withContentCharacteristics(t *testing.T) {
    67  	tmpFile, err := ioutil.TempFile("", "tf-acc-s3-obj-content-characteristics")
    68  	if err != nil {
    69  		t.Fatal(err)
    70  	}
    71  	defer os.Remove(tmpFile.Name())
    72  
    73  	rInt := acctest.RandInt()
    74  	// first write some data to the tempfile just so it's not 0 bytes.
    75  	err = ioutil.WriteFile(tmpFile.Name(), []byte("{anything will do }"), 0644)
    76  	if err != nil {
    77  		t.Fatal(err)
    78  	}
    79  
    80  	var obj s3.GetObjectOutput
    81  
    82  	resource.Test(t, resource.TestCase{
    83  		PreCheck:     func() { testAccPreCheck(t) },
    84  		Providers:    testAccProviders,
    85  		CheckDestroy: testAccCheckAWSS3BucketObjectDestroy,
    86  		Steps: []resource.TestStep{
    87  			resource.TestStep{
    88  				Config: testAccAWSS3BucketObjectConfig_withContentCharacteristics(rInt, tmpFile.Name()),
    89  				Check: resource.ComposeTestCheckFunc(
    90  					testAccCheckAWSS3BucketObjectExists("aws_s3_bucket_object.object", &obj),
    91  					resource.TestCheckResourceAttr(
    92  						"aws_s3_bucket_object.object", "content_type", "binary/octet-stream"),
    93  				),
    94  			},
    95  		},
    96  	})
    97  }
    98  
    99  func TestAccAWSS3BucketObject_updates(t *testing.T) {
   100  	tmpFile, err := ioutil.TempFile("", "tf-acc-s3-obj-updates")
   101  	if err != nil {
   102  		t.Fatal(err)
   103  	}
   104  	defer os.Remove(tmpFile.Name())
   105  
   106  	rInt := acctest.RandInt()
   107  	err = ioutil.WriteFile(tmpFile.Name(), []byte("initial object state"), 0644)
   108  	if err != nil {
   109  		t.Fatal(err)
   110  	}
   111  	var obj s3.GetObjectOutput
   112  
   113  	resource.Test(t, resource.TestCase{
   114  		PreCheck:     func() { testAccPreCheck(t) },
   115  		Providers:    testAccProviders,
   116  		CheckDestroy: testAccCheckAWSS3BucketObjectDestroy,
   117  		Steps: []resource.TestStep{
   118  			resource.TestStep{
   119  				Config: testAccAWSS3BucketObjectConfig_updates(rInt, tmpFile.Name()),
   120  				Check: resource.ComposeTestCheckFunc(
   121  					testAccCheckAWSS3BucketObjectExists("aws_s3_bucket_object.object", &obj),
   122  					resource.TestCheckResourceAttr("aws_s3_bucket_object.object", "etag", "647d1d58e1011c743ec67d5e8af87b53"),
   123  				),
   124  			},
   125  			resource.TestStep{
   126  				PreConfig: func() {
   127  					err = ioutil.WriteFile(tmpFile.Name(), []byte("modified object"), 0644)
   128  					if err != nil {
   129  						t.Fatal(err)
   130  					}
   131  				},
   132  				Config: testAccAWSS3BucketObjectConfig_updates(rInt, tmpFile.Name()),
   133  				Check: resource.ComposeTestCheckFunc(
   134  					testAccCheckAWSS3BucketObjectExists("aws_s3_bucket_object.object", &obj),
   135  					resource.TestCheckResourceAttr("aws_s3_bucket_object.object", "etag", "1c7fd13df1515c2a13ad9eb068931f09"),
   136  				),
   137  			},
   138  		},
   139  	})
   140  }
   141  
   142  func TestAccAWSS3BucketObject_updatesWithVersioning(t *testing.T) {
   143  	tmpFile, err := ioutil.TempFile("", "tf-acc-s3-obj-updates-w-versions")
   144  	if err != nil {
   145  		t.Fatal(err)
   146  	}
   147  	defer os.Remove(tmpFile.Name())
   148  
   149  	rInt := acctest.RandInt()
   150  	err = ioutil.WriteFile(tmpFile.Name(), []byte("initial versioned object state"), 0644)
   151  	if err != nil {
   152  		t.Fatal(err)
   153  	}
   154  
   155  	var originalObj, modifiedObj s3.GetObjectOutput
   156  
   157  	resource.Test(t, resource.TestCase{
   158  		PreCheck:     func() { testAccPreCheck(t) },
   159  		Providers:    testAccProviders,
   160  		CheckDestroy: testAccCheckAWSS3BucketObjectDestroy,
   161  		Steps: []resource.TestStep{
   162  			resource.TestStep{
   163  				Config: testAccAWSS3BucketObjectConfig_updatesWithVersioning(rInt, tmpFile.Name()),
   164  				Check: resource.ComposeTestCheckFunc(
   165  					testAccCheckAWSS3BucketObjectExists("aws_s3_bucket_object.object", &originalObj),
   166  					resource.TestCheckResourceAttr("aws_s3_bucket_object.object", "etag", "cee4407fa91906284e2a5e5e03e86b1b"),
   167  				),
   168  			},
   169  			resource.TestStep{
   170  				PreConfig: func() {
   171  					err = ioutil.WriteFile(tmpFile.Name(), []byte("modified versioned object"), 0644)
   172  					if err != nil {
   173  						t.Fatal(err)
   174  					}
   175  				},
   176  				Config: testAccAWSS3BucketObjectConfig_updatesWithVersioning(rInt, tmpFile.Name()),
   177  				Check: resource.ComposeTestCheckFunc(
   178  					testAccCheckAWSS3BucketObjectExists("aws_s3_bucket_object.object", &modifiedObj),
   179  					resource.TestCheckResourceAttr("aws_s3_bucket_object.object", "etag", "00b8c73b1b50e7cc932362c7225b8e29"),
   180  					testAccCheckAWSS3BucketObjectVersionIdDiffers(&originalObj, &modifiedObj),
   181  				),
   182  			},
   183  		},
   184  	})
   185  }
   186  
   187  func testAccCheckAWSS3BucketObjectVersionIdDiffers(first, second *s3.GetObjectOutput) resource.TestCheckFunc {
   188  	return func(s *terraform.State) error {
   189  		if first.VersionId == nil {
   190  			return fmt.Errorf("Expected first object to have VersionId: %s", first)
   191  		}
   192  		if second.VersionId == nil {
   193  			return fmt.Errorf("Expected second object to have VersionId: %s", second)
   194  		}
   195  
   196  		if *first.VersionId == *second.VersionId {
   197  			return fmt.Errorf("Expected Version IDs to differ, but they are equal (%s)", *first.VersionId)
   198  		}
   199  
   200  		return nil
   201  	}
   202  }
   203  
   204  func testAccCheckAWSS3BucketObjectDestroy(s *terraform.State) error {
   205  	s3conn := testAccProvider.Meta().(*AWSClient).s3conn
   206  
   207  	for _, rs := range s.RootModule().Resources {
   208  		if rs.Type != "aws_s3_bucket_object" {
   209  			continue
   210  		}
   211  
   212  		_, err := s3conn.HeadObject(
   213  			&s3.HeadObjectInput{
   214  				Bucket:  aws.String(rs.Primary.Attributes["bucket"]),
   215  				Key:     aws.String(rs.Primary.Attributes["key"]),
   216  				IfMatch: aws.String(rs.Primary.Attributes["etag"]),
   217  			})
   218  		if err == nil {
   219  			return fmt.Errorf("AWS S3 Object still exists: %s", rs.Primary.ID)
   220  		}
   221  	}
   222  	return nil
   223  }
   224  
   225  func testAccCheckAWSS3BucketObjectExists(n string, obj *s3.GetObjectOutput) resource.TestCheckFunc {
   226  	return func(s *terraform.State) error {
   227  		rs, ok := s.RootModule().Resources[n]
   228  		if !ok {
   229  			return fmt.Errorf("Not Found: %s", n)
   230  		}
   231  
   232  		if rs.Primary.ID == "" {
   233  			return fmt.Errorf("No S3 Bucket Object ID is set")
   234  		}
   235  
   236  		s3conn := testAccProvider.Meta().(*AWSClient).s3conn
   237  		out, err := s3conn.GetObject(
   238  			&s3.GetObjectInput{
   239  				Bucket:  aws.String(rs.Primary.Attributes["bucket"]),
   240  				Key:     aws.String(rs.Primary.Attributes["key"]),
   241  				IfMatch: aws.String(rs.Primary.Attributes["etag"]),
   242  			})
   243  		if err != nil {
   244  			return fmt.Errorf("S3Bucket Object error: %s", err)
   245  		}
   246  
   247  		*obj = *out
   248  
   249  		return nil
   250  	}
   251  }
   252  
   253  func TestAccAWSS3BucketObject_kms(t *testing.T) {
   254  	rInt := acctest.RandInt()
   255  	var obj s3.GetObjectOutput
   256  
   257  	resource.Test(t, resource.TestCase{
   258  		PreCheck:     func() { testAccPreCheck(t) },
   259  		Providers:    testAccProviders,
   260  		CheckDestroy: testAccCheckAWSS3BucketObjectDestroy,
   261  		Steps: []resource.TestStep{
   262  			resource.TestStep{
   263  				PreConfig: func() {},
   264  				Config:    testAccAWSS3BucketObjectConfig_withKMSId(rInt),
   265  				Check:     testAccCheckAWSS3BucketObjectExists("aws_s3_bucket_object.object", &obj),
   266  			},
   267  		},
   268  	})
   269  }
   270  
   271  func TestAccAWSS3BucketObject_sse(t *testing.T) {
   272  	tmpFile, err := ioutil.TempFile("", "tf-acc-s3-obj-source-sse")
   273  	if err != nil {
   274  		t.Fatal(err)
   275  	}
   276  	defer os.Remove(tmpFile.Name())
   277  
   278  	// first write some data to the tempfile just so it's not 0 bytes.
   279  	err = ioutil.WriteFile(tmpFile.Name(), []byte("{anything will do}"), 0644)
   280  	if err != nil {
   281  		t.Fatal(err)
   282  	}
   283  
   284  	rInt := acctest.RandInt()
   285  	var obj s3.GetObjectOutput
   286  
   287  	resource.Test(t, resource.TestCase{
   288  		PreCheck:     func() { testAccPreCheck(t) },
   289  		Providers:    testAccProviders,
   290  		CheckDestroy: testAccCheckAWSS3BucketObjectDestroy,
   291  		Steps: []resource.TestStep{
   292  			resource.TestStep{
   293  				PreConfig: func() {},
   294  				Config:    testAccAWSS3BucketObjectConfig_withSSE(rInt, tmpFile.Name()),
   295  				Check: resource.ComposeTestCheckFunc(
   296  					testAccCheckAWSS3BucketObjectExists(
   297  						"aws_s3_bucket_object.object",
   298  						&obj),
   299  					testAccCheckAWSS3BucketObjectSSE(
   300  						"aws_s3_bucket_object.object",
   301  						"aws:kms"),
   302  				),
   303  			},
   304  		},
   305  	})
   306  }
   307  
   308  func TestAccAWSS3BucketObject_acl(t *testing.T) {
   309  	rInt := acctest.RandInt()
   310  	var obj s3.GetObjectOutput
   311  
   312  	resource.Test(t, resource.TestCase{
   313  		PreCheck:     func() { testAccPreCheck(t) },
   314  		Providers:    testAccProviders,
   315  		CheckDestroy: testAccCheckAWSS3BucketObjectDestroy,
   316  		Steps: []resource.TestStep{
   317  			resource.TestStep{
   318  				Config: testAccAWSS3BucketObjectConfig_acl(rInt, "private"),
   319  				Check: resource.ComposeTestCheckFunc(
   320  					testAccCheckAWSS3BucketObjectExists(
   321  						"aws_s3_bucket_object.object", &obj),
   322  					resource.TestCheckResourceAttr(
   323  						"aws_s3_bucket_object.object",
   324  						"acl",
   325  						"private"),
   326  					testAccCheckAWSS3BucketObjectAcl(
   327  						"aws_s3_bucket_object.object",
   328  						[]string{"FULL_CONTROL"}),
   329  				),
   330  			},
   331  			resource.TestStep{
   332  				Config: testAccAWSS3BucketObjectConfig_acl(rInt, "public-read"),
   333  				Check: resource.ComposeTestCheckFunc(
   334  					testAccCheckAWSS3BucketObjectExists(
   335  						"aws_s3_bucket_object.object",
   336  						&obj),
   337  					resource.TestCheckResourceAttr(
   338  						"aws_s3_bucket_object.object",
   339  						"acl",
   340  						"public-read"),
   341  					testAccCheckAWSS3BucketObjectAcl(
   342  						"aws_s3_bucket_object.object",
   343  						[]string{"FULL_CONTROL", "READ"}),
   344  				),
   345  			},
   346  		},
   347  	})
   348  }
   349  
   350  func testAccCheckAWSS3BucketObjectAcl(n string, expectedPerms []string) resource.TestCheckFunc {
   351  	return func(s *terraform.State) error {
   352  		rs, _ := s.RootModule().Resources[n]
   353  		s3conn := testAccProvider.Meta().(*AWSClient).s3conn
   354  
   355  		out, err := s3conn.GetObjectAcl(&s3.GetObjectAclInput{
   356  			Bucket: aws.String(rs.Primary.Attributes["bucket"]),
   357  			Key:    aws.String(rs.Primary.Attributes["key"]),
   358  		})
   359  
   360  		if err != nil {
   361  			return fmt.Errorf("GetObjectAcl error: %v", err)
   362  		}
   363  
   364  		var perms []string
   365  		for _, v := range out.Grants {
   366  			perms = append(perms, *v.Permission)
   367  		}
   368  		sort.Strings(perms)
   369  
   370  		if !reflect.DeepEqual(perms, expectedPerms) {
   371  			return fmt.Errorf("Expected ACL permissions to be %v, got %v", expectedPerms, perms)
   372  		}
   373  
   374  		return nil
   375  	}
   376  }
   377  
   378  func TestResourceAWSS3BucketObjectAcl_validation(t *testing.T) {
   379  	_, errors := validateS3BucketObjectAclType("incorrect", "acl")
   380  	if len(errors) == 0 {
   381  		t.Fatalf("Expected to trigger a validation error")
   382  	}
   383  
   384  	var testCases = []struct {
   385  		Value    string
   386  		ErrCount int
   387  	}{
   388  		{
   389  			Value:    "public-read",
   390  			ErrCount: 0,
   391  		},
   392  		{
   393  			Value:    "public-read-write",
   394  			ErrCount: 0,
   395  		},
   396  	}
   397  
   398  	for _, tc := range testCases {
   399  		_, errors := validateS3BucketObjectAclType(tc.Value, "acl")
   400  		if len(errors) != tc.ErrCount {
   401  			t.Fatalf("Expected not to trigger a validation error")
   402  		}
   403  	}
   404  }
   405  
   406  func TestAccAWSS3BucketObject_storageClass(t *testing.T) {
   407  	rInt := acctest.RandInt()
   408  	var obj s3.GetObjectOutput
   409  
   410  	resource.Test(t, resource.TestCase{
   411  		PreCheck:     func() { testAccPreCheck(t) },
   412  		Providers:    testAccProviders,
   413  		CheckDestroy: testAccCheckAWSS3BucketObjectDestroy,
   414  		Steps: []resource.TestStep{
   415  			resource.TestStep{
   416  				PreConfig: func() {},
   417  				Config:    testAccAWSS3BucketObjectConfigContent(rInt),
   418  				Check: resource.ComposeTestCheckFunc(
   419  					testAccCheckAWSS3BucketObjectExists(
   420  						"aws_s3_bucket_object.object",
   421  						&obj),
   422  					resource.TestCheckResourceAttr(
   423  						"aws_s3_bucket_object.object",
   424  						"storage_class",
   425  						"STANDARD"),
   426  					testAccCheckAWSS3BucketObjectStorageClass(
   427  						"aws_s3_bucket_object.object",
   428  						"STANDARD"),
   429  				),
   430  			},
   431  			resource.TestStep{
   432  				Config: testAccAWSS3BucketObjectConfig_storageClass(rInt, "REDUCED_REDUNDANCY"),
   433  				Check: resource.ComposeTestCheckFunc(
   434  					testAccCheckAWSS3BucketObjectExists(
   435  						"aws_s3_bucket_object.object",
   436  						&obj),
   437  					resource.TestCheckResourceAttr(
   438  						"aws_s3_bucket_object.object",
   439  						"storage_class",
   440  						"REDUCED_REDUNDANCY"),
   441  					testAccCheckAWSS3BucketObjectStorageClass(
   442  						"aws_s3_bucket_object.object",
   443  						"REDUCED_REDUNDANCY"),
   444  				),
   445  			},
   446  		},
   447  	})
   448  }
   449  
   450  func TestResourceAWSS3BucketObjectStorageClass_validation(t *testing.T) {
   451  	_, errors := validateS3BucketObjectStorageClassType("incorrect", "storage_class")
   452  	if len(errors) == 0 {
   453  		t.Fatalf("Expected to trigger a validation error")
   454  	}
   455  
   456  	var testCases = []struct {
   457  		Value    string
   458  		ErrCount int
   459  	}{
   460  		{
   461  			Value:    "STANDARD",
   462  			ErrCount: 0,
   463  		},
   464  		{
   465  			Value:    "REDUCED_REDUNDANCY",
   466  			ErrCount: 0,
   467  		},
   468  	}
   469  
   470  	for _, tc := range testCases {
   471  		_, errors := validateS3BucketObjectStorageClassType(tc.Value, "storage_class")
   472  		if len(errors) != tc.ErrCount {
   473  			t.Fatalf("Expected not to trigger a validation error")
   474  		}
   475  	}
   476  }
   477  
   478  func testAccCheckAWSS3BucketObjectStorageClass(n, expectedClass string) resource.TestCheckFunc {
   479  	return func(s *terraform.State) error {
   480  		rs, _ := s.RootModule().Resources[n]
   481  		s3conn := testAccProvider.Meta().(*AWSClient).s3conn
   482  
   483  		out, err := s3conn.HeadObject(&s3.HeadObjectInput{
   484  			Bucket: aws.String(rs.Primary.Attributes["bucket"]),
   485  			Key:    aws.String(rs.Primary.Attributes["key"]),
   486  		})
   487  
   488  		if err != nil {
   489  			return fmt.Errorf("HeadObject error: %v", err)
   490  		}
   491  
   492  		// The "STANDARD" (which is also the default) storage
   493  		// class when set would not be included in the results.
   494  		storageClass := s3.StorageClassStandard
   495  		if out.StorageClass != nil {
   496  			storageClass = *out.StorageClass
   497  		}
   498  
   499  		if storageClass != expectedClass {
   500  			return fmt.Errorf("Expected Storage Class to be %v, got %v",
   501  				expectedClass, storageClass)
   502  		}
   503  
   504  		return nil
   505  	}
   506  }
   507  
   508  func testAccCheckAWSS3BucketObjectSSE(n, expectedSSE string) resource.TestCheckFunc {
   509  	return func(s *terraform.State) error {
   510  		rs, _ := s.RootModule().Resources[n]
   511  		s3conn := testAccProvider.Meta().(*AWSClient).s3conn
   512  
   513  		out, err := s3conn.HeadObject(&s3.HeadObjectInput{
   514  			Bucket: aws.String(rs.Primary.Attributes["bucket"]),
   515  			Key:    aws.String(rs.Primary.Attributes["key"]),
   516  		})
   517  
   518  		if err != nil {
   519  			return fmt.Errorf("HeadObject error: %v", err)
   520  		}
   521  
   522  		if out.ServerSideEncryption == nil {
   523  			return fmt.Errorf("Expected a non %v Server Side Encryption.", out.ServerSideEncryption)
   524  		}
   525  
   526  		sse := *out.ServerSideEncryption
   527  		if sse != expectedSSE {
   528  			return fmt.Errorf("Expected Server Side Encryption %v, got %v.",
   529  				expectedSSE, sse)
   530  		}
   531  
   532  		return nil
   533  	}
   534  }
   535  
   536  func TestAccAWSS3BucketObject_tags(t *testing.T) {
   537  	rInt := acctest.RandInt()
   538  	var obj s3.GetObjectOutput
   539  
   540  	resource.Test(t, resource.TestCase{
   541  		PreCheck:     func() { testAccPreCheck(t) },
   542  		Providers:    testAccProviders,
   543  		CheckDestroy: testAccCheckAWSS3BucketObjectDestroy,
   544  		Steps: []resource.TestStep{
   545  			resource.TestStep{
   546  				PreConfig: func() {},
   547  				Config:    testAccAWSS3BucketObjectConfig_withTags(rInt),
   548  				Check: resource.ComposeTestCheckFunc(
   549  					testAccCheckAWSS3BucketObjectExists("aws_s3_bucket_object.object", &obj),
   550  					resource.TestCheckResourceAttr("aws_s3_bucket_object.object", "tags.%", "2"),
   551  				),
   552  			},
   553  		},
   554  	})
   555  }
   556  
   557  func testAccAWSS3BucketObjectConfigSource(randInt int, source string) string {
   558  	return fmt.Sprintf(`
   559  resource "aws_s3_bucket" "object_bucket" {
   560      bucket = "tf-object-test-bucket-%d"
   561  }
   562  resource "aws_s3_bucket_object" "object" {
   563  	bucket = "${aws_s3_bucket.object_bucket.bucket}"
   564  	key = "test-key"
   565  	source = "%s"
   566  	content_type = "binary/octet-stream"
   567  }
   568  `, randInt, source)
   569  }
   570  
   571  func testAccAWSS3BucketObjectConfig_withContentCharacteristics(randInt int, source string) string {
   572  	return fmt.Sprintf(`
   573  resource "aws_s3_bucket" "object_bucket_2" {
   574  	bucket = "tf-object-test-bucket-%d"
   575  }
   576  
   577  resource "aws_s3_bucket_object" "object" {
   578  	bucket = "${aws_s3_bucket.object_bucket_2.bucket}"
   579  	key = "test-key"
   580  	source = "%s"
   581  	content_language = "en"
   582  	content_type = "binary/octet-stream"
   583  }
   584  `, randInt, source)
   585  }
   586  
   587  func testAccAWSS3BucketObjectConfigContent(randInt int) string {
   588  	return fmt.Sprintf(`
   589  resource "aws_s3_bucket" "object_bucket" {
   590          bucket = "tf-object-test-bucket-%d"
   591  }
   592  resource "aws_s3_bucket_object" "object" {
   593          bucket = "${aws_s3_bucket.object_bucket.bucket}"
   594          key = "test-key"
   595          content = "some_bucket_content"
   596  }
   597  `, randInt)
   598  }
   599  
   600  func testAccAWSS3BucketObjectConfig_updates(randInt int, source string) string {
   601  	return fmt.Sprintf(`
   602  resource "aws_s3_bucket" "object_bucket_3" {
   603  	bucket = "tf-object-test-bucket-%d"
   604  }
   605  
   606  resource "aws_s3_bucket_object" "object" {
   607  	bucket = "${aws_s3_bucket.object_bucket_3.bucket}"
   608  	key = "updateable-key"
   609  	source = "%s"
   610  	etag = "${md5(file("%s"))}"
   611  }
   612  `, randInt, source, source)
   613  }
   614  
   615  func testAccAWSS3BucketObjectConfig_updatesWithVersioning(randInt int, source string) string {
   616  	return fmt.Sprintf(`
   617  resource "aws_s3_bucket" "object_bucket_3" {
   618  	bucket = "tf-object-test-bucket-%d"
   619  	versioning {
   620  		enabled = true
   621  	}
   622  }
   623  
   624  resource "aws_s3_bucket_object" "object" {
   625  	bucket = "${aws_s3_bucket.object_bucket_3.bucket}"
   626  	key = "updateable-key"
   627  	source = "%s"
   628  	etag = "${md5(file("%s"))}"
   629  }
   630  `, randInt, source, source)
   631  }
   632  
   633  func testAccAWSS3BucketObjectConfig_withKMSId(randInt int) string {
   634  	return fmt.Sprintf(`
   635  resource "aws_kms_key" "kms_key_1" {
   636  }
   637  
   638  resource "aws_s3_bucket" "object_bucket_2" {
   639  	bucket = "tf-object-test-bucket-%d"
   640  }
   641  
   642  resource "aws_s3_bucket_object" "object" {
   643  	bucket = "${aws_s3_bucket.object_bucket_2.bucket}"
   644  	key = "test-key"
   645  	content = "stuff"
   646  	kms_key_id = "${aws_kms_key.kms_key_1.arn}"
   647  }
   648  `, randInt)
   649  }
   650  
   651  func testAccAWSS3BucketObjectConfig_withSSE(randInt int, source string) string {
   652  	return fmt.Sprintf(`
   653  resource "aws_s3_bucket" "object_bucket" {
   654  	bucket = "tf-object-test-bucket-%d"
   655  }
   656  
   657  resource "aws_s3_bucket_object" "object" {
   658  	bucket = "${aws_s3_bucket.object_bucket.bucket}"
   659  	key = "test-key"
   660  	source = "%s"
   661  	server_side_encryption = "aws:kms"
   662  }
   663  `, randInt, source)
   664  }
   665  
   666  func testAccAWSS3BucketObjectConfig_acl(randInt int, acl string) string {
   667  	return fmt.Sprintf(`
   668  resource "aws_s3_bucket" "object_bucket" {
   669          bucket = "tf-object-test-bucket-%d"
   670  }
   671  resource "aws_s3_bucket_object" "object" {
   672          bucket = "${aws_s3_bucket.object_bucket.bucket}"
   673          key = "test-key"
   674          content = "some_bucket_content"
   675          acl = "%s"
   676  }
   677  `, randInt, acl)
   678  }
   679  
   680  func testAccAWSS3BucketObjectConfig_storageClass(randInt int, storage_class string) string {
   681  	return fmt.Sprintf(`
   682  resource "aws_s3_bucket" "object_bucket" {
   683          bucket = "tf-object-test-bucket-%d"
   684  }
   685  resource "aws_s3_bucket_object" "object" {
   686          bucket = "${aws_s3_bucket.object_bucket.bucket}"
   687          key = "test-key"
   688          content = "some_bucket_content"
   689          storage_class = "%s"
   690  }
   691  `, randInt, storage_class)
   692  }
   693  
   694  func testAccAWSS3BucketObjectConfig_withTags(randInt int) string {
   695  	return fmt.Sprintf(`
   696  resource "aws_s3_bucket" "object_bucket_2" {
   697  	bucket = "tf-object-test-bucket-%d"
   698  }
   699  
   700  resource "aws_s3_bucket_object" "object" {
   701  	bucket = "${aws_s3_bucket.object_bucket_2.bucket}"
   702  	key = "test-key"
   703  	content = "stuff"
   704  	tags {
   705  		Key1 = "Value One"
   706  		Description = "Very interesting"
   707  	}
   708  }
   709  `, randInt)
   710  }