driftctl/pkg/resource/aws/aws_iam_policy.go

27 lines
875 B
Go
Raw Normal View History

package aws
2021-05-07 15:47:53 +00:00
import (
2021-12-06 13:29:39 +00:00
"github.com/snyk/driftctl/pkg/helpers"
"github.com/snyk/driftctl/pkg/resource"
2021-05-07 15:47:53 +00:00
)
2021-03-25 11:13:52 +00:00
const AwsIamPolicyResourceType = "aws_iam_policy"
2021-05-07 15:47:53 +00:00
func initAwsIAMPolicyMetaData(resourceSchemaRepository resource.SchemaRepositoryInterface) {
resourceSchemaRepository.UpdateSchema(AwsIamPolicyResourceType, map[string]func(attributeSchema *resource.AttributeSchema){
"policy": func(attributeSchema *resource.AttributeSchema) {
attributeSchema.JsonString = true
},
})
2021-08-09 14:03:04 +00:00
resourceSchemaRepository.SetNormalizeFunc(AwsIamPolicyResourceType, func(res *resource.Resource) {
val := res.Attrs
2021-05-07 15:47:53 +00:00
jsonString, err := helpers.NormalizeJsonString((*val)["policy"])
if err == nil {
2021-05-21 14:09:45 +00:00
_ = val.SafeSet([]string{"policy"}, jsonString)
2021-05-07 15:47:53 +00:00
}
val.SafeDelete([]string{"name_prefix"})
})
2021-09-17 15:16:06 +00:00
resourceSchemaRepository.SetFlags(AwsIamPolicyResourceType, resource.FlagDeepMode)
2021-05-07 15:47:53 +00:00
}