Skip to content

Commit

Permalink
Added GCS backend for remote .tfstate storage
Browse files Browse the repository at this point in the history
- Fixed terraform render in kite generate
  • Loading branch information
vshatravenko committed Sep 22, 2017
1 parent abd05f2 commit 5b22ddb
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 11 deletions.
14 changes: 3 additions & 11 deletions lib/kite/core.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,8 @@ def generate()

case options[:cloud]
when 'aws'
copy_file('aws/terraform/main.tf', 'terraform/main.tf')
copy_file('aws/terraform/network.tf', 'terraform/network.tf')
copy_file('aws/terraform/outputs.tf', 'terraform/outputs.tf')
copy_file('aws/terraform/variables.tf', 'terraform/variables.tf')
template('aws/terraform/terraform.tfvars.erb', 'terraform/terraform.tfvars')
copy_file('aws/README.md', 'README.md')
directory('aws/terraform', 'terraform')
copy_file('aws/README.md', 'README.md', force: true)

template('aws/bosh-install.sh.erb', 'bin/bosh-install.sh')
template('aws/setup-tunnel.sh.erb', 'bin/setup-tunnel.sh')
Expand All @@ -35,11 +31,7 @@ def generate()
chmod('bin/setup-tunnel.sh', 0755)

when 'gcp'
copy_file('gcp/terraform/main.tf', 'terraform/main.tf')
copy_file('gcp/terraform/network.tf', 'terraform/network.tf')
copy_file('gcp/terraform/outputs.tf', 'terraform/outputs.tf')
copy_file('gcp/terraform/variables.tf', 'terraform/variables.tf')
template('gcp/terraform/terraform.tfvars.erb', 'terraform/terraform.tfvars')
directory('gcp/terraform', 'terraform')
copy_file('gcp/README.md', 'README.md', force: true)

template('gcp/bosh-install.sh.erb', 'bin/bosh-install.sh')
Expand Down
6 changes: 6 additions & 0 deletions tpl/gcp/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
## GCP Cloud

### Usage

Set path to your service account credentials:
```
export GOOGLE_CREDENTIALS=*~/credentials/service-account.json*
```

Apply terraform code
```
pushd terraform && terraform init && terraform apply && popd
Expand Down
24 changes: 24 additions & 0 deletions tpl/gcp/terraform/gcs.tf.tt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Setup Terraform backend to be able to store .tfstate remotely
terraform {
backend "gcs" {
bucket = "<%= @values['gcp']['tfstate_bucket_name'] %>"
path = "terraform.tfstate"
project = "<%= @values['gcp']['project'] %>"
}
}

# Create GCS bucket to store .tfstate in
resource "google_storage_bucket" "tfstate-bucket" {
name = "<%= @values['gcp']['tfstate_bucket_name'] %>"
location = "<%= @values['gcp']['region'] %>"
}

# Store .tfstate in a GCS bucket
data "terraform_remote_state" "tfstate" {
backend = "gcs"
config {
bucket = "<%= @values['gcp']['tfstate_bucket_name'] %>"
path = "terraform.tfstate"
project = "<%= @values['gcp']['project'] %>"
}
}
File renamed without changes.
1 change: 1 addition & 0 deletions tpl/skel/config/cloud.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ gcp:
region: "europe-west1"
zone: "europe-west1-b"
service_account: "~/safe/terraform.json"
tfstate_bucket_name: "test-tfstate-bucket"
vpc_name: "platform-tools"
subnet_name: "platform-net"
subnet_cidr: "10.0.0.0/24"
Expand Down

0 comments on commit 5b22ddb

Please sign in to comment.