diff --git a/.changelog/3400.txt b/.changelog/3400.txt new file mode 100644 index 00000000000..6d4f29a5a35 --- /dev/null +++ b/.changelog/3400.txt @@ -0,0 +1,12 @@ +```release-note:new-resource +`google_logging_folder_bucket_config` +``` +```release-note:new-resource +`google_logging_project_bucket_config` +``` +```release-note:new-resource +`google_logging_organization_bucket_config` +``` +```release-note:new-resource +`google_logging_billing_account_bucket_config` +``` diff --git a/google/provider.go b/google/provider.go index 77b9dd1504e..17594cb0ab2 100644 --- a/google/provider.go +++ b/google/provider.go @@ -787,12 +787,16 @@ func ResourceMapWithErrors() (map[string]*schema.Resource, error) { "google_healthcare_hl7_v2_store_iam_policy": ResourceIamPolicy(IamHealthcareHl7V2StoreSchema, NewHealthcareHl7V2StoreIamUpdater, Hl7V2StoreIdParseFunc), "google_logging_billing_account_sink": resourceLoggingBillingAccountSink(), "google_logging_billing_account_exclusion": ResourceLoggingExclusion(BillingAccountLoggingExclusionSchema, NewBillingAccountLoggingExclusionUpdater, billingAccountLoggingExclusionIdParseFunc), + "google_logging_billing_account_bucket_config": ResourceLoggingBillingAccountBucketConfig(), "google_logging_organization_sink": resourceLoggingOrganizationSink(), "google_logging_organization_exclusion": ResourceLoggingExclusion(OrganizationLoggingExclusionSchema, NewOrganizationLoggingExclusionUpdater, organizationLoggingExclusionIdParseFunc), + "google_logging_organization_bucket_config": ResourceLoggingOrganizationBucketConfig(), "google_logging_folder_sink": resourceLoggingFolderSink(), "google_logging_folder_exclusion": ResourceLoggingExclusion(FolderLoggingExclusionSchema, NewFolderLoggingExclusionUpdater, folderLoggingExclusionIdParseFunc), + "google_logging_folder_bucket_config": ResourceLoggingFolderBucketConfig(), "google_logging_project_sink": resourceLoggingProjectSink(), "google_logging_project_exclusion": ResourceLoggingExclusion(ProjectLoggingExclusionSchema, NewProjectLoggingExclusionUpdater, projectLoggingExclusionIdParseFunc), + "google_logging_project_bucket_config": ResourceLoggingProjectBucketConfig(), "google_kms_key_ring_iam_binding": ResourceIamBinding(IamKmsKeyRingSchema, NewKmsKeyRingIamUpdater, KeyRingIdParseFunc), "google_kms_key_ring_iam_member": ResourceIamMember(IamKmsKeyRingSchema, NewKmsKeyRingIamUpdater, KeyRingIdParseFunc), "google_kms_key_ring_iam_policy": ResourceIamPolicy(IamKmsKeyRingSchema, NewKmsKeyRingIamUpdater, KeyRingIdParseFunc), diff --git a/google/resource_logging_billing_account_bucket_config.go b/google/resource_logging_billing_account_bucket_config.go new file mode 100644 index 00000000000..ef78c3c8eb1 --- /dev/null +++ b/google/resource_logging_billing_account_bucket_config.go @@ -0,0 +1,34 @@ +package google + +import ( + "fmt" + "strings" + + "github.com/hashicorp/terraform-plugin-sdk/helper/schema" +) + +var loggingBillingAccountBucketConfigSchema = map[string]*schema.Schema{ + "billing_account": { + Type: schema.TypeString, + Required: true, + ForceNew: true, + }, +} + +func billingAccountBucketConfigID(d *schema.ResourceData, config *Config) (string, error) { + billingAccount := d.Get("billing_account").(string) + location := d.Get("location").(string) + bucketID := d.Get("bucket_id").(string) + + if !strings.HasPrefix(billingAccount, "billingAccounts") { + billingAccount = "billingAccounts/" + billingAccount + } + + id := fmt.Sprintf("%s/locations/%s/buckets/%s", billingAccount, location, bucketID) + return id, nil +} + +// Create Logging Bucket config +func ResourceLoggingBillingAccountBucketConfig() *schema.Resource { + return ResourceLoggingBucketConfig("billing_account", loggingBillingAccountBucketConfigSchema, billingAccountBucketConfigID) +} diff --git a/google/resource_logging_bucket_config.go b/google/resource_logging_bucket_config.go new file mode 100644 index 00000000000..1cbd6f44093 --- /dev/null +++ b/google/resource_logging_bucket_config.go @@ -0,0 +1,177 @@ +package google + +import ( + "fmt" + "log" + "regexp" + "strings" + + "github.com/hashicorp/terraform-plugin-sdk/helper/schema" +) + +var loggingBucketConfigSchema = map[string]*schema.Schema{ + "name": { + Type: schema.TypeString, + Computed: true, + }, + "location": { + Type: schema.TypeString, + Required: true, + ForceNew: true, + }, + "bucket_id": { + Type: schema.TypeString, + Required: true, + ForceNew: true, + }, + "description": { + Type: schema.TypeString, + Optional: true, + Computed: true, + }, + "retention_days": { + Type: schema.TypeInt, + Optional: true, + Default: 30, + }, + "lifecycle_state": { + Type: schema.TypeString, + Computed: true, + }, +} + +type loggingBucketConfigIDFunc func(d *schema.ResourceData, config *Config) (string, error) + +// ResourceLoggingBucketConfig creates a resource definition by merging a unique field (eg: folder) to a generic logging bucket +// config resource. In practice the only difference between these resources is the url location. +func ResourceLoggingBucketConfig(parentType string, parentSpecificSchema map[string]*schema.Schema, iDFunc loggingBucketConfigIDFunc) *schema.Resource { + return &schema.Resource{ + Create: resourceLoggingBucketConfigAcquire(iDFunc), + Read: resourceLoggingBucketConfigRead, + Update: resourceLoggingBucketConfigUpdate, + Delete: resourceLoggingBucketConfigDelete, + Importer: &schema.ResourceImporter{ + State: resourceLoggingBucketConfigImportState(parentType), + }, + Schema: mergeSchemas(loggingBucketConfigSchema, parentSpecificSchema), + } +} + +var loggingBucketConfigIDRegex = regexp.MustCompile("(.+)/(.+)/locations/(.+)/buckets/(.+)") + +func resourceLoggingBucketConfigImportState(parent string) schema.StateFunc { + return func(d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) { + parts := loggingBucketConfigIDRegex.FindStringSubmatch(d.Id()) + if parts == nil { + return nil, fmt.Errorf("unable to parse logging sink id %#v", d.Id()) + } + + if len(parts) != 5 { + return nil, fmt.Errorf("Invalid id format. Format should be '{{parent}}/{{parent_id}}/locations/{{location}}/buckets/{{bucket_id}} with parent in %s", loggingSinkResourceTypes) + } + + validLoggingType := false + for _, v := range loggingSinkResourceTypes { + if v == parts[1] { + validLoggingType = true + break + } + } + if !validLoggingType { + return nil, fmt.Errorf("Logging parent type %s is not valid. Valid resource types: %#v", parts[1], + loggingSinkResourceTypes) + } + + d.Set(parent, parts[1]+"/"+parts[2]) + + d.Set("location", parts[3]) + + d.Set("bucket_id", parts[4]) + + return []*schema.ResourceData{d}, nil + } +} + +func resourceLoggingBucketConfigAcquire(iDFunc loggingBucketConfigIDFunc) func(*schema.ResourceData, interface{}) error { + return func(d *schema.ResourceData, meta interface{}) error { + config := meta.(*Config) + + id, err := iDFunc(d, config) + if err != nil { + return err + } + + d.SetId(id) + + return resourceLoggingBucketConfigUpdate(d, meta) + } +} + +func resourceLoggingBucketConfigRead(d *schema.ResourceData, meta interface{}) error { + config := meta.(*Config) + + log.Printf("[DEBUG] Fetching logging bucket config: %#v", d.Id()) + + url, err := replaceVars(d, config, fmt.Sprintf("{{LoggingBasePath}}%s", d.Id())) + if err != nil { + return err + } + + res, err := sendRequest(config, "GET", "", url, nil) + if err != nil { + log.Printf("[WARN] Unable to acquire logging bucket config at %s", d.Id()) + + d.SetId("") + return err + } + + d.Set("name", res["name"]) + d.Set("description", res["description"]) + d.Set("lifecycle_state", res["lifecycleState"]) + d.Set("retention_days", res["retentionDays"]) + + return nil + +} + +func resourceLoggingBucketConfigUpdate(d *schema.ResourceData, meta interface{}) error { + config := meta.(*Config) + + obj := make(map[string]interface{}) + + url, err := replaceVars(d, config, fmt.Sprintf("{{LoggingBasePath}}%s", d.Id())) + if err != nil { + return err + } + + obj["retentionDays"] = d.Get("retention_days") + obj["description"] = d.Get("description") + + updateMask := []string{} + if d.HasChange("retention_days") { + updateMask = append(updateMask, "retentionDays") + } + if d.HasChange("description") { + updateMask = append(updateMask, "description") + } + url, err = addQueryParams(url, map[string]string{"updateMask": strings.Join(updateMask, ",")}) + if err != nil { + return err + } + + _, err = sendRequestWithTimeout(config, "PATCH", "", url, obj, d.Timeout(schema.TimeoutUpdate)) + if err != nil { + return fmt.Errorf("Error updating Logging Bucket Config %q: %s", d.Id(), err) + } + + return resourceLoggingBucketConfigRead(d, meta) + +} + +func resourceLoggingBucketConfigDelete(d *schema.ResourceData, meta interface{}) error { + + log.Printf("[WARN] Logging bucket configs cannot be deleted. Removing logging bucket config from state: %#v", d.Id()) + d.SetId("") + + return nil +} diff --git a/google/resource_logging_bucket_config_test.go b/google/resource_logging_bucket_config_test.go new file mode 100644 index 00000000000..048a6637476 --- /dev/null +++ b/google/resource_logging_bucket_config_test.go @@ -0,0 +1,215 @@ +package google + +import ( + "fmt" + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/helper/resource" +) + +func TestAccLoggingBucketConfigFolder_basic(t *testing.T) { + t.Parallel() + + context := map[string]interface{}{ + "random_suffix": randString(t, 10), + "folder_name": "tf-test-" + randString(t, 10), + "org_id": getTestOrgFromEnv(t), + } + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + Steps: []resource.TestStep{ + { + Config: testAccLoggingBucketConfigFolder_basic(context, 30), + }, + { + ResourceName: "google_logging_folder_bucket_config.basic", + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"folder"}, + }, + { + Config: testAccLoggingBucketConfigFolder_basic(context, 40), + }, + { + ResourceName: "google_logging_folder_bucket_config.basic", + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"folder"}, + }, + }, + }) +} + +func TestAccLoggingBucketConfigProject_basic(t *testing.T) { + t.Parallel() + + context := map[string]interface{}{ + "random_suffix": randString(t, 10), + "project_name": "tf-test-" + randString(t, 10), + "org_id": getTestOrgFromEnv(t), + } + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + Steps: []resource.TestStep{ + { + Config: testAccLoggingBucketConfigProject_basic(context, 30), + }, + { + ResourceName: "google_logging_project_bucket_config.basic", + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"project"}, + }, + { + Config: testAccLoggingBucketConfigProject_basic(context, 40), + }, + { + ResourceName: "google_logging_project_bucket_config.basic", + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"project"}, + }, + }, + }) +} + +func TestAccLoggingBucketConfigBillingAccount_basic(t *testing.T) { + t.Parallel() + + context := map[string]interface{}{ + "random_suffix": randString(t, 10), + "billing_account_name": "billingAccounts/" + getTestBillingAccountFromEnv(t), + "org_id": getTestOrgFromEnv(t), + } + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + Steps: []resource.TestStep{ + { + Config: testAccLoggingBucketConfigBillingAccount_basic(context, 30), + }, + { + ResourceName: "google_logging_billing_account_bucket_config.basic", + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"billing_account"}, + }, + { + Config: testAccLoggingBucketConfigBillingAccount_basic(context, 40), + }, + { + ResourceName: "google_logging_billing_account_bucket_config.basic", + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"billing_account"}, + }, + }, + }) +} + +func TestAccLoggingBucketConfigOrganization_basic(t *testing.T) { + t.Parallel() + + context := map[string]interface{}{ + "random_suffix": randString(t, 10), + "org_id": getTestOrgFromEnv(t), + } + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + Steps: []resource.TestStep{ + { + Config: testAccLoggingBucketConfigOrganization_basic(context, 30), + }, + { + ResourceName: "google_logging_organization_bucket_config.basic", + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"organization"}, + }, + { + Config: testAccLoggingBucketConfigOrganization_basic(context, 40), + }, + { + ResourceName: "google_logging_organization_bucket_config.basic", + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"organization"}, + }, + }, + }) +} + +func testAccLoggingBucketConfigFolder_basic(context map[string]interface{}, retention int) string { + return fmt.Sprintf(Nprintf(` +resource "google_folder" "default" { + display_name = "%{folder_name}" + parent = "organizations/%{org_id}" +} + +resource "google_logging_folder_bucket_config" "basic" { + folder = google_folder.default.name + location = "global" + retention_days = %d + description = "retention test %d days" + bucket_id = "_Default" +} +`, context), retention, retention) +} + +func testAccLoggingBucketConfigProject_basic(context map[string]interface{}, retention int) string { + return fmt.Sprintf(Nprintf(` +resource "google_project" "default" { + project_id = "%{project_name}" + name = "%{project_name}" + org_id = "%{org_id}" +} + +resource "google_logging_project_bucket_config" "basic" { + project = google_project.default.name + location = "global" + retention_days = %d + description = "retention test %d days" + bucket_id = "_Default" +} +`, context), retention, retention) +} + +func testAccLoggingBucketConfigBillingAccount_basic(context map[string]interface{}, retention int) string { + return fmt.Sprintf(Nprintf(` + +data "google_billing_account" "default" { + billing_account = "%{billing_account_name}" +} + +resource "google_logging_billing_account_bucket_config" "basic" { + billing_account = data.google_billing_account.default.billing_account + location = "global" + retention_days = %d + description = "retention test %d days" + bucket_id = "_Default" +} +`, context), retention, retention) +} + +func testAccLoggingBucketConfigOrganization_basic(context map[string]interface{}, retention int) string { + return fmt.Sprintf(Nprintf(` +data "google_organization" "default" { + organization = "%{org_id}" +} + +resource "google_logging_organization_bucket_config" "basic" { + organization = data.google_organization.default.organization + location = "global" + retention_days = %d + description = "retention test %d days" + bucket_id = "_Default" +} +`, context), retention, retention) +} diff --git a/google/resource_logging_folder_bucket_config.go b/google/resource_logging_folder_bucket_config.go new file mode 100644 index 00000000000..40603fdd9d3 --- /dev/null +++ b/google/resource_logging_folder_bucket_config.go @@ -0,0 +1,34 @@ +package google + +import ( + "fmt" + "strings" + + "github.com/hashicorp/terraform-plugin-sdk/helper/schema" +) + +var loggingFolderBucketConfigSchema = map[string]*schema.Schema{ + "folder": { + Type: schema.TypeString, + Required: true, + ForceNew: true, + }, +} + +func folderBucketConfigID(d *schema.ResourceData, config *Config) (string, error) { + folder := d.Get("folder").(string) + location := d.Get("location").(string) + bucketID := d.Get("bucket_id").(string) + + if !strings.HasPrefix(folder, "folder") { + folder = "folders/" + folder + } + + id := fmt.Sprintf("%s/locations/%s/buckets/%s", folder, location, bucketID) + return id, nil +} + +// Create Logging Bucket config +func ResourceLoggingFolderBucketConfig() *schema.Resource { + return ResourceLoggingBucketConfig("folder", loggingFolderBucketConfigSchema, folderBucketConfigID) +} diff --git a/google/resource_logging_organization_bucket_config.go b/google/resource_logging_organization_bucket_config.go new file mode 100644 index 00000000000..6efd0429ebf --- /dev/null +++ b/google/resource_logging_organization_bucket_config.go @@ -0,0 +1,34 @@ +package google + +import ( + "fmt" + "strings" + + "github.com/hashicorp/terraform-plugin-sdk/helper/schema" +) + +var loggingOrganizationBucketConfigSchema = map[string]*schema.Schema{ + "organization": { + Type: schema.TypeString, + Required: true, + ForceNew: true, + }, +} + +func organizationBucketConfigID(d *schema.ResourceData, config *Config) (string, error) { + organization := d.Get("organization").(string) + location := d.Get("location").(string) + bucketID := d.Get("bucket_id").(string) + + if !strings.HasPrefix(organization, "organization") { + organization = "organizations/" + organization + } + + id := fmt.Sprintf("%s/locations/%s/buckets/%s", organization, location, bucketID) + return id, nil +} + +// Create Logging Bucket config +func ResourceLoggingOrganizationBucketConfig() *schema.Resource { + return ResourceLoggingBucketConfig("organization", loggingOrganizationBucketConfigSchema, organizationBucketConfigID) +} diff --git a/google/resource_logging_project_bucket_config.go b/google/resource_logging_project_bucket_config.go new file mode 100644 index 00000000000..b0bf6a89e3f --- /dev/null +++ b/google/resource_logging_project_bucket_config.go @@ -0,0 +1,34 @@ +package google + +import ( + "fmt" + "strings" + + "github.com/hashicorp/terraform-plugin-sdk/helper/schema" +) + +var loggingProjectBucketConfigSchema = map[string]*schema.Schema{ + "project": { + Type: schema.TypeString, + Required: true, + ForceNew: true, + }, +} + +func projectBucketConfigID(d *schema.ResourceData, config *Config) (string, error) { + project := d.Get("project").(string) + location := d.Get("location").(string) + bucketID := d.Get("bucket_id").(string) + + if !strings.HasPrefix(project, "project") { + project = "projects/" + project + } + + id := fmt.Sprintf("%s/locations/%s/buckets/%s", project, location, bucketID) + return id, nil +} + +// Create Logging Bucket config +func ResourceLoggingProjectBucketConfig() *schema.Resource { + return ResourceLoggingBucketConfig("project", loggingProjectBucketConfigSchema, projectBucketConfigID) +} diff --git a/website/docs/r/logging_billing_account_bucket_config.html.markdown b/website/docs/r/logging_billing_account_bucket_config.html.markdown new file mode 100644 index 00000000000..3f8c420933b --- /dev/null +++ b/website/docs/r/logging_billing_account_bucket_config.html.markdown @@ -0,0 +1,62 @@ +--- +subcategory: "Cloud (Stackdriver) Logging" +layout: "google" +page_title: "Google: google_logging_billing_account_bucket_config" +sidebar_current: "docs-google-logging-billing-account-bucket-config" +description: |- + Manages a billing account level logging bucket config. +--- + +# google\_logging\_billing_account\_bucket\_config + +Manages a billing account level logging bucket config. For more information see +[the official logging documentation](https://cloud.google.com/logging/docs/) and +[Storing Logs](https://cloud.google.com/logging/docs/storage). + +~> **Note:** Logging buckets are automatically created for a given folder, project, organization, billingAccount and cannot be deleted. Creating a resource of this type will acquire and update the resource that already exists at the desired location. These buckets cannot be removed so deleting this resource will remove the bucket config from your terraform state but will leave the logging bucket unchanged. The buckets that are currently automatically created are "_Default" and "_Required". + +## Example Usage + +```hcl +data "google_billing_account" "default" { + billing_account = "00AA00-000AAA-00AA0A" +} + +resource "google_logging_billing_account_bucket_config" "basic" { + billing_account = data.google_billing_account.default.billing_account + location = "global" + retention_days = 30 + bucket_id = "_Default" +} +``` + +## Argument Reference + +The following arguments are supported: + +* `billing_account` - (Required) The parent resource that contains the logging bucket. + +* `location` - (Required) The location of the bucket. The supported locations are: "global" "us-central1" + +* `bucket_id` - (Required) The name of the logging bucket. Logging automatically creates two log buckets: `_Required` and `_Default`. + +* `description` - (Optional) Describes this bucket. + +* `retention_days` - (Optional) Logs will be retained by default for this amount of time, after which they will automatically be deleted. The minimum retention period is 1 day. If this value is set to zero at bucket creation time, the default time of 30 days will be used. + +## Attributes Reference + +In addition to the arguments listed above, the following computed attributes are +exported: + +* `name` - The resource name of the bucket. For example: "projects/my-project-id/locations/my-location/buckets/my-bucket-id" + +* `lifecycle_state` - The bucket's lifecycle such as active or deleted. See [LifecycleState](https://cloud.google.com/logging/docs/reference/v2/rest/v2/billingAccounts.buckets#LogBucket.LifecycleState). + +## Import + +This resource can be imported using the following format: + +``` +$ terraform import google_logging_billing_account_bucket_config.default billingAccounts/{{billingAccount}}/locations/{{location}}/buckets/{{bucket_id}} +``` diff --git a/website/docs/r/logging_folder_bucket_config.html.markdown b/website/docs/r/logging_folder_bucket_config.html.markdown new file mode 100644 index 00000000000..a448973928a --- /dev/null +++ b/website/docs/r/logging_folder_bucket_config.html.markdown @@ -0,0 +1,63 @@ +--- +subcategory: "Cloud (Stackdriver) Logging" +layout: "google" +page_title: "Google: google_logging_folder_bucket_config" +sidebar_current: "docs-google-logging-folder-bucket-config" +description: |- + Manages a folder-level logging bucket config. +--- + +# google\_logging\_folder\_bucket\_config + +Manages a folder-level logging bucket config. For more information see +[the official logging documentation](https://cloud.google.com/logging/docs/) and +[Storing Logs](https://cloud.google.com/logging/docs/storage). + +~> **Note:** Logging buckets are automatically created for a given folder, project, organization, billingAccount and cannot be deleted. Creating a resource of this type will acquire and update the resource that already exists at the desired location. These buckets cannot be removed so deleting this resource will remove the bucket config from your terraform state but will leave the logging bucket unchanged. The buckets that are currently automatically created are "_Default" and "_Required". + +## Example Usage + +```hcl +resource "google_folder" "default" { + display_name = "some-folder-name" + parent = "organizations/123456789" +} + +resource "google_logging_folder_bucket_config" "basic" { + folder = google_folder.default.name + location = "global" + retention_days = 30 + bucket_id = "_Default" +} +``` + +## Argument Reference + +The following arguments are supported: + +* `folder` - (Required) The parent resource that contains the logging bucket. + +* `location` - (Required) The location of the bucket. The supported locations are: "global" "us-central1" + +* `bucket_id` - (Required) The name of the logging bucket. Logging automatically creates two log buckets: `_Required` and `_Default`. + +* `description` - (Optional) Describes this bucket. + +* `retention_days` - (Optional) Logs will be retained by default for this amount of time, after which they will automatically be deleted. The minimum retention period is 1 day. If this value is set to zero at bucket creation time, the default time of 30 days will be used. + +## Attributes Reference + +In addition to the arguments listed above, the following computed attributes are +exported: + +* `name` - The resource name of the bucket. For example: "folders/my-folder-id/locations/my-location/buckets/my-bucket-id" + +* `lifecycle_state` - The bucket's lifecycle such as active or deleted. See [LifecycleState](https://cloud.google.com/logging/docs/reference/v2/rest/v2/billingAccounts.buckets#LogBucket.LifecycleState). + +## Import + +This resource can be imported using the following format: + +``` +$ terraform import google_logging_folder_bucket_config.default folders/{{folder}}/locations/{{location}}/buckets/{{bucket_id}} +``` \ No newline at end of file diff --git a/website/docs/r/logging_organization_bucket_config.html.markdown b/website/docs/r/logging_organization_bucket_config.html.markdown new file mode 100644 index 00000000000..762f3eb45d2 --- /dev/null +++ b/website/docs/r/logging_organization_bucket_config.html.markdown @@ -0,0 +1,63 @@ +--- +subcategory: "Cloud (Stackdriver) Logging" +layout: "google" +page_title: "Google: google_logging_organization_bucket_config" +sidebar_current: "docs-google-logging-organization-bucket-config" +description: |- + Manages a organization-level logging bucket config. +--- + +# google\_logging\_organization\_bucket\_config + +Manages a organization-level logging bucket config. For more information see +[the official logging documentation](https://cloud.google.com/logging/docs/) and +[Storing Logs](https://cloud.google.com/logging/docs/storage). + +~> **Note:** Logging buckets are automatically created for a given folder, project, organization, billingAccount and cannot be deleted. Creating a resource of this type will acquire and update the resource that already exists at the desired location. These buckets cannot be removed so deleting this resource will remove the bucket config from your terraform state but will leave the logging bucket unchanged. The buckets that are currently automatically created are "_Default" and "_Required". + +## Example Usage + +```hcl +data "google_organization" "default" { + organization = "123456789" +} + +resource "google_logging_organization_bucket_config" "basic" { + organization = data.google_organization.default.organization + location = "global" + retention_days = 30 + bucket_id = "_Default" +} +``` + +## Argument Reference + +The following arguments are supported: + +* `organization` - (Required) The parent resource that contains the logging bucket. + +* `location` - (Required) The location of the bucket. The supported locations are: "global" "us-central1" + +* `bucket_id` - (Required) The name of the logging bucket. Logging automatically creates two log buckets: `_Required` and `_Default`. + +* `description` - (Optional) Describes this bucket. + +* `retention_days` - (Optional) Logs will be retained by default for this amount of time, after which they will automatically be deleted. The minimum retention period is 1 day. If this value is set to zero at bucket creation time, the default time of 30 days will be used. + +## Attributes Reference + +In addition to the arguments listed above, the following computed attributes are +exported: + +* `name` - The resource name of the bucket. For example: "organizations/my-organization-id/locations/my-location/buckets/my-bucket-id" + +* `lifecycle_state` - The bucket's lifecycle such as active or deleted. See [LifecycleState](https://cloud.google.com/logging/docs/reference/v2/rest/v2/billingAccounts.buckets#LogBucket.LifecycleState). + +## Import + + +This resource can be imported using the following format: + +``` +$ terraform import google_logging_organization_bucket_config.default organizations/{{organization}}/locations/{{location}}/buckets/{{bucket_id}} +``` diff --git a/website/docs/r/logging_project_bucket_config.html.markdown b/website/docs/r/logging_project_bucket_config.html.markdown new file mode 100644 index 00000000000..3fa6ea570d0 --- /dev/null +++ b/website/docs/r/logging_project_bucket_config.html.markdown @@ -0,0 +1,64 @@ +--- +subcategory: "Cloud (Stackdriver) Logging" +layout: "google" +page_title: "Google: google_logging_project_bucket_config" +sidebar_current: "docs-google-logging-project-bucket-config" +description: |- + Manages a project-level logging bucket config. +--- + +# google\_logging\_project\_bucket\_config + +Manages a project-level logging bucket config. For more information see +[the official logging documentation](https://cloud.google.com/logging/docs/) and +[Storing Logs](https://cloud.google.com/logging/docs/storage). + +~> **Note:** Logging buckets are automatically created for a given folder, project, organization, billingAccount and cannot be deleted. Creating a resource of this type will acquire and update the resource that already exists at the desired location. These buckets cannot be removed so deleting this resource will remove the bucket config from your terraform state but will leave the logging bucket unchanged. The buckets that are currently automatically created are "_Default" and "_Required". + +## Example Usage + +```hcl +resource "google_project" "default" { + project_id = "your-project-id" + name = "your-project-id" + org_id = "123456789" +} + +resource "google_logging_project_bucket_config" "basic" { + project = google_project.default.name + location = "global" + retention_days = 30 + bucket_id = "_Default" +} +``` + +## Argument Reference + +The following arguments are supported: + +* `project` - (Required) The parent resource that contains the logging bucket. + +* `location` - (Required) The location of the bucket. The supported locations are: "global" "us-central1" + +* `bucket_id` - (Required) The name of the logging bucket. Logging automatically creates two log buckets: `_Required` and `_Default`. + +* `description` - (Optional) Describes this bucket. + +* `retention_days` - (Optional) Logs will be retained by default for this amount of time, after which they will automatically be deleted. The minimum retention period is 1 day. If this value is set to zero at bucket creation time, the default time of 30 days will be used. + +## Attributes Reference + +In addition to the arguments listed above, the following computed attributes are +exported: + +* `name` - The resource name of the bucket. For example: "projects/my-project-id/locations/my-location/buckets/my-bucket-id" + +* `lifecycle_state` - The bucket's lifecycle such as active or deleted. See [LifecycleState](https://cloud.google.com/logging/docs/reference/v2/rest/v2/billingAccounts.buckets#LogBucket.LifecycleState). + +## Import + +This resource can be imported using the following format: + +``` +$ terraform import google_logging_project_bucket_config.default projects/{{project}}/locations/{{location}}/buckets/{{bucket_id}} +``` diff --git a/website/google.erb b/website/google.erb index c8d04be50dc..6d209d9cd73 100644 --- a/website/google.erb +++ b/website/google.erb @@ -193,6 +193,10 @@ Resources