@@ -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,113 @@ func TestBlockCollectionElementForceNew(t *testing.T) {
1621
1624
})
1622
1625
})
1623
1626
}
1627
+
1628
+ func TestDetailedDiffReplacementComputedProperty (t * testing.T ) {
1629
+ t .Parallel ()
1630
+ // TODO[pulumi/pulumi-terraform-bridge#2660]
1631
+ // We fail to re-compute computed properties when the resource is being replaced.
1632
+ res := & schema.Resource {
1633
+ Schema : map [string ]* schema.Schema {
1634
+ "computed" : {
1635
+ Type : schema .TypeString ,
1636
+ Computed : true ,
1637
+ },
1638
+ "other" : {
1639
+ Type : schema .TypeString ,
1640
+ Optional : true ,
1641
+ ForceNew : true ,
1642
+ },
1643
+ },
1644
+ CreateContext : func (ctx context.Context , rd * schema.ResourceData , meta interface {}) diag.Diagnostics {
1645
+ rd .SetId ("r1" )
1646
+
1647
+ err := rd .Set ("computed" , "computed_value" )
1648
+ contract .AssertNoErrorf (err , "setting computed" )
1649
+ return nil
1650
+ },
1651
+ }
1652
+
1653
+ type testOutput struct {
1654
+ initialValue cty.Value
1655
+ changeValue cty.Value
1656
+ tfOut string
1657
+ pulumiOut string
1658
+ detailedDiff map [string ]any
1659
+ }
1660
+
1661
+ t .Run ("no change" , func (t * testing.T ) {
1662
+ t .Parallel ()
1663
+ initialValue := cty .ObjectVal (map [string ]cty.Value {})
1664
+ changeValue := cty .ObjectVal (map [string ]cty.Value {})
1665
+ diff := runDiffCheck (t , diffTestCase {
1666
+ Resource : res ,
1667
+ Config1 : initialValue ,
1668
+ Config2 : changeValue ,
1669
+ })
1670
+
1671
+ autogold .ExpectFile (t , testOutput {
1672
+ initialValue : initialValue ,
1673
+ changeValue : changeValue ,
1674
+ tfOut : diff .TFOut ,
1675
+ pulumiOut : diff .PulumiOut ,
1676
+ detailedDiff : diff .PulumiDiff .DetailedDiff ,
1677
+ })
1678
+ })
1679
+
1680
+ t .Run ("non-computed added" , func (t * testing.T ) {
1681
+ t .Parallel ()
1682
+ initialValue := cty .ObjectVal (map [string ]cty.Value {})
1683
+ changeValue := cty .ObjectVal (map [string ]cty.Value {"other" : cty .StringVal ("other_value" )})
1684
+ diff := runDiffCheck (t , diffTestCase {
1685
+ Resource : res ,
1686
+ Config1 : initialValue ,
1687
+ Config2 : changeValue ,
1688
+ })
1689
+
1690
+ autogold .ExpectFile (t , testOutput {
1691
+ initialValue : initialValue ,
1692
+ changeValue : changeValue ,
1693
+ tfOut : diff .TFOut ,
1694
+ pulumiOut : diff .PulumiOut ,
1695
+ detailedDiff : diff .PulumiDiff .DetailedDiff ,
1696
+ })
1697
+ })
1698
+
1699
+ t .Run ("non-computed removed" , func (t * testing.T ) {
1700
+ t .Parallel ()
1701
+ initialValue := cty .ObjectVal (map [string ]cty.Value {"other" : cty .StringVal ("other_value" )})
1702
+ changeValue := cty .ObjectVal (map [string ]cty.Value {})
1703
+ diff := runDiffCheck (t , diffTestCase {
1704
+ Resource : res ,
1705
+ Config1 : initialValue ,
1706
+ Config2 : changeValue ,
1707
+ })
1708
+
1709
+ autogold .ExpectFile (t , testOutput {
1710
+ initialValue : initialValue ,
1711
+ changeValue : changeValue ,
1712
+ tfOut : diff .TFOut ,
1713
+ pulumiOut : diff .PulumiOut ,
1714
+ detailedDiff : diff .PulumiDiff .DetailedDiff ,
1715
+ })
1716
+ })
1717
+
1718
+ t .Run ("non-computed changed" , func (t * testing.T ) {
1719
+ t .Parallel ()
1720
+ initialValue := cty .ObjectVal (map [string ]cty.Value {"other" : cty .StringVal ("other_value" )})
1721
+ changeValue := cty .ObjectVal (map [string ]cty.Value {"other" : cty .StringVal ("other_value_2" )})
1722
+ diff := runDiffCheck (t , diffTestCase {
1723
+ Resource : res ,
1724
+ Config1 : initialValue ,
1725
+ Config2 : changeValue ,
1726
+ })
1727
+
1728
+ autogold .ExpectFile (t , testOutput {
1729
+ initialValue : initialValue ,
1730
+ changeValue : changeValue ,
1731
+ tfOut : diff .TFOut ,
1732
+ pulumiOut : diff .PulumiOut ,
1733
+ detailedDiff : diff .PulumiDiff .DetailedDiff ,
1734
+ })
1735
+ })
1736
+ }
0 commit comments