From 0133b06e234a489e1ba7f17e0b73c3b6c1164333 Mon Sep 17 00:00:00 2001 From: Domenico Di Ruocco Date: Wed, 22 Jan 2025 13:06:57 +0100 Subject: [PATCH] fix: recreate channel on tier change OTT-7024 --- awsmt/resource_channel.go | 5 +++++ awsmt/resource_channel_test.go | 18 ++++++++++++------ 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/awsmt/resource_channel.go b/awsmt/resource_channel.go index 0249886..ebcfdd7 100644 --- a/awsmt/resource_channel.go +++ b/awsmt/resource_channel.go @@ -8,7 +8,9 @@ import ( "github.com/hashicorp/terraform-plugin-framework/path" "github.com/hashicorp/terraform-plugin-framework/resource" "github.com/hashicorp/terraform-plugin-framework/resource/schema" + "github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier" "github.com/hashicorp/terraform-plugin-framework/resource/schema/stringdefault" + "github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier" "github.com/hashicorp/terraform-plugin-framework/schema/validator" "github.com/hashicorp/terraform-plugin-framework/types" "strings" @@ -114,6 +116,9 @@ func (r *resourceChannel) Schema(_ context.Context, _ resource.SchemaRequest, re stringvalidator.OneOf([]string{"BASIC", "STANDARD"}...), }, Default: stringdefault.StaticString("BASIC"), + PlanModifiers: []planmodifier.String{ + stringplanmodifier.RequiresReplace(), + }, }, }, } diff --git a/awsmt/resource_channel_test.go b/awsmt/resource_channel_test.go index a5e4564..0414217 100644 --- a/awsmt/resource_channel_test.go +++ b/awsmt/resource_channel_test.go @@ -221,17 +221,23 @@ func TestAccChannelValuesNotFlickering(t *testing.T) { }) } -func TestAccChannelResourceSTANDARD(t *testing.T) { +func TestAccChannelTierChange(t *testing.T) { resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ { - Config: standardTierChannel(), + Config: standardTierChannel("STANDARD"), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("data.awsmt_channel.test", "tier", "STANDARD"), ), }, + { + Config: standardTierChannel("BASIC"), + Check: resource.ComposeAggregateTestCheckFunc( + resource.TestCheckResourceAttr("data.awsmt_channel.test", "tier", "BASIC"), + ), + }, }, }) } @@ -408,8 +414,8 @@ func logConfigChannel(enable bool) string { `, enable) } -func standardTierChannel() string { - return `resource "awsmt_vod_source" "test" { +func standardTierChannel(t string) string { + return fmt.Sprintf(`resource "awsmt_vod_source" "test" { http_package_configurations = [{ path = "/" source_group = "default" @@ -464,7 +470,7 @@ func standardTierChannel() string { vod_source_name = awsmt_vod_source.test.name } policy = "{\"Version\": \"2012-10-17\", \"Statement\": [{\"Sid\": \"AllowAnonymous\", \"Effect\": \"Allow\", \"Principal\": \"*\", \"Action\": \"mediatailor:GetManifest\", \"Resource\": \"arn:aws:mediatailor:eu-central-1:985600762523:channel/test\"}]}" - tier = "STANDARD" + tier = "%s" tags = {"Environment": "dev"} } @@ -475,5 +481,5 @@ func standardTierChannel() string { output "channel_out" { value = data.awsmt_channel.test } -` +`, t) }