|
| 1 | +package ivs_test |
| 2 | + |
| 3 | +import ( |
| 4 | + "fmt" |
| 5 | + "regexp" |
| 6 | + "testing" |
| 7 | + |
| 8 | + "github.com/aws/aws-sdk-go/service/ivs" |
| 9 | + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" |
| 10 | + "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" |
| 11 | + "github.com/hashicorp/terraform-provider-aws/internal/acctest" |
| 12 | +) |
| 13 | + |
| 14 | +func TestAccIVSStreamKeyDataSource_basic(t *testing.T) { |
| 15 | + dataSourceName := "data.aws_ivs_stream_key.test" |
| 16 | + channelResourceName := "aws_ivs_channel.test" |
| 17 | + |
| 18 | + resource.ParallelTest(t, resource.TestCase{ |
| 19 | + PreCheck: func() { acctest.PreCheck(t) }, |
| 20 | + ErrorCheck: acctest.ErrorCheck(t, ivs.EndpointsID), |
| 21 | + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, |
| 22 | + Steps: []resource.TestStep{ |
| 23 | + { |
| 24 | + Config: testAccStreamKeyDataSourceConfig_basic(), |
| 25 | + Check: resource.ComposeTestCheckFunc( |
| 26 | + testAccCheckStreamKeyDataSource(dataSourceName), |
| 27 | + resource.TestCheckResourceAttrPair(dataSourceName, "channel_arn", channelResourceName, "id"), |
| 28 | + resource.TestCheckResourceAttrSet(dataSourceName, "value"), |
| 29 | + acctest.MatchResourceAttrRegionalARN(dataSourceName, "arn", "ivs", regexp.MustCompile(`stream-key/.+`)), |
| 30 | + ), |
| 31 | + }, |
| 32 | + }, |
| 33 | + }) |
| 34 | +} |
| 35 | + |
| 36 | +func testAccCheckStreamKeyDataSource(n string) resource.TestCheckFunc { |
| 37 | + return func(s *terraform.State) error { |
| 38 | + rs, ok := s.RootModule().Resources[n] |
| 39 | + if !ok { |
| 40 | + return fmt.Errorf("Can't find Stream Key data source: %s", n) |
| 41 | + } |
| 42 | + |
| 43 | + if rs.Primary.ID == "" { |
| 44 | + return fmt.Errorf("Stream Key data source ID not set") |
| 45 | + } |
| 46 | + return nil |
| 47 | + } |
| 48 | +} |
| 49 | + |
| 50 | +func testAccStreamKeyDataSourceConfig_basic() string { |
| 51 | + return ` |
| 52 | +resource "aws_ivs_channel" "test" { |
| 53 | +} |
| 54 | +
|
| 55 | +data "aws_ivs_stream_key" "test" { |
| 56 | + channel_arn = aws_ivs_channel.test.arn |
| 57 | +} |
| 58 | +` |
| 59 | +} |
0 commit comments