mirror of
https://github.com/letic/terraform-provider-google.git
synced 2024-09-06 17:16:44 +00:00
![Christoph Tavan](/assets/img/avatar_default.png)
Adds support for log exclusions in billingAccounts, organizations, folders and projects, see: https://cloud.google.com/logging/docs/exclusions ``` ==> Checking that code complies with gofmt requirements... TF_ACC=1 go test ./google -v -run=Exclusion -timeout 120m === RUN TestAccLoggingBillingAccountExclusion_basic === PAUSE TestAccLoggingBillingAccountExclusion_basic === RUN TestAccLoggingBillingAccountExclusion_update === PAUSE TestAccLoggingBillingAccountExclusion_update === RUN TestAccLoggingFolderExclusion_basic === PAUSE TestAccLoggingFolderExclusion_basic === RUN TestAccLoggingFolderExclusion_folderAcceptsFullFolderPath === PAUSE TestAccLoggingFolderExclusion_folderAcceptsFullFolderPath === RUN TestAccLoggingFolderExclusion_update === PAUSE TestAccLoggingFolderExclusion_update === RUN TestAccLoggingOrganizationExclusion_basic === PAUSE TestAccLoggingOrganizationExclusion_basic === RUN TestAccLoggingOrganizationExclusion_update === PAUSE TestAccLoggingOrganizationExclusion_update === RUN TestAccLoggingProjectExclusion_basic === PAUSE TestAccLoggingProjectExclusion_basic === RUN TestAccLoggingProjectExclusion_disablePreservesFilter === PAUSE TestAccLoggingProjectExclusion_disablePreservesFilter === RUN TestAccLoggingProjectExclusion_update === PAUSE TestAccLoggingProjectExclusion_update === CONT TestAccLoggingBillingAccountExclusion_basic === CONT TestAccLoggingOrganizationExclusion_update === CONT TestAccLoggingProjectExclusion_update === CONT TestAccLoggingFolderExclusion_folderAcceptsFullFolderPath === CONT TestAccLoggingOrganizationExclusion_basic --- PASS: TestAccLoggingProjectExclusion_update (3.60s) --- PASS: TestAccLoggingOrganizationExclusion_update (4.40s) === CONT TestAccLoggingFolderExclusion_update --- PASS: TestAccLoggingOrganizationExclusion_basic (1.90s) === CONT TestAccLoggingFolderExclusion_basic --- PASS: TestAccLoggingBillingAccountExclusion_basic (6.21s) === CONT TestAccLoggingBillingAccountExclusion_update --- PASS: TestAccLoggingBillingAccountExclusion_update (5.90s) === CONT TestAccLoggingProjectExclusion_disablePreservesFilter --- PASS: TestAccLoggingProjectExclusion_disablePreservesFilter (3.90s) === CONT TestAccLoggingProjectExclusion_basic --- PASS: TestAccLoggingFolderExclusion_folderAcceptsFullFolderPath (16.67s) --- PASS: TestAccLoggingProjectExclusion_basic (1.96s) --- PASS: TestAccLoggingFolderExclusion_basic (15.30s) --- PASS: TestAccLoggingFolderExclusion_update (18.35s) PASS ok github.com/terraform-providers/terraform-provider-google/google 22.810s ```
103 lines
2.9 KiB
Go
103 lines
2.9 KiB
Go
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)
|
|
}
|