2020-12-09 15:31:34 +00:00
|
|
|
package resource
|
|
|
|
|
2021-03-25 11:13:52 +00:00
|
|
|
import (
|
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
|
|
|
)
|
2020-12-09 15:31:34 +00:00
|
|
|
|
|
|
|
type FakeResource struct {
|
2021-05-21 14:09:45 +00:00
|
|
|
Id string
|
|
|
|
Type string
|
|
|
|
Attrs *resource.Attributes
|
2020-12-09 15:31:34 +00:00
|
|
|
}
|
|
|
|
|
2021-05-21 14:09:45 +00:00
|
|
|
func (d *FakeResource) Schema() *resource.Schema {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (d *FakeResource) TerraformId() string {
|
2020-12-09 15:31:34 +00:00
|
|
|
return d.Id
|
|
|
|
}
|
|
|
|
|
2021-05-21 14:09:45 +00:00
|
|
|
func (d *FakeResource) TerraformType() string {
|
2020-12-09 15:31:34 +00:00
|
|
|
if d.Type != "" {
|
|
|
|
return d.Type
|
|
|
|
}
|
|
|
|
return "FakeResource"
|
|
|
|
}
|
|
|
|
|
2021-05-21 14:09:45 +00:00
|
|
|
func (d *FakeResource) Attributes() *resource.Attributes {
|
|
|
|
return d.Attrs
|
2021-03-25 11:13:52 +00:00
|
|
|
}
|
|
|
|
|
2021-08-03 08:26:38 +00:00
|
|
|
func (d *FakeResource) Src() resource.Source {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2020-12-09 15:31:34 +00:00
|
|
|
type FakeResourceStringer struct {
|
2021-08-03 08:26:38 +00:00
|
|
|
Id string
|
|
|
|
Attrs *resource.Attributes
|
|
|
|
Source resource.Source
|
2021-05-21 14:09:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (d *FakeResourceStringer) Schema() *resource.Schema {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2020-12-09 15:31:34 +00:00
|
|
|
func (d *FakeResourceStringer) TerraformId() string {
|
|
|
|
return d.Id
|
|
|
|
}
|
|
|
|
|
|
|
|
func (d *FakeResourceStringer) TerraformType() string {
|
|
|
|
return "FakeResourceStringer"
|
|
|
|
}
|
|
|
|
|
2021-05-21 14:09:45 +00:00
|
|
|
func (d *FakeResourceStringer) Attributes() *resource.Attributes {
|
|
|
|
return d.Attrs
|
2020-12-09 15:31:34 +00:00
|
|
|
}
|
2021-03-26 08:44:55 +00:00
|
|
|
|
2021-08-03 08:26:38 +00:00
|
|
|
func (d *FakeResourceStringer) Src() resource.Source {
|
|
|
|
return d.Source
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
}
|
2021-07-29 09:50:35 +00:00
|
|
|
_ = repo.Init("Fake", "1.0.0", schema)
|
2021-03-26 08:44:55 +00:00
|
|
|
return repo
|
|
|
|
}
|