2021-02-04 15:11:51 +00:00
|
|
|
package aws
|
|
|
|
|
2021-05-03 16:41:25 +00:00
|
|
|
import (
|
2021-05-18 15:06:11 +00:00
|
|
|
"github.com/cloudskiff/driftctl/pkg/helpers"
|
2021-05-03 16:41:25 +00:00
|
|
|
"github.com/cloudskiff/driftctl/pkg/resource"
|
|
|
|
)
|
2021-03-25 11:13:52 +00:00
|
|
|
|
2021-02-04 15:11:51 +00:00
|
|
|
const AwsSnsTopicPolicyResourceType = "aws_sns_topic_policy"
|
|
|
|
|
2021-05-03 16:41:25 +00:00
|
|
|
func initSnsTopicPolicyMetaData(resourceSchemaRepository resource.SchemaRepositoryInterface) {
|
2021-08-09 15:15:35 +00:00
|
|
|
resourceSchemaRepository.SetResolveReadAttributesFunc(AwsSnsTopicPolicyResourceType, func(res *resource.Resource) map[string]string {
|
|
|
|
return map[string]string{
|
2021-08-18 13:58:28 +00:00
|
|
|
"topic_arn": res.ResourceId(),
|
2021-08-09 15:15:35 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2021-05-03 16:41:25 +00:00
|
|
|
resourceSchemaRepository.UpdateSchema(AwsSnsTopicPolicyResourceType, map[string]func(attributeSchema *resource.AttributeSchema){
|
|
|
|
"policy": func(attributeSchema *resource.AttributeSchema) {
|
|
|
|
attributeSchema.JsonString = true
|
|
|
|
},
|
|
|
|
})
|
2021-05-18 15:06:11 +00:00
|
|
|
|
2021-08-09 14:03:04 +00:00
|
|
|
resourceSchemaRepository.SetNormalizeFunc(AwsSnsTopicPolicyResourceType, func(res *resource.Resource) {
|
2021-05-24 15:19:06 +00:00
|
|
|
val := res.Attrs
|
2021-06-17 13:39:26 +00:00
|
|
|
val.SafeDelete([]string{"owner"})
|
2021-05-18 15:06:11 +00:00
|
|
|
jsonString, err := helpers.NormalizeJsonString((*val)["policy"])
|
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
2021-05-21 14:09:45 +00:00
|
|
|
_ = val.SafeSet([]string{"policy"}, jsonString)
|
2021-05-18 15:06:11 +00:00
|
|
|
})
|
2021-05-03 16:41:25 +00:00
|
|
|
}
|