Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add google_logging_project_exclusion resource #990

Merged
merged 1 commit into from
May 18, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
95 changes: 95 additions & 0 deletions google/logging_exclusion_billing_account.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
package google

import (
"fmt"
"github.com/hashicorp/errwrap"
"github.com/hashicorp/terraform/helper/schema"
"google.golang.org/api/logging/v2"
)

var BillingAccountLoggingExclusionSchema = map[string]*schema.Schema{
"billing_account": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
},
}

type BillingAccountLoggingExclusionUpdater struct {
resourceType string
resourceId string
Config *Config
}

func NewBillingAccountLoggingExclusionUpdater(d *schema.ResourceData, config *Config) (ResourceLoggingExclusionUpdater, error) {
billingAccount := d.Get("billing_account").(string)

return &BillingAccountLoggingExclusionUpdater{
resourceType: "billingAccounts",
resourceId: billingAccount,
Config: config,
}, nil
}

func billingAccountLoggingExclusionIdParseFunc(d *schema.ResourceData, _ *Config) error {
loggingExclusionId, err := parseLoggingExclusionId(d.Id())
if err != nil {
return err
}

if "billingAccounts" != loggingExclusionId.resourceType {
return fmt.Errorf("Error importing logging exclusion, invalid resourceType %#v", loggingExclusionId.resourceType)
}

d.Set("billing_account", loggingExclusionId.resourceId)
return nil
}

func (u *BillingAccountLoggingExclusionUpdater) CreateLoggingExclusion(parent string, exclusion *logging.LogExclusion) error {
_, err := u.Config.clientLogging.BillingAccounts.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 *BillingAccountLoggingExclusionUpdater) ReadLoggingExclusion(id string) (*logging.LogExclusion, error) {
exclusion, err := u.Config.clientLogging.BillingAccounts.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 *BillingAccountLoggingExclusionUpdater) UpdateLoggingExclusion(id string, exclusion *logging.LogExclusion, updateMask string) error {
_, err := u.Config.clientLogging.BillingAccounts.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 *BillingAccountLoggingExclusionUpdater) DeleteLoggingExclusion(id string) error {
_, err := u.Config.clientLogging.BillingAccounts.Exclusions.Delete(id).Do()
if err != nil {
return errwrap.Wrap(fmt.Errorf("Error deleting logging exclusion for %s.", u.DescribeResource()), err)
}

return nil
}

func (u *BillingAccountLoggingExclusionUpdater) GetResourceType() string {
return u.resourceType
}

func (u *BillingAccountLoggingExclusionUpdater) GetResourceId() string {
return u.resourceId
}

func (u *BillingAccountLoggingExclusionUpdater) DescribeResource() string {
return fmt.Sprintf("%q %q", u.resourceType, u.resourceId)
}
96 changes: 96 additions & 0 deletions google/logging_exclusion_folder.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
package google

import (
"fmt"
"github.com/hashicorp/errwrap"
"github.com/hashicorp/terraform/helper/schema"
"google.golang.org/api/logging/v2"
)

var FolderLoggingExclusionSchema = map[string]*schema.Schema{
"folder": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
DiffSuppressFunc: optionalPrefixSuppress("folders/"),
},
}

type FolderLoggingExclusionUpdater struct {
resourceType string
resourceId string
Config *Config
}

func NewFolderLoggingExclusionUpdater(d *schema.ResourceData, config *Config) (ResourceLoggingExclusionUpdater, error) {
folder := parseFolderId(d.Get("folder"))

return &FolderLoggingExclusionUpdater{
resourceType: "folders",
resourceId: folder,
Config: config,
}, nil
}

func folderLoggingExclusionIdParseFunc(d *schema.ResourceData, _ *Config) error {
loggingExclusionId, err := parseLoggingExclusionId(d.Id())
if err != nil {
return err
}

if "folders" != loggingExclusionId.resourceType {
return fmt.Errorf("Error importing logging exclusion, invalid resourceType %#v", loggingExclusionId.resourceType)
}

d.Set("folder", loggingExclusionId.resourceId)
return nil
}

func (u *FolderLoggingExclusionUpdater) CreateLoggingExclusion(parent string, exclusion *logging.LogExclusion) error {
_, err := u.Config.clientLogging.Folders.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 *FolderLoggingExclusionUpdater) ReadLoggingExclusion(id string) (*logging.LogExclusion, error) {
exclusion, err := u.Config.clientLogging.Folders.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 *FolderLoggingExclusionUpdater) UpdateLoggingExclusion(id string, exclusion *logging.LogExclusion, updateMask string) error {
_, err := u.Config.clientLogging.Folders.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 *FolderLoggingExclusionUpdater) DeleteLoggingExclusion(id string) error {
_, err := u.Config.clientLogging.Folders.Exclusions.Delete(id).Do()
if err != nil {
return errwrap.Wrap(fmt.Errorf("Error deleting logging exclusion for %s.", u.DescribeResource()), err)
}

return nil
}

func (u *FolderLoggingExclusionUpdater) GetResourceType() string {
return u.resourceType
}

func (u *FolderLoggingExclusionUpdater) GetResourceId() string {
return u.resourceId
}

func (u *FolderLoggingExclusionUpdater) DescribeResource() string {
return fmt.Sprintf("%q %q", u.resourceType, u.resourceId)
}
95 changes: 95 additions & 0 deletions google/logging_exclusion_organization.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
package google

import (
"fmt"
"github.com/hashicorp/errwrap"
"github.com/hashicorp/terraform/helper/schema"
"google.golang.org/api/logging/v2"
)

var OrganizationLoggingExclusionSchema = map[string]*schema.Schema{
"org_id": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
},
}

type OrganizationLoggingExclusionUpdater struct {
resourceType string
resourceId string
Config *Config
}

func NewOrganizationLoggingExclusionUpdater(d *schema.ResourceData, config *Config) (ResourceLoggingExclusionUpdater, error) {
organization := d.Get("org_id").(string)

return &OrganizationLoggingExclusionUpdater{
resourceType: "organizations",
resourceId: organization,
Config: config,
}, nil
}

func organizationLoggingExclusionIdParseFunc(d *schema.ResourceData, _ *Config) error {
loggingExclusionId, err := parseLoggingExclusionId(d.Id())
if err != nil {
return err
}

if "organizations" != loggingExclusionId.resourceType {
return fmt.Errorf("Error importing logging exclusion, invalid resourceType %#v", loggingExclusionId.resourceType)
}

d.Set("org_id", loggingExclusionId.resourceId)
return nil
}

func (u *OrganizationLoggingExclusionUpdater) CreateLoggingExclusion(parent string, exclusion *logging.LogExclusion) error {
_, err := u.Config.clientLogging.Organizations.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 *OrganizationLoggingExclusionUpdater) ReadLoggingExclusion(id string) (*logging.LogExclusion, error) {
exclusion, err := u.Config.clientLogging.Organizations.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 *OrganizationLoggingExclusionUpdater) UpdateLoggingExclusion(id string, exclusion *logging.LogExclusion, updateMask string) error {
_, err := u.Config.clientLogging.Organizations.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 *OrganizationLoggingExclusionUpdater) DeleteLoggingExclusion(id string) error {
_, err := u.Config.clientLogging.Organizations.Exclusions.Delete(id).Do()
if err != nil {
return errwrap.Wrap(fmt.Errorf("Error deleting logging exclusion for %s.", u.DescribeResource()), err)
}

return nil
}

func (u *OrganizationLoggingExclusionUpdater) GetResourceType() string {
return u.resourceType
}

func (u *OrganizationLoggingExclusionUpdater) GetResourceId() string {
return u.resourceId
}

func (u *OrganizationLoggingExclusionUpdater) DescribeResource() string {
return fmt.Sprintf("%q %q", u.resourceType, u.resourceId)
}
102 changes: 102 additions & 0 deletions google/logging_exclusion_project.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,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)
}
Loading