Sample rails app use ruby-spanner-activerecord
# for terraforn and gcloud cli
export GOOGLE_APPLICATION_CREDENTIALS=YOUR_CREDENTIAL
export GOOGLE_PROJECT=YOUR_PROJECT
export PROJECT_ID=$GOOGLE_PROJECT
# spanner free-trial instance support region
# us-east5, europe-west3, asia-south2, asia-southeast2
export REGION=us-east5
export RAILS_MASTER_KEY=`cat config/master.key | tr -d \n `
make create_instance_production
cd infra && terraform init
# comment out
data "google_kms_secret" "rails_master_key" {
crypto_key = google_kms_crypto_key.crypto_key.id
# Must Replace!: echo -n $RAILS_MASTER_KEY | gcloud kms encrypt --location asia-northeast1 --keyring key-ring --key crypto-key --plaintext-file - --ciphertext-file - | base64
ciphertext = "CiQAZ4zH06xt5lU6j2Q4QRsojbdH1RCwg9KJLJt3blR+2noYcbYSSQDLeR9jDCTyztjOnaxTLsvcBjP82GLLCIRWfK5RtzAYt/x4IySg6Awot82dFLuOrYi3/zEk6W8rR+iEnrddxhPQDbJAlqAa3uU="
}
resource "google_secret_manager_secret" "rails_master_key" {
project = data.google_project.default.project_id
secret_id = "rails-master-key"
replication {
automatic = true
}
}
resource "google_secret_manager_secret_version" "rails_master_key" {
secret = google_secret_manager_secret.rails_master_key.id
secret_data = data.google_kms_secret.rails_master_key.plaintext
}
terraform plan
terraform apply -auto-approve
echo -n $RAILS_MASTER_KEY | gcloud kms encrypt --location asia-northeast1 --keyring key-ring --key crypto-key --plaintext-file - --ciphertext-file - | base64
data "google_kms_secret" "rails_master_key" {
crypto_key = google_kms_crypto_key.crypto_key.id
# Must Replace!: echo -n $RAILS_MASTER_KEY | gcloud kms encrypt --location asia-northeast1 --keyring key-ring --key crypto-key --plaintext-file - --ciphertext-file - | base64
ciphertext = ### Here! ###
}
terraform plan
terraform apply -auto-approve
make create_migrate_production_job
make deploy_production