github.com/gabrielperezs/terraform@v0.7.0-rc2.0.20160715084931-f7da2612946f/builtin/providers/aws/resource_aws_elastic_transcoder_pipeline_test.go (about)

     1  package aws
     2  
     3  import (
     4  	"fmt"
     5  	"testing"
     6  
     7  	"github.com/aws/aws-sdk-go/aws"
     8  	"github.com/aws/aws-sdk-go/aws/awserr"
     9  	"github.com/aws/aws-sdk-go/service/elastictranscoder"
    10  	"github.com/hashicorp/terraform/helper/resource"
    11  	"github.com/hashicorp/terraform/terraform"
    12  )
    13  
    14  func TestAccAWSElasticTranscoderPipeline_basic(t *testing.T) {
    15  	pipeline := &elastictranscoder.Pipeline{}
    16  
    17  	resource.Test(t, resource.TestCase{
    18  		PreCheck:      func() { testAccPreCheck(t) },
    19  		IDRefreshName: "aws_elastictranscoder_pipeline.bar",
    20  		Providers:     testAccProviders,
    21  		CheckDestroy:  testAccCheckElasticTranscoderPipelineDestroy,
    22  		Steps: []resource.TestStep{
    23  			resource.TestStep{
    24  				Config: awsElasticTranscoderPipelineConfigBasic,
    25  				Check: resource.ComposeTestCheckFunc(
    26  					testAccCheckAWSElasticTranscoderPipelineExists("aws_elastictranscoder_pipeline.bar", pipeline),
    27  				),
    28  			},
    29  		},
    30  	})
    31  }
    32  
    33  func TestAccAWSElasticTranscoderPipeline_withContentConfig(t *testing.T) {
    34  	pipeline := &elastictranscoder.Pipeline{}
    35  
    36  	resource.Test(t, resource.TestCase{
    37  		PreCheck:      func() { testAccPreCheck(t) },
    38  		IDRefreshName: "aws_elastictranscoder_pipeline.bar",
    39  		Providers:     testAccProviders,
    40  		CheckDestroy:  testAccCheckElasticTranscoderPipelineDestroy,
    41  		Steps: []resource.TestStep{
    42  			resource.TestStep{
    43  				Config: awsElasticTranscoderPipelineWithContentConfig,
    44  				Check: resource.ComposeTestCheckFunc(
    45  					testAccCheckAWSElasticTranscoderPipelineExists("aws_elastictranscoder_pipeline.bar", pipeline),
    46  				),
    47  			},
    48  			resource.TestStep{
    49  				Config: awsElasticTranscoderPipelineWithContentConfigUpdate,
    50  				Check: resource.ComposeTestCheckFunc(
    51  					testAccCheckAWSElasticTranscoderPipelineExists("aws_elastictranscoder_pipeline.bar", pipeline),
    52  				),
    53  			},
    54  		},
    55  	})
    56  }
    57  
    58  func TestAccAWSElasticTranscoderPipeline_withPermissions(t *testing.T) {
    59  	pipeline := &elastictranscoder.Pipeline{}
    60  
    61  	resource.Test(t, resource.TestCase{
    62  		PreCheck:      func() { testAccPreCheck(t) },
    63  		IDRefreshName: "aws_elastictranscoder_pipeline.baz",
    64  		Providers:     testAccProviders,
    65  		CheckDestroy:  testAccCheckElasticTranscoderPipelineDestroy,
    66  		Steps: []resource.TestStep{
    67  			resource.TestStep{
    68  				Config: awsElasticTranscoderPipelineWithPerms,
    69  				Check: resource.ComposeTestCheckFunc(
    70  					testAccCheckAWSElasticTranscoderPipelineExists("aws_elastictranscoder_pipeline.baz", pipeline),
    71  				),
    72  			},
    73  		},
    74  	})
    75  }
    76  
    77  func testAccCheckAWSElasticTranscoderPipelineExists(n string, res *elastictranscoder.Pipeline) resource.TestCheckFunc {
    78  	return func(s *terraform.State) error {
    79  		rs, ok := s.RootModule().Resources[n]
    80  		if !ok {
    81  			return fmt.Errorf("Not found: %s", n)
    82  		}
    83  
    84  		if rs.Primary.ID == "" {
    85  			return fmt.Errorf("No Pipeline ID is set")
    86  		}
    87  
    88  		conn := testAccProvider.Meta().(*AWSClient).elastictranscoderconn
    89  
    90  		out, err := conn.ReadPipeline(&elastictranscoder.ReadPipelineInput{
    91  			Id: aws.String(rs.Primary.ID),
    92  		})
    93  
    94  		if err != nil {
    95  			return err
    96  		}
    97  
    98  		*res = *out.Pipeline
    99  
   100  		return nil
   101  	}
   102  }
   103  
   104  func testAccCheckElasticTranscoderPipelineDestroy(s *terraform.State) error {
   105  	conn := testAccProvider.Meta().(*AWSClient).elastictranscoderconn
   106  
   107  	for _, rs := range s.RootModule().Resources {
   108  		if rs.Type != "aws_elastictranscoder_pipline" {
   109  			continue
   110  		}
   111  
   112  		out, err := conn.ReadPipeline(&elastictranscoder.ReadPipelineInput{
   113  			Id: aws.String(rs.Primary.ID),
   114  		})
   115  
   116  		if err == nil {
   117  			if out.Pipeline != nil && *out.Pipeline.Id == rs.Primary.ID {
   118  				return fmt.Errorf("Elastic Transcoder Pipeline still exists")
   119  			}
   120  		}
   121  
   122  		awsErr, ok := err.(awserr.Error)
   123  		if !ok {
   124  			return err
   125  		}
   126  
   127  		if awsErr.Code() != "ResourceNotFoundException" {
   128  			return fmt.Errorf("unexpected error: %s", awsErr)
   129  		}
   130  
   131  	}
   132  	return nil
   133  }
   134  
   135  const awsElasticTranscoderPipelineConfigBasic = `
   136  resource "aws_elastictranscoder_pipeline" "bar" {
   137    input_bucket  = "${aws_s3_bucket.test_bucket.bucket}"
   138    output_bucket = "${aws_s3_bucket.test_bucket.bucket}"
   139    name          = "aws_elastictranscoder_pipeline_tf_test_"
   140    role          = "${aws_iam_role.test_role.arn}"
   141  }
   142  
   143  resource "aws_iam_role" "test_role" {
   144    name = "aws_elastictranscoder_pipeline_tf_test_role_"
   145  
   146    assume_role_policy = <<EOF
   147  {
   148    "Version": "2012-10-17",
   149    "Statement": [
   150      {
   151        "Action": "sts:AssumeRole",
   152        "Principal": {
   153          "Service": "ec2.amazonaws.com"
   154        },
   155        "Effect": "Allow",
   156        "Sid": ""
   157      }
   158    ]
   159  }
   160  EOF
   161  }
   162  
   163  resource "aws_s3_bucket" "test_bucket" {
   164    bucket = "aws-elasticencoder-pipeline-tf-test-bucket"
   165    acl    = "private"
   166  }
   167  `
   168  
   169  const awsElasticTranscoderPipelineWithContentConfig = `
   170  resource "aws_elastictranscoder_pipeline" "bar" {
   171    input_bucket = "${aws_s3_bucket.content_bucket.bucket}"
   172    name         = "aws_elastictranscoder_pipeline_tf_test_"
   173    role         = "${aws_iam_role.test_role.arn}"
   174  
   175    content_config {
   176      bucket        = "${aws_s3_bucket.content_bucket.bucket}"
   177      storage_class = "Standard"
   178    }
   179  
   180    thumbnail_config {
   181      bucket        = "${aws_s3_bucket.content_bucket.bucket}"
   182      storage_class = "Standard"
   183    }
   184  }
   185  
   186  resource "aws_iam_role" "test_role" {
   187    name = "aws_elastictranscoder_pipeline_tf_test_role_"
   188  
   189    assume_role_policy = <<EOF
   190  {
   191    "Version": "2012-10-17",
   192    "Statement": [
   193      {
   194        "Action": "sts:AssumeRole",
   195        "Principal": {
   196          "Service": "ec2.amazonaws.com"
   197        },
   198        "Effect": "Allow",
   199        "Sid": ""
   200      }
   201    ]
   202  }
   203  EOF
   204  }
   205  
   206  resource "aws_s3_bucket" "content_bucket" {
   207    bucket = "aws-elasticencoder-pipeline-tf-content-bucket"
   208    acl    = "private"
   209  }
   210  
   211  resource "aws_s3_bucket" "input_bucket" {
   212    bucket = "aws-elasticencoder-pipeline-tf-input-bucket"
   213    acl    = "private"
   214  }
   215  
   216  resource "aws_s3_bucket" "thumb_bucket" {
   217    bucket = "aws-elasticencoder-pipeline-tf-thumb-bucket"
   218    acl    = "private"
   219  }
   220  `
   221  
   222  const awsElasticTranscoderPipelineWithContentConfigUpdate = `
   223  resource "aws_elastictranscoder_pipeline" "bar" {
   224    input_bucket = "${aws_s3_bucket.input_bucket.bucket}"
   225    name         = "aws_elastictranscoder_pipeline_tf_test_"
   226    role         = "${aws_iam_role.test_role.arn}"
   227  
   228    content_config {
   229      bucket        = "${aws_s3_bucket.content_bucket.bucket}"
   230      storage_class = "Standard"
   231    }
   232  
   233    thumbnail_config {
   234      bucket        = "${aws_s3_bucket.thumb_bucket.bucket}"
   235      storage_class = "Standard"
   236    }
   237  }
   238  
   239  resource "aws_iam_role" "test_role" {
   240    name = "aws_elastictranscoder_pipeline_tf_test_role_"
   241  
   242    assume_role_policy = <<EOF
   243  {
   244    "Version": "2012-10-17",
   245    "Statement": [
   246      {
   247        "Action": "sts:AssumeRole",
   248        "Principal": {
   249          "Service": "ec2.amazonaws.com"
   250        },
   251        "Effect": "Allow",
   252        "Sid": ""
   253      }
   254    ]
   255  }
   256  EOF
   257  }
   258  
   259  resource "aws_s3_bucket" "content_bucket" {
   260    bucket = "aws-elasticencoder-pipeline-tf-content-bucket"
   261    acl    = "private"
   262  }
   263  
   264  resource "aws_s3_bucket" "input_bucket" {
   265    bucket = "aws-elasticencoder-pipeline-tf-input-bucket"
   266    acl    = "private"
   267  }
   268  
   269  resource "aws_s3_bucket" "thumb_bucket" {
   270    bucket = "aws-elasticencoder-pipeline-tf-thumb-bucket"
   271    acl    = "private"
   272  }
   273  `
   274  
   275  const awsElasticTranscoderPipelineWithPerms = `
   276  resource "aws_elastictranscoder_pipeline" "baz" {
   277    input_bucket = "${aws_s3_bucket.content_bucket.bucket}"
   278    name         = "aws_elastictranscoder_pipeline_tf_test_"
   279    role         = "${aws_iam_role.test_role.arn}"
   280  
   281    content_config {
   282      bucket        = "${aws_s3_bucket.content_bucket.bucket}"
   283      storage_class = "Standard"
   284    }
   285  
   286    content_config_permissions = {
   287      grantee_type = "Group"
   288      grantee      = "AuthenticatedUsers"
   289      access       = ["FullControl"]
   290    }
   291  
   292    thumbnail_config {
   293      bucket        = "${aws_s3_bucket.content_bucket.bucket}"
   294      storage_class = "Standard"
   295    }
   296  
   297    thumbnail_config_permissions = {
   298      grantee_type = "Group"
   299      grantee      = "AuthenticatedUsers"
   300      access       = ["FullControl"]
   301    }
   302  }
   303  
   304  resource "aws_iam_role" "test_role" {
   305    name = "aws_elastictranscoder_pipeline_tf_test_role_"
   306  
   307    assume_role_policy = <<EOF
   308  {
   309    "Version": "2012-10-17",
   310    "Statement": [
   311      {
   312        "Action": "sts:AssumeRole",
   313        "Principal": {
   314          "Service": "ec2.amazonaws.com"
   315        },
   316        "Effect": "Allow",
   317        "Sid": ""
   318      }
   319    ]
   320  }
   321  EOF
   322  }
   323  
   324  resource "aws_s3_bucket" "content_bucket" {
   325    bucket = "aws-elasticencoder-pipeline-tf-content-bucket"
   326    acl    = "private"
   327  }
   328  `