forked from hashicorp/terraform-provider-google
-
Notifications
You must be signed in to change notification settings - Fork 0
/
logging_exclusion_project.go
102 lines (81 loc) · 2.85 KB
/
logging_exclusion_project.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
package google
import (
"fmt"
"github.com/hashicorp/errwrap"
"github.com/hashicorp/terraform/helper/schema"
"google.golang.org/api/logging/v2"
)
var ProjectLoggingExclusionSchema = map[string]*schema.Schema{
"project": {
Type: schema.TypeString,
Optional: true,
Computed: true,
ForceNew: true,
},
}
type ProjectLoggingExclusionUpdater struct {
resourceType string
resourceId string
Config *Config
}
func NewProjectLoggingExclusionUpdater(d *schema.ResourceData, config *Config) (ResourceLoggingExclusionUpdater, error) {
pid, err := getProject(d, config)
if err != nil {
return nil, err
}
return &ProjectLoggingExclusionUpdater{
resourceType: "projects",
resourceId: pid,
Config: config,
}, nil
}
func projectLoggingExclusionIdParseFunc(d *schema.ResourceData, config *Config) error {
loggingExclusionId, err := parseLoggingExclusionId(d.Id())
if err != nil {
return err
}
if "projects" != loggingExclusionId.resourceType {
return fmt.Errorf("Error importing logging exclusion, invalid resourceType %#v", loggingExclusionId.resourceType)
}
if config.Project != loggingExclusionId.resourceId {
d.Set("project", loggingExclusionId.resourceId)
}
return nil
}
func (u *ProjectLoggingExclusionUpdater) CreateLoggingExclusion(parent string, exclusion *logging.LogExclusion) error {
_, err := u.Config.clientLogging.Projects.Exclusions.Create(parent, exclusion).Do()
if err != nil {
return errwrap.Wrapf(fmt.Sprintf("Error creating logging exclusion for %s: {{err}}", u.DescribeResource()), err)
}
return nil
}
func (u *ProjectLoggingExclusionUpdater) ReadLoggingExclusion(id string) (*logging.LogExclusion, error) {
exclusion, err := u.Config.clientLogging.Projects.Exclusions.Get(id).Do()
if err != nil {
return nil, fmt.Errorf("Error retrieving logging exclusion for %s: %s", u.DescribeResource(), err)
}
return exclusion, nil
}
func (u *ProjectLoggingExclusionUpdater) UpdateLoggingExclusion(id string, exclusion *logging.LogExclusion, updateMask string) error {
_, err := u.Config.clientLogging.Projects.Exclusions.Patch(id, exclusion).UpdateMask(updateMask).Do()
if err != nil {
return errwrap.Wrapf(fmt.Sprintf("Error updating logging exclusion for %s: {{err}}", u.DescribeResource()), err)
}
return nil
}
func (u *ProjectLoggingExclusionUpdater) DeleteLoggingExclusion(id string) error {
_, err := u.Config.clientLogging.Projects.Exclusions.Delete(id).Do()
if err != nil {
return errwrap.Wrapf(fmt.Sprintf("Error deleting logging exclusion for %s: {{err}}", u.DescribeResource()), err)
}
return nil
}
func (u *ProjectLoggingExclusionUpdater) GetResourceType() string {
return u.resourceType
}
func (u *ProjectLoggingExclusionUpdater) GetResourceId() string {
return u.resourceId
}
func (u *ProjectLoggingExclusionUpdater) DescribeResource() string {
return fmt.Sprintf("%q %q", u.resourceType, u.resourceId)
}