Skip to content

A basic terraform module example, which the example uses for a helm repo

License

Notifications You must be signed in to change notification settings

JamesWoolfenden/terraform-gcp-storage

Repository files navigation

terraform-gcp-storage

Build Status Latest Release GitHub tag (latest SemVer) Terraform Version Infrastructure Tests pre-commit checkov Infrastructure Tests Infrastructure Tests

This creates a GCP storage account.

alt text

I created this module initially to help with making a Helm repo.

I had to first create a test repo from the charts folder

helm serve --repo-path ./charts

This gave me a sample index.yaml, which I added as part of the repo creation process [it's in the template folder for the example].

I now have a public Helm repo. https://helm-repo-examplea.storage.googleapis.com/

This example has a minimal index.yaml

Adding the repo to your Helm

helm repo add baby-steps https://helm-repo-examplea.storage.googleapis.com/
"baby-steps" has been added to your repositories

Verify:

$helm repo list
NAME            URL
stable          https://kubernetes-charts.storage.googleapis.com
baby-steps      https://helm-repo-examplea.storage.googleapis.com/

Usage

Add module.storage.tf to your code:-

module "storage" {
  source        = "JamesWoolfenden/storage/gcp"
  version       = "0.2.3"
  common_tags   = var.common_tags
  binding       = var.binding
  bucket_name   = var.bucket_name
  project       = var.project
  location      = var.location
  log_bucket    = google_storage_bucket.logging.name
  force_destroy = true
}

Permissions

This being GCP you'll get this error when was making this project, your service account will need these permissions, Included in the "Cloud Storage Admin" role.

 examplea@examplea.iam.gserviceaccount.com does not have storage.buckets.create access to project XXXXXX, forbidden

Requirements

No requirements.

Providers

Name Version
google n/a

Modules

No modules.

Resources

Name Type
google_storage_bucket.bucket resource
google_storage_bucket_acl.bucketacl resource
google_storage_bucket_iam_binding.binding resource

Inputs

Name Description Type Default Required
acl Flag to create and ACL or not, alternative is to use a bucket policy/binding number 0 no
action_storage_class The target Storage Class of objects affected by this Lifecycle Rule. Supported values include: MULTI_REGIONAL, REGIONAL, NEARLINE, COLDLINE, ARCHIVE string "COLDLINE" no
action_type The type of the action of this Lifecycle Rule. Supported values include: Delete and SetStorageClass string "SetStorageClass" no
binding_members n/a any n/a yes
binding_role n/a any n/a yes
bucket_name The name of the bucket string n/a yes
common_tags This is to help you add tags to your cloud objects map(any) n/a yes
cors n/a map
{
"max_age_seconds": null,
"method": [
""
],
"origin": [
""
],
"response_header": [
""
]
}
no
force_destroy Flag to set to destroy buckets with content bool false no
kms_key Which key to encrypt with string "" no
lifecycle_age Minimum (days) age of an object in days to satisfy this condition number 3 no
location Where the bucket is string "US" no
log_bucket Should not be itself string n/a yes
main_page_suffix n/a string null no
not_found_page n/a string "404.html" no
predefined_acl n/a string "private" no
project The GCP project name string n/a yes
public Make bucket publicly accessible string "enforced" no
versioning n/a string true no

Outputs

Name Description
bucket All the bucket info
url The Url of the statebucket

Role and Permissions

The Terraform resource required is:

resource "google_project_iam_custom_role" "terraform_pike" {
  project     = "pike"
  role_id     = "terraform_pike"
  title       = "terraform_pike"
  description = "A user with least privileges"
  permissions = [
    "storage.buckets.create",
    "storage.buckets.delete",
    "storage.buckets.get",
    "storage.buckets.getIamPolicy",
    "storage.buckets.setIamPolicy",
    "storage.buckets.update"
  ]
}

Related Projects

Check out these related projects.

Help

Got a question?

File a GitHub issue.

Contributing

Bug Reports & Feature Requests

Please use the issue tracker to report any bugs or file feature requests.

Copyrights

Copyright © 2019-2023 James Woolfenden

License

License

See LICENSE for full details.

Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to you 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

https://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.

Contributors

James Woolfenden
James Woolfenden