-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #58 from spring-media/feat/source-location
Feat/source location
- Loading branch information
Showing
17 changed files
with
896 additions
and
99 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
package awsmt | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"github.com/aws/aws-sdk-go/aws" | ||
"github.com/aws/aws-sdk-go/service/mediatailor" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/diag" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||
) | ||
|
||
func dataSourceSourceLocation() *schema.Resource { | ||
return &schema.Resource{ | ||
ReadContext: dataSourceSourceLocationRead, | ||
Schema: map[string]*schema.Schema{ | ||
"access_configuration": { | ||
Type: schema.TypeList, | ||
Computed: true, | ||
Elem: &schema.Resource{ | ||
Schema: map[string]*schema.Schema{ | ||
"access_type": &computedString, | ||
// SMATC is short for Secret Manager Access Token Configuration | ||
"smatc_header_name": &computedString, | ||
"smatc_secret_arn": &computedString, | ||
"smatc_secret_string_key": &computedString, | ||
}, | ||
}, | ||
}, | ||
"arn": &computedString, | ||
"creation_time": &computedString, | ||
"default_segment_delivery_configuration_url": &computedString, | ||
"http_configuration_url": &computedString, | ||
"last_modified_time": &computedString, | ||
"segment_delivery_configurations": { | ||
Type: schema.TypeList, | ||
Computed: true, | ||
Elem: &schema.Resource{ | ||
Schema: map[string]*schema.Schema{ | ||
"base_url": &computedString, | ||
"name": &computedString, | ||
}, | ||
}, | ||
}, | ||
"source_location_name": &requiredString, | ||
"tags": { | ||
Type: schema.TypeMap, | ||
Computed: true, | ||
Elem: &schema.Schema{ | ||
Type: schema.TypeString, | ||
}, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func dataSourceSourceLocationRead(_ context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { | ||
client := m.(*mediatailor.MediaTailor) | ||
|
||
name := d.Get("source_location_name").(string) | ||
if name == "" { | ||
return diag.Errorf("`source_location_name` parameter required") | ||
} | ||
res, err := client.DescribeSourceLocation(&mediatailor.DescribeSourceLocationInput{SourceLocationName: &name}) | ||
if err != nil { | ||
return diag.FromErr(fmt.Errorf("error while retrieving the source location: %w", err)) | ||
} | ||
|
||
d.SetId(aws.StringValue(res.SourceLocationName)) | ||
|
||
err = setSourceLocation(res, d) | ||
if err != nil { | ||
diag.FromErr(err) | ||
} | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package awsmt | ||
|
||
import ( | ||
"fmt" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" | ||
"regexp" | ||
"testing" | ||
) | ||
|
||
func TestAccSourceLocationDataSourceBasic(t *testing.T) { | ||
dataSourceName := "data.awsmt_source_location.test" | ||
rName := "basic_source_location" | ||
resource.Test(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
ProviderFactories: ProviderFactories, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccSourceLocationDataSourceBasic(rName), | ||
Check: resource.ComposeTestCheckFunc( | ||
resource.TestMatchResourceAttr(dataSourceName, "arn", regexp.MustCompile(`^arn:aws:mediatailor:[\w-]+:\d+:sourceLocation\/.*$`)), | ||
resource.TestMatchResourceAttr(dataSourceName, "creation_time", regexp.MustCompile(`^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2} \+\d{4} \w+$`)), | ||
resource.TestMatchResourceAttr(dataSourceName, "last_modified_time", regexp.MustCompile(`^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2} \+\d{4} \w+$`)), | ||
resource.TestCheckResourceAttr(dataSourceName, "source_location_name", rName), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func testAccSourceLocationDataSourceBasic(rName string) string { | ||
return fmt.Sprintf(` | ||
resource "awsmt_source_location" "test_data_source"{ | ||
access_configuration { | ||
access_type = "S3_SIGV4" | ||
} | ||
default_segment_delivery_configuration_url = "https://www.example.com" | ||
http_configuration_url = "https://ott-mediatailor-test.s3.eu-central-1.amazonaws.com/test-img.jpeg" | ||
source_location_name = "%[1]s" | ||
segment_delivery_configurations { | ||
base_url = "https://ott-mediatailor-test.s3.eu-central-1.amazonaws.com/test-img.jpeg" | ||
name = "example" | ||
} | ||
} | ||
data "awsmt_source_location" "test" { | ||
source_location_name = awsmt_source_location.test_data_source.source_location_name | ||
} | ||
`, rName) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.