-
Notifications
You must be signed in to change notification settings - Fork 23
/
assume_role_policy.go
53 lines (43 loc) · 1.5 KB
/
assume_role_policy.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package main
import (
"context"
"fmt"
"strings"
awspolicy "github.com/hashicorp/awspolicyequivalence"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)
type TrustPolicyDocument struct {
Version string `json:",omitempty"`
Id string `json:",omitempty"`
Statements interface{} `json:"Statement"`
}
func SuppressEquivalentTrustPolicyDiffs(key string, old string, new string, d *schema.ResourceData) bool {
if strings.TrimSpace(old) == "" && strings.TrimSpace(new) == "" {
return true
}
if strings.TrimSpace(old) == "{}" && strings.TrimSpace(new) == "" {
return true
}
if strings.TrimSpace(old) == "" && strings.TrimSpace(new) == "{}" {
return true
}
if strings.TrimSpace(old) == "{}" && strings.TrimSpace(new) == "{}" {
return true
}
equivalent, err := awspolicy.PoliciesAreEquivalent(old, new)
if err != nil {
return false
}
return equivalent
}
// Using a diff function is the currently accepted way to compare the configuration of two different attributes at plan time.
func trustPoliciesWithIncludeDefaultPolicies(_ context.Context, diff *schema.ResourceDiff, meta interface{}) error {
var assumeRolePolicy = diff.Get("assume_role_policy")
var includeDefaultPolicies = (diff.Get("include_default_policies").(bool))
if (assumeRolePolicy != nil) && (assumeRolePolicy != "") {
if includeDefaultPolicies {
return fmt.Errorf("include_default_policies must be false or excluded if including an assume_role_policy %#v", assumeRolePolicy)
}
}
return nil
}