88 "github.com/hashicorp/terraform-plugin-framework/resource"
99 "github.com/hashicorp/terraform-plugin-framework/resource/schema"
1010 "github.com/hashicorp/terraform-plugin-framework/schema/validator"
11+ "strings"
1112 "terraform-provider-mediatailor/awsmt/models"
1213)
1314
@@ -108,7 +109,7 @@ func (r *resourceSourceLocation) Create(ctx context.Context, req resource.Create
108109 return
109110 }
110111
111- plan = writeSourceLocationToPlan (plan , * sourceLocation , true )
112+ plan = writeSourceLocationToPlan (plan , * sourceLocation )
112113
113114 diags = resp .State .Set (ctx , plan )
114115 resp .Diagnostics .Append (diags ... )
@@ -133,7 +134,7 @@ func (r *resourceSourceLocation) Read(ctx context.Context, req resource.ReadRequ
133134 return
134135 }
135136
136- state = writeSourceLocationToPlan (state , mediatailor .CreateSourceLocationOutput (* sourceLocation ), true )
137+ state = writeSourceLocationToPlan (state , mediatailor .CreateSourceLocationOutput (* sourceLocation ))
137138
138139 diags = resp .State .Set (ctx , & state )
139140 resp .Diagnostics .Append (diags ... )
@@ -189,7 +190,7 @@ func (r *resourceSourceLocation) Update(ctx context.Context, req resource.Update
189190 )
190191 return
191192 }
192- plan = writeSourceLocationToPlan (plan , mediatailor .CreateSourceLocationOutput (* sourceLocationUpdated ), true )
193+ plan = writeSourceLocationToPlan (plan , mediatailor .CreateSourceLocationOutput (* sourceLocationUpdated ))
193194 }
194195
195196 resp .Diagnostics .Append (resp .State .Set (ctx , plan )... )
@@ -218,5 +219,29 @@ func (r *resourceSourceLocation) Delete(ctx context.Context, req resource.Delete
218219}
219220
220221func (r * resourceSourceLocation ) ImportState (ctx context.Context , req resource.ImportStateRequest , resp * resource.ImportStateResponse ) {
221- resource .ImportStatePassthroughID (ctx , path .Root ("name" ), req , resp )
222+ // Split the import ID to support various import formats
223+ idParts := strings .Split (req .ID , "/" )
224+
225+ if len (idParts ) == 1 {
226+ resource .ImportStatePassthroughID (ctx , path .Root ("name" ), req , resp )
227+ return
228+ }
229+
230+ // Support ARN import format
231+ if strings .HasPrefix (req .ID , "arn:aws:mediatailor:" ) {
232+ arnParts := strings .Split (req .ID , ":" )
233+ if len (arnParts ) >= 6 {
234+ resourcePath := arnParts [5 ]
235+ resourceParts := strings .Split (resourcePath , "/" )
236+ if len (resourceParts ) >= 2 && resourceParts [0 ] == "sourceLocation" {
237+ resp .Diagnostics .Append (resp .State .SetAttribute (ctx , path .Root ("name" ), resourceParts [1 ])... )
238+ return
239+ }
240+ }
241+ }
242+
243+ resp .Diagnostics .AddError (
244+ "Invalid import ID" ,
245+ "Expected import ID to be either the source location name or the full ARN" ,
246+ )
222247}
0 commit comments