JamesWoolfenden / terraform-gcp-statebucket

Contains a module to create a statebucket for use with Terraform

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

terraform-gcp-statebucket

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

Terraform module to provision a secure terraform state bucket for team use of IAC.


It's 100% Open Source and licensed under the APACHE2.

Usage

Include this repository as a module in your existing terraform code:

module "statebucket" {
  source      = "JamesWoolfenden/statebucket/gcp"
  version     = "0.3.22"
  common_tags = var.common_tags
  kms_key     ="pike"
}

Requirements

No requirements.

Providers

Name Version
google n/a
local n/a

Modules

No modules.

Resources

Name Type
google_storage_bucket.statebucket resource
local_file.remote_state resource

Inputs

Name Description Type Default Required
common_tags This is a map type for applying tags on resources map(any) n/a yes
kms_key Which key to encrypt with string n/a yes
location n/a string n/a yes
project_id n/a string n/a yes

Outputs

Name Description
bucket_domain_name 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.update"
  ]
}

Information

When working with Terraform as part of a team, instead of a local terrraform.tfstate file, a shared remote state store is required, for GCP this is the google_storage_bucket. But if we want to automate everything via Terraform? Traditionally we would have to create the initial bucket by hand via the console or by the CLI and the resource unmanaged. The module and example solve the issue of creating a state bucket in Terraform using Terraform itself.

But how

The Makefile in folder examples\examplesA has several tasks, one specifically to create the initial bucket:

make first

This makes the lock DB table, the state (google_storage_bucket) bucket, fills out and creates the remote_state.tf file and then copies the state from the local disk to the bucket.PHEW. The State of the bucket is now managed along with any future resources.

On the second and subsequent runs, you use:

make build

If this is your first time using the APIs you will need to enable them: https://console.developers.google.com/apis/api/cloudresourcemanager.googleapis.com/overview?

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

About

Contains a module to create a statebucket for use with Terraform

License:Apache License 2.0


Languages

Language:HCL 52.2%Language:Makefile 35.3%Language:PowerShell 5.9%Language:Shell 3.7%Language:Python 3.0%