Skip to content

Commit

Permalink
Support helper/schema.Resource *WithoutTimeout fields in terraformtyp…
Browse files Browse the repository at this point in the history
…e and xpasses/XR006
  • Loading branch information
bflad committed Mar 25, 2021
1 parent d733591 commit 7c1c55c
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 22 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
# v0.25.0

ENHANCEMENTS

* helper/terraformtype/helper/schema: Add constants for new `Resource` type `CreateWithoutTimeout`, `DeleteWithoutTimeout`, `ReadWithoutTimeout`, and `DeleteWithoutTimeout` fields
* xpasses/XR006: Support `CreateWithoutTimeout`, `DeleteWithoutTimeout`, `ReadWithoutTimeout`, and `DeleteWithoutTimeout`

# v0.24.0

FEATURES
Expand Down
40 changes: 22 additions & 18 deletions helper/terraformtype/helper/schema/type_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,28 @@ import (
)

const (
ResourceFieldCreate = `Create`
ResourceFieldCreateContext = `CreateContext`
ResourceFieldCustomizeDiff = `CustomizeDiff`
ResourceFieldDelete = `Delete`
ResourceFieldDeleteContext = `DeleteContext`
ResourceFieldDeprecationMessage = `DeprecationMessage`
ResourceFieldDescription = `Description`
ResourceFieldExists = `Exists`
ResourceFieldImporter = `Importer`
ResourceFieldMigrateState = `MigrateState`
ResourceFieldRead = `Read`
ResourceFieldReadContext = `ReadContext`
ResourceFieldSchema = `Schema`
ResourceFieldSchemaVersion = `SchemaVersion`
ResourceFieldStateUpgraders = `StateUpgraders`
ResourceFieldTimeouts = `Timeouts`
ResourceFieldUpdate = `Update`
ResourceFieldUpdateContext = `UpdateContext`
ResourceFieldCreate = `Create`
ResourceFieldCreateContext = `CreateContext`
ResourceFieldCreateWithoutTimeout = `CreateWithoutTimeout`
ResourceFieldCustomizeDiff = `CustomizeDiff`
ResourceFieldDelete = `Delete`
ResourceFieldDeleteContext = `DeleteContext`
ResourceFieldDeleteWithoutTimeout = `DeleteWithoutTimeout`
ResourceFieldDeprecationMessage = `DeprecationMessage`
ResourceFieldDescription = `Description`
ResourceFieldExists = `Exists`
ResourceFieldImporter = `Importer`
ResourceFieldMigrateState = `MigrateState`
ResourceFieldRead = `Read`
ResourceFieldReadContext = `ReadContext`
ResourceFieldReadWithoutTimeout = `ReadWithoutTimeout`
ResourceFieldSchema = `Schema`
ResourceFieldSchemaVersion = `SchemaVersion`
ResourceFieldStateUpgraders = `StateUpgraders`
ResourceFieldTimeouts = `Timeouts`
ResourceFieldUpdate = `Update`
ResourceFieldUpdateContext = `UpdateContext`
ResourceFieldUpdateWithoutTimeout = `UpdateWithoutTimeout`

TypeNameResource = `Resource`
)
Expand Down
8 changes: 4 additions & 4 deletions xpasses/XR006/XR006.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,19 +32,19 @@ func run(pass *analysis.Pass) (interface{}, error) {
continue
}

if !resource.DeclaresField(schema.ResourceFieldCreate) && !resource.DeclaresField(schema.ResourceFieldCreateContext) && resource.Resource.Timeouts.Create != nil {
if !resource.DeclaresField(schema.ResourceFieldCreate) && !resource.DeclaresField(schema.ResourceFieldCreateContext) && !resource.DeclaresField(schema.ResourceFieldCreateWithoutTimeout) && resource.Resource.Timeouts.Create != nil {
pass.Reportf(resource.AstCompositeLit.Pos(), "%s: resource should not configure Timeouts.Create without Create implementation", analyzerName)
}

if !resource.DeclaresField(schema.ResourceFieldDelete) && !resource.DeclaresField(schema.ResourceFieldDeleteContext) && resource.Resource.Timeouts.Delete != nil {
if !resource.DeclaresField(schema.ResourceFieldDelete) && !resource.DeclaresField(schema.ResourceFieldDeleteContext) && !resource.DeclaresField(schema.ResourceFieldDeleteWithoutTimeout) && resource.Resource.Timeouts.Delete != nil {
pass.Reportf(resource.AstCompositeLit.Pos(), "%s: resource should not configure Timeouts.Delete without Delete implementation", analyzerName)
}

if !resource.DeclaresField(schema.ResourceFieldRead) && !resource.DeclaresField(schema.ResourceFieldReadContext) && resource.Resource.Timeouts.Read != nil {
if !resource.DeclaresField(schema.ResourceFieldRead) && !resource.DeclaresField(schema.ResourceFieldReadContext) && !resource.DeclaresField(schema.ResourceFieldReadWithoutTimeout) && resource.Resource.Timeouts.Read != nil {
pass.Reportf(resource.AstCompositeLit.Pos(), "%s: resource should not configure Timeouts.Read without Read implementation", analyzerName)
}

if !resource.DeclaresField(schema.ResourceFieldUpdate) && !resource.DeclaresField(schema.ResourceFieldUpdateContext) && resource.Resource.Timeouts.Update != nil {
if !resource.DeclaresField(schema.ResourceFieldUpdate) && !resource.DeclaresField(schema.ResourceFieldUpdateContext) && !resource.DeclaresField(schema.ResourceFieldUpdateWithoutTimeout) && resource.Resource.Timeouts.Update != nil {
pass.Reportf(resource.AstCompositeLit.Pos(), "%s: resource should not configure Timeouts.Update without Update implementation", analyzerName)
}
}
Expand Down
28 changes: 28 additions & 0 deletions xpasses/XR006/testdata/src/a/main_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,34 @@ func f_v2() {
Update: schema.DefaultTimeout(time.Minute),
},
}

_ = schema.Resource{
CreateWithoutTimeout: createContextFunc_v2,
Timeouts: &schema.ResourceTimeout{
Create: schema.DefaultTimeout(time.Minute),
},
}

_ = schema.Resource{
DeleteWithoutTimeout: deleteContextFunc_v2,
Timeouts: &schema.ResourceTimeout{
Delete: schema.DefaultTimeout(time.Minute),
},
}

_ = schema.Resource{
ReadWithoutTimeout: readContextFunc_v2,
Timeouts: &schema.ResourceTimeout{
Read: schema.DefaultTimeout(time.Minute),
},
}

_ = schema.Resource{
UpdateWithoutTimeout: updateContextFunc_v2,
Timeouts: &schema.ResourceTimeout{
Update: schema.DefaultTimeout(time.Minute),
},
}
}

func createFunc_v2(d *schema.ResourceData, meta interface{}) error {
Expand Down

0 comments on commit 7c1c55c

Please sign in to comment.