forked from hashicorp/terraform-provider-aws
/
resource_aws_media_store_container_policy.go
103 lines (87 loc) · 2.73 KB
/
resource_aws_media_store_container_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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
package aws
import (
"log"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/mediastore"
"github.com/hashicorp/terraform/helper/schema"
)
func resourceAwsMediaStoreContainerPolicy() *schema.Resource {
return &schema.Resource{
Create: resourceAwsMediaStoreContainerPolicyPut,
Read: resourceAwsMediaStoreContainerPolicyRead,
Update: resourceAwsMediaStoreContainerPolicyPut,
Delete: resourceAwsMediaStoreContainerPolicyDelete,
Importer: &schema.ResourceImporter{
State: schema.ImportStatePassthrough,
},
Schema: map[string]*schema.Schema{
"container_name": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
},
"policy": {
Type: schema.TypeString,
Required: true,
ValidateFunc: validateIAMPolicyJson,
DiffSuppressFunc: suppressEquivalentAwsPolicyDiffs,
},
},
}
}
func resourceAwsMediaStoreContainerPolicyPut(d *schema.ResourceData, meta interface{}) error {
conn := meta.(*AWSClient).mediastoreconn
input := &mediastore.PutContainerPolicyInput{
ContainerName: aws.String(d.Get("container_name").(string)),
Policy: aws.String(d.Get("policy").(string)),
}
_, err := conn.PutContainerPolicy(input)
if err != nil {
return err
}
d.SetId(d.Get("container_name").(string))
return resourceAwsMediaStoreContainerPolicyRead(d, meta)
}
func resourceAwsMediaStoreContainerPolicyRead(d *schema.ResourceData, meta interface{}) error {
conn := meta.(*AWSClient).mediastoreconn
input := &mediastore.GetContainerPolicyInput{
ContainerName: aws.String(d.Id()),
}
resp, err := conn.GetContainerPolicy(input)
if err != nil {
if isAWSErr(err, mediastore.ErrCodeContainerNotFoundException, "") {
log.Printf("[WARN] MediaContainer Policy %q not found, removing from state", d.Id())
d.SetId("")
return nil
}
if isAWSErr(err, mediastore.ErrCodePolicyNotFoundException, "") {
log.Printf("[WARN] MediaContainer Policy %q not found, removing from state", d.Id())
d.SetId("")
return nil
}
return err
}
d.Set("container_name", d.Id())
d.Set("policy", resp.Policy)
return nil
}
func resourceAwsMediaStoreContainerPolicyDelete(d *schema.ResourceData, meta interface{}) error {
conn := meta.(*AWSClient).mediastoreconn
input := &mediastore.DeleteContainerPolicyInput{
ContainerName: aws.String(d.Id()),
}
_, err := conn.DeleteContainerPolicy(input)
if err != nil {
if isAWSErr(err, mediastore.ErrCodeContainerNotFoundException, "") {
return nil
}
if isAWSErr(err, mediastore.ErrCodePolicyNotFoundException, "") {
return nil
}
// if isAWSErr(err, mediastore.ErrCodeContainerInUseException, "Container must be ACTIVE in order to perform this operation") {
// return nil
// }
return err
}
return nil
}