-
Notifications
You must be signed in to change notification settings - Fork 44
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Reproduce aws-3880 in a test #1917
Changes from 1 commit
3a20298
8706961
a255fa9
668e2eb
40952e3
06d4038
38fa425
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -58,8 +58,8 @@ func runDiffCheck(t T, tc diffTestCase) { | |
tfwd := t.TempDir() | ||
|
||
tfd := newTfDriver(t, tfwd, providerShortName, rtype, tc.Resource) | ||
_ = tfd.writePlanApply(t, tc.Resource.Schema, rtype, "example", tc.Config1) | ||
tfDiffPlan := tfd.writePlanApply(t, tc.Resource.Schema, rtype, "example", tc.Config2) | ||
_ = tfd.writePlanApply(t, tc.Resource.SchemaMap(), rtype, "example", tc.Config1) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Resource may specify Schema or SchemaFunc, and SchemaMap() normalizes to access either, this is the way. |
||
tfDiffPlan := tfd.writePlanApply(t, tc.Resource.SchemaMap(), rtype, "example", tc.Config2) | ||
|
||
tfp := &schema.Provider{ | ||
ResourcesMap: map[string]*schema.Resource{ | ||
|
@@ -102,6 +102,7 @@ func runDiffCheck(t T, tc diffTestCase) { | |
x := pt.Up() | ||
|
||
tfAction := tfd.parseChangesFromTFPlan(*tfDiffPlan) | ||
t.Logf("Terraform decided to take the %q action", tfAction) | ||
|
||
tc.verifyBasicDiffAgreement(t, tfAction, x.Summary) | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -56,14 +56,18 @@ func writeBlock(body *hclwrite.Body, schemas map[string]*schema.Schema, values m | |
if sch.Type == schema.TypeMap { | ||
body.SetAttributeValue(key, value) | ||
} else if sch.Type == schema.TypeSet { | ||
for _, v := range value.AsValueSet().Values() { | ||
newBlock := body.AppendNewBlock(key, nil) | ||
writeBlock(newBlock.Body(), elem.Schema, v.AsValueMap()) | ||
if !value.IsNull() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Tolerate missing values encoded by nulls - as required by tftypes.Value (and translated to cty.Value). |
||
for _, v := range value.AsValueSet().Values() { | ||
newBlock := body.AppendNewBlock(key, nil) | ||
writeBlock(newBlock.Body(), elem.Schema, v.AsValueMap()) | ||
} | ||
} | ||
} else if sch.Type == schema.TypeList { | ||
for _, v := range value.AsValueSlice() { | ||
newBlock := body.AppendNewBlock(key, nil) | ||
writeBlock(newBlock.Body(), elem.Schema, v.AsValueMap()) | ||
if !value.IsNull() { | ||
for _, v := range value.AsValueSlice() { | ||
newBlock := body.AppendNewBlock(key, nil) | ||
writeBlock(newBlock.Body(), elem.Schema, v.AsValueMap()) | ||
} | ||
} | ||
} else { | ||
contract.Failf("unexpected schema type %v", sch.Type) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,10 +6,8 @@ | |
package wafv2 | ||
|
||
import ( | ||
"bytes" | ||
"context" | ||
"fmt" | ||
"hash/crc32" | ||
"regexp" | ||
"strings" | ||
|
||
|
@@ -18,17 +16,17 @@ import ( | |
) | ||
|
||
func ResourceWebACL() *schema.Resource { | ||
hashcodeString := func(s string) int { | ||
v := int(crc32.ChecksumIEEE([]byte(s))) | ||
if v >= 0 { | ||
return v | ||
} | ||
if -v >= 0 { | ||
return -v | ||
} | ||
// v == MinInt | ||
return 0 | ||
} | ||
// hashcodeString := func(s string) int { | ||
// v := int(crc32.ChecksumIEEE([]byte(s))) | ||
// if v >= 0 { | ||
// return v | ||
// } | ||
// if -v >= 0 { | ||
// return -v | ||
// } | ||
// // v == MinInt | ||
// return 0 | ||
// } | ||
|
||
ruleElement := &schema.Resource{ | ||
Schema: map[string]*schema.Schema{ | ||
|
@@ -138,20 +136,20 @@ func ResourceWebACL() *schema.Resource { | |
}, | ||
"rule": { | ||
Type: schema.TypeSet, | ||
Set: func(v interface{}) int { | ||
var buf bytes.Buffer | ||
schema.SerializeResourceForHash(&buf, v, ruleElement) | ||
// before := "action:(<allow:(<custom_request_handling:();>;);" | ||
// after := "action:(<allow:(<>;);" | ||
s := buf.String() | ||
//s = strings.ReplaceAll(s, before, after) | ||
n := hashcodeString(s) | ||
if 1+2 == 18 { | ||
fmt.Printf("PRE-HASH:\n%s\n\n", s) | ||
fmt.Printf("HASHED: %d\n", n) | ||
} | ||
return n | ||
}, | ||
// Set: func(v interface{}) int { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This was really here for debugging only. The original in AWS does not specify a custom Set. |
||
// var buf bytes.Buffer | ||
// schema.SerializeResourceForHash(&buf, v, ruleElement) | ||
// // before := "action:(<allow:(<custom_request_handling:();>;);" | ||
// // after := "action:(<allow:(<>;);" | ||
// s := buf.String() | ||
// //s = strings.ReplaceAll(s, before, after) | ||
// n := hashcodeString(s) | ||
// if 1+2 == 18 { | ||
// fmt.Printf("PRE-HASH:\n%s\n\n", s) | ||
// fmt.Printf("HASHED: %d\n", n) | ||
// } | ||
// return n | ||
// }, | ||
Optional: true, | ||
Elem: ruleElement, | ||
}, | ||
|
@@ -161,8 +159,6 @@ func ResourceWebACL() *schema.Resource { | |
ForceNew: true, | ||
//ValidateFunc: validation.StringInSlice(wafv2.Scope_Values(), false), | ||
}, | ||
// names.AttrTags: tftags.TagsSchema(), | ||
// names.AttrTagsAll: tftags.TagsSchemaTrulyComputed(), | ||
"token_domains": { | ||
Type: schema.TypeSet, | ||
Optional: true, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Noted that tftypes.Value representation insists (via panics) that every attribute has an entry, even if it's a nil entry. It also insisted on no optional attributes. This is now the case in this adapter, it frees the test writer from writing explicit nulls for attributes that do not matter.