-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow to inject definitions of resource type outside from package
- Loading branch information
1 parent
f8dbf09
commit 9575027
Showing
3 changed files
with
56 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package aws | ||
|
||
import "github.com/minamijoyo/tfedit/migration/schema" | ||
|
||
func init() { | ||
RegisterSchema() | ||
} | ||
|
||
func RegisterSchema() { | ||
importIDMap := map[string]schema.ImportIDFunc{ | ||
"aws_s3_bucket_acl": func(r schema.Resource) string { | ||
return r["bucket"].(string) + "," + r["acl"].(string) | ||
}, | ||
} | ||
|
||
for k, v := range importIDMap { | ||
schema.RegisterImportIDFunc(k, v) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package schema | ||
|
||
type Resource map[string]interface{} | ||
type ImportIDFunc func(r Resource) string | ||
|
||
type Dictionary struct { | ||
importIDMap map[string]ImportIDFunc | ||
} | ||
|
||
func NewDictionary() *Dictionary { | ||
return &Dictionary{ | ||
importIDMap: make(map[string]ImportIDFunc), | ||
} | ||
} | ||
|
||
func (d *Dictionary) RegisterImportIDFunc(resourceType string, f ImportIDFunc) { | ||
d.importIDMap[resourceType] = f | ||
} | ||
|
||
func (d *Dictionary) ImportID(resourceType string, r Resource) string { | ||
f := d.importIDMap[resourceType] | ||
return f(r) | ||
} | ||
|
||
var defaultDictionary = NewDictionary() | ||
|
||
func RegisterImportIDFunc(resourceType string, f ImportIDFunc) { | ||
defaultDictionary.RegisterImportIDFunc(resourceType, f) | ||
} | ||
|
||
func ImportID(resourceType string, r Resource) string { | ||
return defaultDictionary.ImportID(resourceType, r) | ||
} |