Skip to content

Commit

Permalink
fix: convert lifecycle action object to map (#52)
Browse files Browse the repository at this point in the history
* convert object to map

* fmt

* doc
  • Loading branch information
umairidris committed May 1, 2020
1 parent 9377eea commit f2e6ea3
Show file tree
Hide file tree
Showing 8 changed files with 84 additions and 15 deletions.
1 change: 0 additions & 1 deletion examples/multiple_buckets/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,3 @@ module "cloud_storage" {
}
}]
}

19 changes: 19 additions & 0 deletions examples/simple_bucket/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Simple Example

This example illustrates how to use the `simple-bucket` submodule.

<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
## Inputs

| Name | Description | Type | Default | Required |
|------|-------------|:----:|:-----:|:-----:|
| name | Name of the buckets to create. | string | n/a | yes |
| project\_id | The ID of the project in which to provision resources. | string | n/a | yes |

<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->

To provision this example, run the following from within this directory:
- `terraform init` to get the plugins
- `terraform plan` to see the infrastructure plan
- `terraform apply` to apply the infrastructure build
- `terraform destroy` to destroy the built infrastructure
4 changes: 2 additions & 2 deletions examples/simple_bucket/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
module "bucket" {
source = "../../modules/simple_bucket"

name = "example-bucket"
project_id = "example-project"
name = var.name
project_id = var.project_id
location = "us-east1"

lifecycle_rules = [{
Expand Down
25 changes: 25 additions & 0 deletions examples/simple_bucket/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/**
* Copyright 2018 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

variable "project_id" {
description = "The ID of the project in which to provision resources."
type = string
}

variable "name" {
description = "Name of the buckets to create."
type = string
}
19 changes: 19 additions & 0 deletions examples/simple_bucket/versions.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/**
* Copyright 2019 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

terraform {
required_version = ">= 0.12"
}
2 changes: 1 addition & 1 deletion main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ resource "google_storage_bucket" "buckets" {
content {
action {
type = lifecycle_rule.value.action.type
storage_class = lifecycle_rule.value.action.storage_class
storage_class = lookup(lifecycle_rule.value.action, "storage_class", null)
}
condition {
age = lookup(lifecycle_rule.value.condition, "age", null)
Expand Down
14 changes: 7 additions & 7 deletions modules/simple_bucket/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,15 @@ resource "google_storage_bucket" "bucket" {
for_each = var.lifecycle_rules
content {
action {
type = lifecycle_rule.value.action.type
storage_class = lookup(lifecycle_rule.value.action, "storage_class", null)
type = lifecycle_rule.value.action.type
storage_class = lookup(lifecycle_rule.value.action, "storage_class", null)
}
condition {
age = lookup(lifecycle_rule.value.condition, "age", null)
created_before = lookup(lifecycle_rule.value.condition, "storage_class", null)
with_state = lookup(lifecycle_rule.value.condition, "with_state", null)
matches_storage_class = lookup(lifecycle_rule.value.condition, "matches_storage_class", null)
num_newer_versions = lookup(lifecycle_rule.value.condition, "num_newer_versions", null)
age = lookup(lifecycle_rule.value.condition, "age", null)
created_before = lookup(lifecycle_rule.value.condition, "storage_class", null)
with_state = lookup(lifecycle_rule.value.condition, "with_state", null)
matches_storage_class = lookup(lifecycle_rule.value.condition, "matches_storage_class", null)
num_newer_versions = lookup(lifecycle_rule.value.condition, "num_newer_versions", null)
}
}
}
Expand Down
15 changes: 11 additions & 4 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -129,10 +129,17 @@ variable "set_viewer_roles" {

variable "lifecycle_rules" {
type = set(object({
action = object({
type = string
storage_class = string
})
# Object with keys:
# - type - The type of the action of this Lifecycle Rule. Supported values: Delete and SetStorageClass.
# - storage_class - (Required if action type is SetStorageClass) The target Storage Class of objects affected by this Lifecycle Rule.
action = map(string)

# Object with keys:
# - age - (Optional) Minimum age of an object in days to satisfy this condition.
# - created_before - (Optional) Creation date of an object in RFC 3339 (e.g. 2017-06-13) to satisfy this condition.
# - with_state - (Optional) Match to live and/or archived objects. Supported values include: "LIVE", "ARCHIVED", "ANY".
# - matches_storage_class - (Optional) Comma delimited string for storage class of objects to satisfy this condition. Supported values include: MULTI_REGIONAL, REGIONAL, NEARLINE, COLDLINE, STANDARD, DURABLE_REDUCED_AVAILABILITY.
# - num_newer_versions - (Optional) Relevant only for versioned objects. The number of newer versions of an object to satisfy this condition.
condition = map(string)
}))
description = "List of lifecycle rules to configure. Format is the same as described in provider documentation https://www.terraform.io/docs/providers/google/r/storage_bucket.html#lifecycle_rule except condition.matches_storage_class should be a comma delimited string."
Expand Down

0 comments on commit f2e6ea3

Please sign in to comment.