@@ -26,7 +26,10 @@ import (
26
26
"github.com/hashicorp/terraform-plugin-go/tftypes"
27
27
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
28
28
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
29
+ "github.com/hexops/autogold/v2"
30
+ "github.com/pulumi/pulumi/sdk/v3/go/common/util/contract"
29
31
"github.com/stretchr/testify/require"
32
+ "github.com/zclconf/go-cty/cty"
30
33
)
31
34
32
35
func TestUnchangedBasicObject (t * testing.T ) {
@@ -1621,3 +1624,112 @@ func TestBlockCollectionElementForceNew(t *testing.T) {
1621
1624
})
1622
1625
})
1623
1626
}
1627
+
1628
+ func TestDetailedDiffReplacementComputedProperty (t * testing.T ) {
1629
+ t .Parallel ()
1630
+
1631
+ res := & schema.Resource {
1632
+ Schema : map [string ]* schema.Schema {
1633
+ "computed" : {
1634
+ Type : schema .TypeString ,
1635
+ Computed : true ,
1636
+ },
1637
+ "other" : {
1638
+ Type : schema .TypeString ,
1639
+ Optional : true ,
1640
+ ForceNew : true ,
1641
+ },
1642
+ },
1643
+ CreateContext : func (ctx context.Context , rd * schema.ResourceData , meta interface {}) diag.Diagnostics {
1644
+ rd .SetId ("r1" )
1645
+
1646
+ err := rd .Set ("computed" , "computed_value" )
1647
+ contract .AssertNoErrorf (err , "setting computed" )
1648
+ return nil
1649
+ },
1650
+ }
1651
+
1652
+ type testOutput struct {
1653
+ initialValue cty.Value
1654
+ changeValue cty.Value
1655
+ tfOut string
1656
+ pulumiOut string
1657
+ detailedDiff map [string ]any
1658
+ }
1659
+
1660
+ t .Run ("no change" , func (t * testing.T ) {
1661
+ t .Parallel ()
1662
+ initialValue := cty .ObjectVal (map [string ]cty.Value {})
1663
+ changeValue := cty .ObjectVal (map [string ]cty.Value {})
1664
+ diff := runDiffCheck (t , diffTestCase {
1665
+ Resource : res ,
1666
+ Config1 : initialValue ,
1667
+ Config2 : changeValue ,
1668
+ })
1669
+
1670
+ autogold .ExpectFile (t , testOutput {
1671
+ initialValue : initialValue ,
1672
+ changeValue : changeValue ,
1673
+ tfOut : diff .TFOut ,
1674
+ pulumiOut : diff .PulumiOut ,
1675
+ detailedDiff : diff .PulumiDiff .DetailedDiff ,
1676
+ })
1677
+ })
1678
+
1679
+ t .Run ("non-computed added" , func (t * testing.T ) {
1680
+ t .Parallel ()
1681
+ initialValue := cty .ObjectVal (map [string ]cty.Value {})
1682
+ changeValue := cty .ObjectVal (map [string ]cty.Value {"other" : cty .StringVal ("other_value" )})
1683
+ diff := runDiffCheck (t , diffTestCase {
1684
+ Resource : res ,
1685
+ Config1 : initialValue ,
1686
+ Config2 : changeValue ,
1687
+ })
1688
+
1689
+ autogold .ExpectFile (t , testOutput {
1690
+ initialValue : initialValue ,
1691
+ changeValue : changeValue ,
1692
+ tfOut : diff .TFOut ,
1693
+ pulumiOut : diff .PulumiOut ,
1694
+ detailedDiff : diff .PulumiDiff .DetailedDiff ,
1695
+ })
1696
+ })
1697
+
1698
+ t .Run ("non-computed removed" , func (t * testing.T ) {
1699
+ t .Parallel ()
1700
+ initialValue := cty .ObjectVal (map [string ]cty.Value {"other" : cty .StringVal ("other_value" )})
1701
+ changeValue := cty .ObjectVal (map [string ]cty.Value {})
1702
+ diff := runDiffCheck (t , diffTestCase {
1703
+ Resource : res ,
1704
+ Config1 : initialValue ,
1705
+ Config2 : changeValue ,
1706
+ })
1707
+
1708
+ autogold .ExpectFile (t , testOutput {
1709
+ initialValue : initialValue ,
1710
+ changeValue : changeValue ,
1711
+ tfOut : diff .TFOut ,
1712
+ pulumiOut : diff .PulumiOut ,
1713
+ detailedDiff : diff .PulumiDiff .DetailedDiff ,
1714
+ })
1715
+ })
1716
+
1717
+ t .Run ("non-computed changed" , func (t * testing.T ) {
1718
+ t .Parallel ()
1719
+ initialValue := cty .ObjectVal (map [string ]cty.Value {"other" : cty .StringVal ("other_value" )})
1720
+ changeValue := cty .ObjectVal (map [string ]cty.Value {"other" : cty .StringVal ("other_value_2" )})
1721
+ diff := runDiffCheck (t , diffTestCase {
1722
+ Resource : res ,
1723
+ Config1 : initialValue ,
1724
+ Config2 : changeValue ,
1725
+ })
1726
+
1727
+ autogold .ExpectFile (t , testOutput {
1728
+ initialValue : initialValue ,
1729
+ changeValue : changeValue ,
1730
+ tfOut : diff .TFOut ,
1731
+ pulumiOut : diff .PulumiOut ,
1732
+ detailedDiff : diff .PulumiDiff .DetailedDiff ,
1733
+ })
1734
+ })
1735
+ }
0 commit comments