Skip to content

Commit

Permalink
Revert "wafv2: Implement 'SchemaFunc()'."
Browse files Browse the repository at this point in the history
This reverts commit 39fc99f.
  • Loading branch information
ewbankkit committed Jun 28, 2023
1 parent 59cb145 commit 6b0e911
Show file tree
Hide file tree
Showing 10 changed files with 475 additions and 495 deletions.
118 changes: 58 additions & 60 deletions internal/service/wafv2/ip_set.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,71 +52,69 @@ func ResourceIPSet() *schema.Resource {
},
},

SchemaFunc: func() map[string]*schema.Schema {
return map[string]*schema.Schema{
"addresses": {
Type: schema.TypeSet,
Optional: true,
MaxItems: 10000,
Elem: &schema.Schema{Type: schema.TypeString},
DiffSuppressFunc: func(k, old, new string, d *schema.ResourceData) bool {
if d.GetRawPlan().GetAttr("addresses").IsWhollyKnown() {
o, n := d.GetChange("addresses")
oldAddresses := o.(*schema.Set).List()
newAddresses := n.(*schema.Set).List()
if len(oldAddresses) == len(newAddresses) {
for _, ov := range oldAddresses {
hasAddress := false
for _, nv := range newAddresses {
if itypes.CIDRBlocksEqual(ov.(string), nv.(string)) {
hasAddress = true
break
}
}
if !hasAddress {
return false
Schema: map[string]*schema.Schema{
"addresses": {
Type: schema.TypeSet,
Optional: true,
MaxItems: 10000,
Elem: &schema.Schema{Type: schema.TypeString},
DiffSuppressFunc: func(k, old, new string, d *schema.ResourceData) bool {
if d.GetRawPlan().GetAttr("addresses").IsWhollyKnown() {
o, n := d.GetChange("addresses")
oldAddresses := o.(*schema.Set).List()
newAddresses := n.(*schema.Set).List()
if len(oldAddresses) == len(newAddresses) {
for _, ov := range oldAddresses {
hasAddress := false
for _, nv := range newAddresses {
if itypes.CIDRBlocksEqual(ov.(string), nv.(string)) {
hasAddress = true
break
}
}
return true
if !hasAddress {
return false
}
}
return true
}
return false
},
},
"arn": {
Type: schema.TypeString,
Computed: true,
},
"description": {
Type: schema.TypeString,
Optional: true,
ValidateFunc: validation.StringLenBetween(1, 256),
},
"ip_address_version": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
ValidateFunc: validation.StringInSlice(wafv2.IPAddressVersion_Values(), false),
},
"lock_token": {
Type: schema.TypeString,
Computed: true,
},
"name": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
ValidateFunc: validation.StringLenBetween(1, 128),
},
"scope": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
ValidateFunc: validation.StringInSlice(wafv2.Scope_Values(), false),
}
return false
},
names.AttrTags: tftags.TagsSchema(),
names.AttrTagsAll: tftags.TagsSchemaComputed(),
}
},
"arn": {
Type: schema.TypeString,
Computed: true,
},
"description": {
Type: schema.TypeString,
Optional: true,
ValidateFunc: validation.StringLenBetween(1, 256),
},
"ip_address_version": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
ValidateFunc: validation.StringInSlice(wafv2.IPAddressVersion_Values(), false),
},
"lock_token": {
Type: schema.TypeString,
Computed: true,
},
"name": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
ValidateFunc: validation.StringLenBetween(1, 128),
},
"scope": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
ValidateFunc: validation.StringInSlice(wafv2.Scope_Values(), false),
},
names.AttrTags: tftags.TagsSchema(),
names.AttrTagsAll: tftags.TagsSchemaComputed(),
},

CustomizeDiff: verify.SetTagsDiff,
Expand Down
56 changes: 27 additions & 29 deletions internal/service/wafv2/ip_set_data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,35 +18,33 @@ func DataSourceIPSet() *schema.Resource {
return &schema.Resource{
ReadWithoutTimeout: dataSourceIPSetRead,

SchemaFunc: func() map[string]*schema.Schema {
return map[string]*schema.Schema{
"addresses": {
Type: schema.TypeSet,
Computed: true,
Elem: &schema.Schema{Type: schema.TypeString},
},
"arn": {
Type: schema.TypeString,
Computed: true,
},
"description": {
Type: schema.TypeString,
Computed: true,
},
"ip_address_version": {
Type: schema.TypeString,
Computed: true,
},
"name": {
Type: schema.TypeString,
Required: true,
},
"scope": {
Type: schema.TypeString,
Required: true,
ValidateFunc: validation.StringInSlice(wafv2.Scope_Values(), false),
},
}
Schema: map[string]*schema.Schema{
"addresses": {
Type: schema.TypeSet,
Computed: true,
Elem: &schema.Schema{Type: schema.TypeString},
},
"arn": {
Type: schema.TypeString,
Computed: true,
},
"description": {
Type: schema.TypeString,
Computed: true,
},
"ip_address_version": {
Type: schema.TypeString,
Computed: true,
},
"name": {
Type: schema.TypeString,
Required: true,
},
"scope": {
Type: schema.TypeString,
Required: true,
ValidateFunc: validation.StringInSlice(wafv2.Scope_Values(), false),
},
},
}
}
Expand Down
86 changes: 42 additions & 44 deletions internal/service/wafv2/regex_pattern_set.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,53 +50,51 @@ func ResourceRegexPatternSet() *schema.Resource {
},
},

SchemaFunc: func() map[string]*schema.Schema {
return map[string]*schema.Schema{
"arn": {
Type: schema.TypeString,
Computed: true,
},
"description": {
Type: schema.TypeString,
Optional: true,
ValidateFunc: validation.StringLenBetween(1, 256),
},
"lock_token": {
Type: schema.TypeString,
Computed: true,
},
"name": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
ValidateFunc: validation.StringLenBetween(1, 128),
},
"regular_expression": {
Type: schema.TypeSet,
Optional: true,
MaxItems: 10,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"regex_string": {
Type: schema.TypeString,
Required: true,
ValidateFunc: validation.All(
validation.StringLenBetween(1, 200),
validation.StringIsValidRegExp,
),
},
Schema: map[string]*schema.Schema{
"arn": {
Type: schema.TypeString,
Computed: true,
},
"description": {
Type: schema.TypeString,
Optional: true,
ValidateFunc: validation.StringLenBetween(1, 256),
},
"lock_token": {
Type: schema.TypeString,
Computed: true,
},
"name": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
ValidateFunc: validation.StringLenBetween(1, 128),
},
"regular_expression": {
Type: schema.TypeSet,
Optional: true,
MaxItems: 10,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"regex_string": {
Type: schema.TypeString,
Required: true,
ValidateFunc: validation.All(
validation.StringLenBetween(1, 200),
validation.StringIsValidRegExp,
),
},
},
},
"scope": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
ValidateFunc: validation.StringInSlice(wafv2.Scope_Values(), false),
},
names.AttrTags: tftags.TagsSchema(),
names.AttrTagsAll: tftags.TagsSchemaComputed(),
}
},
"scope": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
ValidateFunc: validation.StringInSlice(wafv2.Scope_Values(), false),
},
names.AttrTags: tftags.TagsSchema(),
names.AttrTagsAll: tftags.TagsSchemaComputed(),
},

CustomizeDiff: verify.SetTagsDiff,
Expand Down
56 changes: 27 additions & 29 deletions internal/service/wafv2/regex_pattern_set_data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,38 +17,36 @@ func DataSourceRegexPatternSet() *schema.Resource {
return &schema.Resource{
ReadWithoutTimeout: dataSourceRegexPatternSetRead,

SchemaFunc: func() map[string]*schema.Schema {
return map[string]*schema.Schema{
"arn": {
Type: schema.TypeString,
Computed: true,
},
"description": {
Type: schema.TypeString,
Computed: true,
},
"name": {
Type: schema.TypeString,
Required: true,
},
"regular_expression": {
Type: schema.TypeSet,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"regex_string": {
Type: schema.TypeString,
Computed: true,
},
Schema: map[string]*schema.Schema{
"arn": {
Type: schema.TypeString,
Computed: true,
},
"description": {
Type: schema.TypeString,
Computed: true,
},
"name": {
Type: schema.TypeString,
Required: true,
},
"regular_expression": {
Type: schema.TypeSet,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"regex_string": {
Type: schema.TypeString,
Computed: true,
},
},
},
"scope": {
Type: schema.TypeString,
Required: true,
ValidateFunc: validation.StringInSlice(wafv2.Scope_Values(), false),
},
}
},
"scope": {
Type: schema.TypeString,
Required: true,
ValidateFunc: validation.StringInSlice(wafv2.Scope_Values(), false),
},
},
}
}
Expand Down
Loading

0 comments on commit 6b0e911

Please sign in to comment.