driftctl/test/resource/resource.go

86 lines
1.8 KiB
Go
Raw Normal View History

package resource
2021-03-25 11:13:52 +00:00
import (
"fmt"
2021-03-26 08:44:55 +00:00
"github.com/cloudskiff/driftctl/pkg/resource"
"github.com/cloudskiff/driftctl/test/schemas"
"github.com/hashicorp/terraform/providers"
2021-03-25 11:13:52 +00:00
"github.com/zclconf/go-cty/cty"
)
type FakeResource struct {
2021-03-25 11:13:52 +00:00
Id string `cty:"id"`
FooBar string `cty:"foo_bar"`
BarFoo string `cty:"bar_foo" computed:"true"`
Json string `cty:"json" jsonstring:"true"`
Type string
2021-03-25 11:13:52 +00:00
Tags map[string]string `cty:"tags"`
CustomMap map[string]struct {
2021-03-25 11:13:52 +00:00
Tag string `cty:"tag"`
} `cty:"custom_map"`
Slice []string `cty:"slice"`
2020-12-18 14:28:46 +00:00
Struct struct {
2021-03-25 11:13:52 +00:00
Baz string `cty:"baz" computed:"true"`
Bar string `cty:"bar"`
} `cty:"struct"`
2020-12-16 12:02:02 +00:00
StructSlice []struct {
2021-03-25 11:13:52 +00:00
String string `cty:"string" computed:"true"`
Array []string `cty:"array" computed:"true"`
} `cty:"struct_slice"`
CtyVal *cty.Value `diff:"-"`
}
func (d FakeResource) TerraformId() string {
return d.Id
}
func (d FakeResource) TerraformType() string {
if d.Type != "" {
return d.Type
}
return "FakeResource"
}
2021-03-25 11:13:52 +00:00
func (r FakeResource) CtyValue() *cty.Value {
return r.CtyVal
}
type FakeResourceStringer struct {
2021-03-25 11:13:52 +00:00
Id string
Name string
CtyVal *cty.Value `diff:"-"`
}
func (d *FakeResourceStringer) TerraformId() string {
return d.Id
}
func (d *FakeResourceStringer) TerraformType() string {
return "FakeResourceStringer"
}
2021-03-25 11:13:52 +00:00
func (r *FakeResourceStringer) CtyValue() *cty.Value {
return r.CtyVal
}
func (d *FakeResourceStringer) String() string {
return fmt.Sprintf("Name: '%s'", d.Name)
}
2021-03-26 08:44:55 +00:00
func InitFakeSchemaRepository(provider, version string) resource.SchemaRepositoryInterface {
repo := resource.NewSchemaRepository()
schema := make(map[string]providers.Schema)
if provider != "" {
s, err := schemas.ReadTestSchema(provider, version)
if err != nil {
// TODO HANDLER ERROR PROPERLY
panic(err)
}
schema = s
}
repo.Init(schema)
return repo
}