@@ -210,6 +210,8 @@ func (r *FeatureFlagResource) Create(ctx context.Context, req resource.CreateReq
210210 if ! resp .Diagnostics .HasError () {
211211 data .Tags = tagsSet
212212 }
213+ } else {
214+ data .Tags = types .SetNull (types .StringType )
213215 }
214216
215217 tflog .Debug (ctx , "Created PostHog feature flag" , map [string ]interface {}{
@@ -227,6 +229,11 @@ func (r *FeatureFlagResource) Read(ctx context.Context, req resource.ReadRequest
227229 return
228230 }
229231
232+ // Track what fields were originally configured
233+ hasFiltersInState := ! data .Filters .IsNull ()
234+ hasRolloutInState := ! data .RolloutPercentage .IsNull ()
235+ hasTagsInState := ! data .Tags .IsNull ()
236+
230237 tflog .Debug (ctx , "Reading PostHog feature flag" , map [string ]interface {}{
231238 "id" : data .ID .ValueInt64 (),
232239 })
@@ -255,26 +262,41 @@ func (r *FeatureFlagResource) Read(ctx context.Context, req resource.ReadRequest
255262 data .Active = types .BoolNull ()
256263 }
257264
258- if flag .Filters != nil && len (flag .Filters ) > 0 {
259- filtersJSON , err := json .Marshal (flag .Filters )
260- if err == nil {
261- data .Filters = types .StringValue (string (filtersJSON ))
265+ // Only set filters if it was originally in state
266+ if hasFiltersInState {
267+ if flag .Filters != nil && len (flag .Filters ) > 0 {
268+ filtersJSON , err := json .Marshal (flag .Filters )
269+ if err == nil {
270+ data .Filters = types .StringValue (string (filtersJSON ))
271+ }
272+ } else {
273+ data .Filters = types .StringNull ()
262274 }
263275 } else {
264276 data .Filters = types .StringNull ()
265277 }
266278
267- if flag .RolloutPercentage != nil {
268- data .RolloutPercentage = types .Int64Value (int64 (* flag .RolloutPercentage ))
279+ // Only set rollout_percentage if it was originally in state
280+ if hasRolloutInState {
281+ if flag .RolloutPercentage != nil {
282+ data .RolloutPercentage = types .Int64Value (int64 (* flag .RolloutPercentage ))
283+ } else {
284+ data .RolloutPercentage = types .Int64Null ()
285+ }
269286 } else {
270287 data .RolloutPercentage = types .Int64Null ()
271288 }
272289
273- if len (flag .Tags ) > 0 {
274- tagsSet , diags := types .SetValueFrom (ctx , types .StringType , flag .Tags )
275- resp .Diagnostics .Append (diags ... )
276- if ! resp .Diagnostics .HasError () {
277- data .Tags = tagsSet
290+ // Only set tags if they were originally in state
291+ if hasTagsInState {
292+ if len (flag .Tags ) > 0 {
293+ tagsSet , diags := types .SetValueFrom (ctx , types .StringType , flag .Tags )
294+ resp .Diagnostics .Append (diags ... )
295+ if ! resp .Diagnostics .HasError () {
296+ data .Tags = tagsSet
297+ }
298+ } else {
299+ data .Tags = types .SetNull (types .StringType )
278300 }
279301 } else {
280302 data .Tags = types .SetNull (types .StringType )
@@ -413,6 +435,13 @@ func (r *FeatureFlagResource) Update(ctx context.Context, req resource.UpdateReq
413435 // Empty set if plan had tags but API returned none
414436 newState .Tags , _ = types .SetValueFrom (ctx , types .StringType , []string {})
415437 }
438+ } else {
439+ // Tags not in plan - preserve from state or set null with proper type
440+ if ! state .Tags .IsNull () {
441+ newState .Tags = state .Tags
442+ } else {
443+ newState .Tags = types .SetNull (types .StringType )
444+ }
416445 }
417446
418447 tflog .Debug (ctx , "Updated PostHog feature flag" , map [string ]interface {}{
0 commit comments