Skip to content

Commit 782132d

Browse files
committed
remove incorrect computed check
The config is already validated, and does not need to be checked in AssertPlanValid. Add some more coverage for plan validation.
1 parent 43f960b commit 782132d

2 files changed

Lines changed: 185 additions & 14 deletions

File tree

internal/plans/objchange/plan_valid.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -286,11 +286,6 @@ func assertPlannedValueValid(attrS *configschema.Attribute, priorV, configV, pla
286286
}
287287
return errs
288288
}
289-
} else {
290-
if attrS.Computed {
291-
errs = append(errs, path.NewErrorf("configuration present for computed attribute"))
292-
return errs
293-
}
294289
}
295290

296291
// If this attribute has a NestedType, validate the nested object

internal/plans/objchange/plan_valid_test.go

Lines changed: 185 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1387,6 +1387,7 @@ func TestAssertPlanValid(t *testing.T) {
13871387
},
13881388
},
13891389
},
1390+
Optional: true,
13901391
Computed: true,
13911392
},
13921393
"single": {
@@ -1423,9 +1424,11 @@ func TestAssertPlanValid(t *testing.T) {
14231424
"list": cty.NullVal(cty.List(cty.Object(map[string]cty.Type{
14241425
"name": cty.String,
14251426
}))),
1426-
"set": cty.NullVal(cty.Set(cty.Object(map[string]cty.Type{
1427-
"name": cty.String,
1428-
}))),
1427+
"set": cty.SetVal([]cty.Value{
1428+
cty.ObjectVal(map[string]cty.Value{
1429+
"name": cty.StringVal("from_config"),
1430+
}),
1431+
}),
14291432
"single": cty.NullVal(cty.Object(map[string]cty.Type{
14301433
"name": cty.String,
14311434
})),
@@ -1437,21 +1440,194 @@ func TestAssertPlanValid(t *testing.T) {
14371440
})),
14381441
}),
14391442
"list": cty.ListVal([]cty.Value{
1440-
cty.UnknownVal(cty.Object(map[string]cty.Type{
1441-
"name": cty.String,
1442-
})),
1443+
cty.ObjectVal(map[string]cty.Value{
1444+
"name": cty.StringVal("computed"),
1445+
}),
14431446
}),
14441447
"set": cty.SetVal([]cty.Value{
1445-
cty.UnknownVal(cty.Object(map[string]cty.Type{
1446-
"name": cty.String,
1447-
})),
1448+
cty.ObjectVal(map[string]cty.Value{
1449+
"name": cty.StringVal("from_config"),
1450+
}),
14481451
}),
14491452
"single": cty.UnknownVal(cty.Object(map[string]cty.Type{
14501453
"name": cty.String,
14511454
})),
14521455
}),
14531456
nil,
14541457
},
1458+
"optional computed within nested objects": {
1459+
&configschema.Block{
1460+
Attributes: map[string]*configschema.Attribute{
1461+
"map": {
1462+
NestedType: &configschema.Object{
1463+
Nesting: configschema.NestingMap,
1464+
Attributes: map[string]*configschema.Attribute{
1465+
"name": {
1466+
Type: cty.String,
1467+
Computed: true,
1468+
},
1469+
},
1470+
},
1471+
},
1472+
// When an object has dynamic attrs, the map may be
1473+
// handled as an object.
1474+
"map_as_obj": {
1475+
NestedType: &configschema.Object{
1476+
Nesting: configschema.NestingMap,
1477+
Attributes: map[string]*configschema.Attribute{
1478+
"name": {
1479+
Type: cty.String,
1480+
Optional: true,
1481+
Computed: true,
1482+
},
1483+
},
1484+
},
1485+
},
1486+
"list": {
1487+
NestedType: &configschema.Object{
1488+
Nesting: configschema.NestingList,
1489+
Attributes: map[string]*configschema.Attribute{
1490+
"name": {
1491+
Type: cty.String,
1492+
Optional: true,
1493+
Computed: true,
1494+
},
1495+
},
1496+
},
1497+
},
1498+
"set": {
1499+
NestedType: &configschema.Object{
1500+
Nesting: configschema.NestingSet,
1501+
Attributes: map[string]*configschema.Attribute{
1502+
"name": {
1503+
Type: cty.String,
1504+
Optional: true,
1505+
Computed: true,
1506+
},
1507+
},
1508+
},
1509+
},
1510+
"single": {
1511+
NestedType: &configschema.Object{
1512+
Nesting: configschema.NestingSingle,
1513+
Attributes: map[string]*configschema.Attribute{
1514+
"name": {
1515+
Type: cty.DynamicPseudoType,
1516+
Optional: true,
1517+
Computed: true,
1518+
},
1519+
},
1520+
},
1521+
},
1522+
},
1523+
},
1524+
cty.NullVal(cty.Object(map[string]cty.Type{
1525+
"map": cty.Map(cty.Object(map[string]cty.Type{
1526+
"name": cty.String,
1527+
})),
1528+
"map_as_obj": cty.Map(cty.Object(map[string]cty.Type{
1529+
"name": cty.DynamicPseudoType,
1530+
})),
1531+
"list": cty.List(cty.Object(map[string]cty.Type{
1532+
"name": cty.String,
1533+
})),
1534+
"set": cty.Set(cty.Object(map[string]cty.Type{
1535+
"name": cty.String,
1536+
})),
1537+
"single": cty.Object(map[string]cty.Type{
1538+
"name": cty.String,
1539+
}),
1540+
})),
1541+
cty.ObjectVal(map[string]cty.Value{
1542+
"map": cty.MapVal(map[string]cty.Value{
1543+
"one": cty.ObjectVal(map[string]cty.Value{
1544+
"name": cty.StringVal("from_config"),
1545+
}),
1546+
}),
1547+
"map_as_obj": cty.MapVal(map[string]cty.Value{
1548+
"one": cty.ObjectVal(map[string]cty.Value{
1549+
"name": cty.NullVal(cty.DynamicPseudoType),
1550+
}),
1551+
}),
1552+
"list": cty.ListVal([]cty.Value{
1553+
cty.ObjectVal(map[string]cty.Value{
1554+
"name": cty.NullVal(cty.String),
1555+
}),
1556+
}),
1557+
"set": cty.SetVal([]cty.Value{
1558+
cty.ObjectVal(map[string]cty.Value{
1559+
"name": cty.NullVal(cty.String),
1560+
}),
1561+
}),
1562+
"single": cty.ObjectVal(map[string]cty.Value{
1563+
"name": cty.StringVal("from_config"),
1564+
}),
1565+
}),
1566+
cty.ObjectVal(map[string]cty.Value{
1567+
"map": cty.MapVal(map[string]cty.Value{
1568+
"one": cty.ObjectVal(map[string]cty.Value{
1569+
"name": cty.StringVal("from_config"),
1570+
}),
1571+
}),
1572+
"map_as_obj": cty.ObjectVal(map[string]cty.Value{
1573+
"one": cty.ObjectVal(map[string]cty.Value{
1574+
"name": cty.StringVal("computed"),
1575+
}),
1576+
}),
1577+
"list": cty.ListVal([]cty.Value{
1578+
cty.ObjectVal(map[string]cty.Value{
1579+
"name": cty.StringVal("computed"),
1580+
}),
1581+
}),
1582+
"set": cty.SetVal([]cty.Value{
1583+
cty.ObjectVal(map[string]cty.Value{
1584+
"name": cty.NullVal(cty.String),
1585+
}),
1586+
}),
1587+
"single": cty.ObjectVal(map[string]cty.Value{
1588+
"name": cty.StringVal("from_config"),
1589+
}),
1590+
}),
1591+
nil,
1592+
},
1593+
"cannot replace config nested attr": {
1594+
&configschema.Block{
1595+
Attributes: map[string]*configschema.Attribute{
1596+
"map": {
1597+
NestedType: &configschema.Object{
1598+
Nesting: configschema.NestingMap,
1599+
Attributes: map[string]*configschema.Attribute{
1600+
"name": {
1601+
Type: cty.String,
1602+
Computed: true,
1603+
Optional: true,
1604+
},
1605+
},
1606+
},
1607+
},
1608+
},
1609+
},
1610+
cty.NullVal(cty.Object(map[string]cty.Type{
1611+
"map": cty.Map(cty.Object(map[string]cty.Type{
1612+
"name": cty.String,
1613+
})),
1614+
})),
1615+
cty.ObjectVal(map[string]cty.Value{
1616+
"map": cty.MapVal(map[string]cty.Value{
1617+
"one": cty.ObjectVal(map[string]cty.Value{
1618+
"name": cty.StringVal("from_config"),
1619+
}),
1620+
}),
1621+
}),
1622+
cty.ObjectVal(map[string]cty.Value{
1623+
"map": cty.MapVal(map[string]cty.Value{
1624+
"one": cty.ObjectVal(map[string]cty.Value{
1625+
"name": cty.StringVal("from_provider"),
1626+
}),
1627+
}),
1628+
}),
1629+
[]string{`.map.one.name: planned value cty.StringVal("from_provider") does not match config value cty.StringVal("from_config")`},
1630+
},
14551631
}
14561632

14571633
for name, test := range tests {

0 commit comments

Comments
 (0)