2020-12-09 15:31:34 +00:00
|
|
|
package aws
|
|
|
|
|
2021-04-29 10:32:02 +00:00
|
|
|
import (
|
|
|
|
"github.com/cloudskiff/driftctl/pkg/resource"
|
2021-06-14 09:26:47 +00:00
|
|
|
"github.com/hashicorp/go-version"
|
2021-04-29 10:32:02 +00:00
|
|
|
)
|
2021-03-25 11:13:52 +00:00
|
|
|
|
2020-12-09 15:31:34 +00:00
|
|
|
const AwsInstanceResourceType = "aws_instance"
|
|
|
|
|
2021-04-29 10:32:02 +00:00
|
|
|
func initAwsInstanceMetaData(resourceSchemaRepository resource.SchemaRepositoryInterface) {
|
2021-08-09 14:03:04 +00:00
|
|
|
resourceSchemaRepository.SetNormalizeFunc(AwsInstanceResourceType, func(res *resource.Resource) {
|
2021-05-24 15:19:06 +00:00
|
|
|
val := res.Attrs
|
2021-04-29 10:32:02 +00:00
|
|
|
val.SafeDelete([]string{"timeouts"})
|
2021-06-14 09:26:47 +00:00
|
|
|
|
|
|
|
if v, _ := version.NewVersion("3.38.0"); res.Schema().ProviderVersion.LessThan(v) {
|
|
|
|
val.SafeDelete([]string{"instance_initiated_shutdown_behavior"})
|
|
|
|
}
|
2021-04-29 10:32:02 +00:00
|
|
|
})
|
2021-08-09 14:03:04 +00:00
|
|
|
resourceSchemaRepository.SetHumanReadableAttributesFunc(AwsInstanceResourceType, func(res *resource.Resource) map[string]string {
|
2021-05-21 14:09:45 +00:00
|
|
|
val := res.Attrs
|
|
|
|
attrs := make(map[string]string)
|
2021-06-02 10:01:55 +00:00
|
|
|
if tags := val.GetMap("tags"); tags != nil {
|
2021-07-27 08:44:52 +00:00
|
|
|
if name, ok := tags["Name"]; ok {
|
2021-06-02 10:01:55 +00:00
|
|
|
attrs["Name"] = name.(string)
|
2021-05-21 14:09:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return attrs
|
|
|
|
})
|
2021-09-17 15:16:06 +00:00
|
|
|
resourceSchemaRepository.SetFlags(AwsInstanceResourceType, resource.FlagDeepMode)
|
2021-04-29 10:32:02 +00:00
|
|
|
}
|