fixed bugs for attached RDS

This commit is contained in:
Arsenii Petrovich 2019-02-26 21:53:54 +03:00
parent 4db52814cd
commit 9aeeb0757c
9 changed files with 18 additions and 10 deletions

2
.gitignore vendored
View File

@ -10,7 +10,7 @@
roles/main_infra/files/backend.tfvars
roles/main_infra/files/remote-backend-selector.tf
roles/main_infra/files/terraform.tfvars
*.backup
# Sensitive information
/*.privkey

View File

@ -189,8 +189,16 @@ You can easily manipulate your deployment from any machine with sufficient prere
## Attaching the existing RDS instance to the current deployment
In some cases you may want not to create a new database, but to add the existing one to use within the deployment. In order to do that configure all the proper values at `group_vars/all.yml` including yours DB ID and name and execute the `ansible-playbook attach_existing_rds.yml` command. This will add the current DB instance into TF managed resource group. After that run `ansible-playbook deploy.yml` as usually.
In some cases you may want not to create a new database, but to add the existing one to use within the deployment. In order to do that configure all the proper values at `group_vars/all.yml` including yours DB ID and name and execute the `ansible-playbook attach_existing_rds.yml` command. This will add the current DB instance into Terraform-managed resource group. After that run `ansible-playbook deploy.yml` as usually.
Note 1: that this action includes creating the S3 and DynamoDB (if `backend` variable is set to `true`) to store Terraform state files.
Note 2: the actual name of your resource must include prefix that you will use in this deployment!
Example:
Real resource: tf-poa
prefix variable: tf
db_id variable: poa
## Common Errors and Questions
### S3: 403 error during provisioning

View File

@ -5,6 +5,10 @@
- { role: s3, when: "backend|bool == true" }
- { role: dynamodb, when: "backend|bool == true" }
- { role: attach_existing_rds }
vars_prompt:
- name: "confirmation"
prompt: "Are you sure you want to attach the existing RDS? If backend variable is set to True, this action includes creating the S3 and DynamoDB table for storing Terraform state files."
default: False
environment:
AWS_ACCESS_KEY_ID: "{{ aws_access_key }}"
AWS_SECRET_ACCESS_KEY: "{{ aws_secret_key }}"

View File

@ -36,7 +36,6 @@ prefix: "sokol"
## The following settings are related to the RDS instance which will be created during deployment
db_id: "poa"
db_name: "poa"
db_username: "username"
db_password: "qwerty12345"
db_instance_class: "db.m4.xlarge"

View File

@ -24,10 +24,10 @@
when: backend|bool == true
#Workaround since terraform module return unexpected error.
- name: Terraform provisioning
- name: Attach RDS to the current deployment
shell: "echo yes | {{ terraform_location }} {{ item }}"
args:
chdir: "roles/main_infra/files"
with_items:
- "init{{ ' -backend-config=backend.tfvars' if backend|bool == true else '' }}"
- "import aws_db_instance.default {{ db_id }}"
- "import aws_db_instance.default {{ prefix }}-{{ db_id }}"

View File

@ -1,5 +1,4 @@
resource "aws_db_instance" "default" {
name = "${var.prefix}-${var.db_name}"
identifier = "${var.prefix}-${var.db_id}"
engine = "postgres"
engine_version = "10.5"

View File

@ -45,7 +45,6 @@ variable "chain_network_icon" {
}
variable "db_id" {}
variable "db_name" {}
variable "db_username" {}
variable "db_password" {}
variable "db_storage" {}

View File

@ -35,11 +35,11 @@
- name: Show Terraform plan
debug:
var: tf_plan.stdout_lines
var: tf_plan.results[1].stdout_lines
- name: User prompt
pause:
prompt: "Are you absolutely sure you want to execute the deployment plan shown above? [Yes/No] Default: No"
prompt: "Are you absolutely sure you want to execute the deployment plan shown above? [False]"
register: user_answer
- name: Terraform provisioning

View File

@ -11,7 +11,6 @@ root_block_size = "{{ root_block_size }}"
pool_size = "{{ pool_size }}"
db_id = "{{ db_id }}"
db_name = "{{ db_name }}"
db_username = "{{ db_username }}"
db_password = "{{ db_password }}"
db_instance_class = "{{ db_instance_class }}"