|
1 |
| -# github-actions-deploy-aurora |
2 |
| -GitHub action to deploy an Aurora DB Instance |
| 1 | +# Deploy Aurora DB Cluster (Postgres/MySQL) |
| 2 | +`bitovi/github-actions-deploy-aurora` deploys an Aurora cluster with any amount of instances, with the option for a proxy. |
| 3 | + |
| 4 | +This action uses our new GitHub Actions Commons repository, a library that contains multiple Terraform modules, allowing us to condense all of our tools in one repo, hence continuous improvements are made to it. |
| 5 | + |
| 6 | +## Action Summary |
| 7 | +This action creates an Aurora Cluster, with the option to add even a proxy. Could be a Postgres or MySQL. |
| 8 | + |
| 9 | +If you would like to deploy a backend app/service, check out our other actions: |
| 10 | +| Action | Purpose | |
| 11 | +| ------ | ------- | |
| 12 | +| [Deploy Docker to EC2](https://github.com/marketplace/actions/deploy-docker-to-aws-ec2) | Deploys a repo with a Dockerized application to a virtual machine (EC2) on AWS | |
| 13 | +| [Deploy React to GitHub Pages](https://github.com/marketplace/actions/deploy-react-to-github-pages) | Builds and deploys a React application to GitHub Pages. | |
| 14 | +| [Deploy static site to AWS (S3/CDN/R53)](https://github.com/marketplace/actions/deploy-static-site-to-aws-s3-cdn-r53) | Hosts a static site in AWS S3 with CloudFront | |
| 15 | +<br/> |
| 16 | + |
| 17 | +**And more!**, check our [list of actions in the GitHub marketplace](https://github.com/marketplace?category=&type=actions&verification=&query=bitovi) |
| 18 | + |
| 19 | +# Need help or have questions? |
| 20 | +This project is supported by [Bitovi, A DevOps consultancy](https://www.bitovi.com/services/devops-consulting). |
| 21 | + |
| 22 | +You can **get help or ask questions** on our: |
| 23 | + |
| 24 | +- [Discord Community](https://discord.gg/J7ejFsZnJ4Z) |
| 25 | + |
| 26 | +Or, you can hire us for training, consulting, or development. [Set up a free consultation](https://www.bitovi.com/services/devops-consulting). |
| 27 | + |
| 28 | +# Basic Use - Postgres |
| 29 | + |
| 30 | +For basic usage, create `.github/workflows/deploy.yaml` with the following to build on push. |
| 31 | +```yaml |
| 32 | +on: |
| 33 | + push: |
| 34 | + branches: |
| 35 | + - "main" # change to the branch you wish to deploy from |
| 36 | + |
| 37 | +jobs: |
| 38 | + deploy: |
| 39 | + runs-on: ubuntu-latest |
| 40 | + steps: |
| 41 | + - id: deploy-aurora |
| 42 | + |
| 43 | + with: |
| 44 | + aws_access_key_id: ${{ secrets.AWS_ACCESS_KEY_ID }} |
| 45 | + aws_secret_access_key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} |
| 46 | + aws_default_region: us-east-1 |
| 47 | + |
| 48 | +``` |
| 49 | + |
| 50 | +# Basic MySQL |
| 51 | +```yaml |
| 52 | +on: |
| 53 | + push: |
| 54 | + branches: |
| 55 | + - "main" # change to the branch you wish to deploy from |
| 56 | + |
| 57 | +jobs: |
| 58 | + deploy: |
| 59 | + runs-on: ubuntu-latest |
| 60 | + steps: |
| 61 | + - id: deploy-aurora |
| 62 | + |
| 63 | + with: |
| 64 | + aws_access_key_id: ${{ secrets.AWS_ACCESS_KEY_ID }} |
| 65 | + aws_secret_access_key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} |
| 66 | + aws_default_region: us-east-1 |
| 67 | + |
| 68 | + aws_aurora_engine: aurora-mysql |
| 69 | +``` |
| 70 | +
|
| 71 | +# Advanced use |
| 72 | +```yaml |
| 73 | +on: |
| 74 | + push: |
| 75 | + branches: |
| 76 | + - "main" # change to the branch you wish to deploy from |
| 77 | + |
| 78 | +jobs: |
| 79 | + deploy: |
| 80 | + runs-on: ubuntu-latest |
| 81 | + steps: |
| 82 | + - id: deploy |
| 83 | + |
| 84 | + with: |
| 85 | + aws_access_key_id: ${{ secrets.AWS_ACCESS_KEY_ID }} |
| 86 | + aws_secret_access_key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} |
| 87 | + aws_default_region: us-east-1 |
| 88 | + |
| 89 | + aws_additional_tags: '{\"some\":\"extra\",\"tag\":\"added\"}' |
| 90 | + |
| 91 | + tf_state_bucket_destroy: true |
| 92 | + |
| 93 | + aws_aurora_engine: aurora-mysql |
| 94 | + aws_aurora_proxy: true |
| 95 | + aws_aurora_cluster_apply_immediately: true |
| 96 | + aws_aurora_database_name: some-db-name |
| 97 | + aws_aurora_master_username: myrdsuser |
| 98 | + aws_aurora_ingress_allow_all: true |
| 99 | + aws_aurora_subnets: subnet-0000000000000,subnet-0000000000000 |
| 100 | + aws_aurora_db_instance_class: db.r6g.large |
| 101 | + aws_vpc_id: vpc-0000000000000 |
| 102 | + aws_resource_identifier: replaced-this-from |
| 103 | + tf_state_bucket: bitovi-resources |
| 104 | + tf_state_file_name_append: rds-dev-db |
| 105 | +``` |
| 106 | +
|
| 107 | +# Multi-AZ cluster |
| 108 | +```yaml |
| 109 | +on: |
| 110 | + push: |
| 111 | + branches: |
| 112 | + - "main" # change to the branch you wish to deploy from |
| 113 | + |
| 114 | +jobs: |
| 115 | + deploy: |
| 116 | + runs-on: ubuntu-latest |
| 117 | + steps: |
| 118 | + - id: deploy |
| 119 | + |
| 120 | + with: |
| 121 | + aws_access_key_id: ${{ secrets.AWS_ACCESS_KEY_ID }} |
| 122 | + aws_secret_access_key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} |
| 123 | + aws_default_region: us-east-1 |
| 124 | + |
| 125 | + tf_state_bucket_destroy: true |
| 126 | + aws_aurora_db_instances_count: 0 |
| 127 | + |
| 128 | + aws_aurora_engine: postgres |
| 129 | + aws_aurora_availability_zones: us-east-1a,us-east-1b,us-east-1c |
| 130 | + aws_aurora_cluster_db_instance_class: db.m5d.large |
| 131 | + aws_aurora_storage_type: io1 |
| 132 | + aws_aurora_storage_iops: 1000 |
| 133 | + aws_aurora_allocated_storage: 100 |
| 134 | + |
| 135 | + aws_aurora_proxy: true |
| 136 | +``` |
| 137 | +
|
| 138 | +### Inputs |
| 139 | +1. [AWS Specific](#aws-specific) |
| 140 | +1. [Action default inputs](#action-default-inputs) |
| 141 | +1. [Aurora Inputs](#aurora-inputs) |
| 142 | +1. [Aurora Proxy Inputs](#aurora-proxy-inputs) |
| 143 | +1. [VPC Inputs](#vpc-inputs) |
| 144 | +
|
| 145 | +### Outputs |
| 146 | +1. [Aurora Outputs](#aurora-outputs) |
| 147 | +
|
| 148 | +The following inputs can be used as `step.with` keys |
| 149 | +<br/> |
| 150 | + |
| 151 | +#### **AWS Specific** |
| 152 | +| Name | Type | Description | |
| 153 | +|------------------|---------|------------------------------------| |
| 154 | +| `aws_access_key_id` | String | AWS access key ID | |
| 155 | +| `aws_secret_access_key` | String | AWS secret access key | |
| 156 | +| `aws_session_token` | String | AWS session token | |
| 157 | +| `aws_default_region` | String | AWS default region. Defaults to `us-east-1` | |
| 158 | +| `aws_resource_identifier` | String | Set to override the AWS resource identifier for the deployment. Defaults to `${GITHUB_ORG_NAME}-${GITHUB_REPO_NAME}-${GITHUB_BRANCH_NAME}`. | |
| 159 | +| `aws_additional_tags` | JSON | Add additional tags to the terraform [default tags](https://www.hashicorp.com/blog/default-tags-in-the-terraform-aws-provider), any tags put here will be added to all provisioned resources.| |
| 160 | +<br/> |
| 161 | + |
| 162 | +#### **Action default inputs** |
| 163 | +| Name | Type | Description | |
| 164 | +|------------------|---------|------------------------------------| |
| 165 | +| `tf_stack_destroy` | Boolean | Set to `true` to destroy the stack. | |
| 166 | +| `tf_state_file_name` | String | Change this to be anything you want to. Carefull to be consistent here. A missing file could trigger recreation, or stepping over destruction of non-defined objects. Defaults to `tf-state-aws`. | |
| 167 | +| `tf_state_file_name_append` | String | Appends a string to the tf-state-file. Setting this to `unique` will generate `tf-state-aws-unique`. (Can co-exist with `tf_state_file_name`) | |
| 168 | +| `tf_state_bucket` | String | AWS S3 bucket name to use for Terraform state. See [note](#s3-buckets-naming) | |
| 169 | +| `tf_state_bucket_destroy` | Boolean | Force purge and deletion of S3 bucket defined. Any file contained there will be destroyed. `tf_stack_destroy` must also be `true`. Default is `false`. | |
| 170 | +| `bitops_code_only` | Boolean | If `true`, will run only the generation phase of BitOps, where the Terraform and Ansible code is built. | |
| 171 | +| `bitops_code_store` | Boolean | Store BitOps generated code as a GitHub artifact. | |
| 172 | +<br/> |
| 173 | + |
| 174 | + |
| 175 | +#### **Aurora Inputs** |
| 176 | +| Name | Type | Description | |
| 177 | +|------------------|---------|------------------------------------| |
| 178 | +| `aws_aurora_enable` | Boolean | Toggles deployment of an Aurora database. Defaults to `true`. | |
| 179 | +| `aws_aurora_proxy` | Boolean | Aurora DB Proxy Toggle. Defaults to `false`. | |
| 180 | +| `aws_aurora_cluster_name` | String | The name of the cluster. Defaults to `aws_resource_identifier` if none set. | |
| 181 | +| `aws_aurora_engine` | String | The database engine to use. Defaults to `aurora-postgresql`. | |
| 182 | +| `aws_aurora_engine_version` | String | The DB version of the engine to use. Will default to one of the latest selected by AWS. More information [Postgres](https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/AuroraPostgreSQL.Updates.20180305.html) or [MySQL](https://docs.aws.amazon.com/AmazonRDS/latest/AuroraMySQLReleaseNotes/Welcome.html)| |
| 183 | +| `aws_aurora_engine_mode` | String | Database engine mode. Could be global, multimaster, parallelquey, provisioned, serverless. | |
| 184 | +| `aws_aurora_availability_zones` | String | Comma separated list of zones to deploy DB to. If none, will automatically set this. | |
| 185 | +| `aws_aurora_cluster_apply_immediately` | Boolean | Apply changes immediately to the cluster. If not, will be done in next maintenance window. Defaults to `false`. | |
| 186 | +| **Storage** ||| |
| 187 | +| `aws_aurora_allocated_storage` | String | Amount of storage in gigabytes. Required for multi-az cluster. | |
| 188 | +| `aws_aurora_storage_encrypted` | Boolean | Toggles whether the DB cluster is encrypted. Defaults to `true`. | |
| 189 | +| `aws_aurora_kms_key_id` | String | KMS Key ID to use with the cluster encrypted storage. | |
| 190 | +| `aws_aurora_storage_type` | String | Define type of storage to use. Required for multi-az cluster. | |
| 191 | +| `aws_aurora_storage_iops` | String | iops for storage. Required for multi-az cluster. | |
| 192 | +| **Cluster details** ||| |
| 193 | +| `aws_aurora_database_name` | String | The name of the database. will be created if it does not exist. Defaults to `aurora`. | |
| 194 | +| `aws_aurora_master_username` | String | Master username. Defaults to `aurora`. | |
| 195 | +| `aws_aurora_database_group_family` | String | The family of the DB parameter group. See [MySQL Reference](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/AuroraMySQL.Reference.html) or [Postgres Reference](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/AuroraPostgreSQL.Reference.html). Defaults automatically set for MySQL(`aurora-mysql8.0`) and Postgres (`aurora-postgresql15`). | |
| 196 | +| `aws_aurora_iam_auth_enabled` | Boolean | Toggles IAM Authentication. Defaults to `false`. | |
| 197 | +| `aws_aurora_iam_roles` | String | Define the ARN list of allowed roles. | |
| 198 | +| `aws_aurora_cluster_db_instance_class` | String | To create a Multi-AZ RDS cluster, you must additionally specify the engine, storage_type, allocated_storage, iops and aws_aurora_db_cluster_instance_class attributes. | |
| 199 | +| **Networking** ||| |
| 200 | +| `aws_aurora_security_group_name` | String | Name of the security group to use for postgres. Defaults to `SG for {aws_resource_identifier} - Aurora`.| |
| 201 | +| `aws_aurora_allowed_security_groups` | String | Extra names of the security groups to access Aurora. Accepts comma separated list of. | |
| 202 | +| `aws_aurora_ingress_allow_all` | Boolean | Allow access from 0.0.0.0/0 in the same VPC. Defaults to `true`. | |
| 203 | +| `aws_aurora_subnets` | String | Subnet ids to use for postgres. Accepts comma separated list of. | |
| 204 | +| `aws_aurora_database_port` | String | Database port. Defaults to `5432`. | |
| 205 | +| **Backup & maint** ||| |
| 206 | +| `aws_aurora_cloudwatch_enable` | Boolean | Toggles cloudwatch. Defaults to `true`. | |
| 207 | +| `aws_aurora_cloudwatch_log_type` | String | Comma separated list of log types to include in cloudwatch. If none defined, will use [postgresql] or [audit,error,general,slowquery]. Based on the db engine. | |
| 208 | +| `aws_aurora_cloudwatch_retention_days` | String | Days to store cloudwatch logs. Defaults to `7`. | |
| 209 | +| `aws_aurora_backtrack_window` | String | Target backtrack window, in seconds. Only available for aurora and aurora-mysql engines currently. 0 to disable. Defaults to `0`. | |
| 210 | +| `aws_aurora_backup_retention_period` | String | Days to retain backups for. Defaults to `5`. | |
| 211 | +| `aws_aurora_backup_window` | String | Daily time range during which the backups happen. | |
| 212 | +| `aws_aurora_maintenance_window` | String | Maintenance window. | |
| 213 | +| `aws_aurora_database_final_snapshot` | String | Set the name to generate a snapshot of the database before deletion. | |
| 214 | +| `aws_aurora_deletion_protection` | Boolean | Protects the cluster from deletion. Defaults to `false`. **This won't prevent db instances to be deleted.** To disable it, you'll have to go through the AWS Console. | |
| 215 | +| `aws_aurora_delete_auto_backups` | Boolean | Specifies whether to remove automated backups immediately after the DB cluster is deleted. Default is `true`. | |
| 216 | +| `aws_aurora_restore_snapshot_id` | String | Restore an initial snapshot of the DB if specified. | |
| 217 | +| `aws_aurora_restore_to_point_in_time` | map{String} | Restore database to a point in time. Will require a map of strings. Like `{"restore_to_time"="W","restore_type"="X","source_cluster_identifier"="Y", "use_latest_restorable_time"="Z"}`. Default `{}`. | |
| 218 | +| `aws_aurora_snapshot_name` | String | Takes a snapshot of the DB. This is treated as one resource, meaning only one can be created, even if name changes.| |
| 219 | +| `aws_aurora_snapshot_overwrite` | Boolean | Takes a snapshot of the DB deleteing the previous snapshot. Defaults to `false`. | |
| 220 | +| **DB Instance** ||| |
| 221 | +| `aws_aurora_db_instances_count` | String | Amount of instances to create. Defaults to `1`. | |
| 222 | +| `aws_aurora_db_instance_class` | String | Database instance size. Defaults to `db.r6g.large`. | |
| 223 | +| `aws_aurora_db_apply_immediately` | String | Specifies whether any modifications are applied immediately, or during the next maintenance window. Defaults to `false`. | |
| 224 | +| `aws_aurora_db_ca_cert_identifier` | String | Certificate to use with the database. Defaults to `rds-ca-ecc384-g1`. | |
| 225 | +| `aws_aurora_db_maintenance_window` | String | Maintenance window. | |
| 226 | +| `aws_aurora_db_publicly_accessible` | Boolean | Make database publicly accessible. Defaults to `false`. | |
| 227 | +| `aws_aurora_additional_tags` | JSON | A JSON object of additional tags that will be included on created resources. Example: `{"key1": "value1", "key2": "value2"}`. | |
| 228 | +<br/> |
| 229 | + |
| 230 | +#### **Aurora Proxy Inputs** |
| 231 | +| Name | Type | Description | |
| 232 | +|------------------|---------|------------------------------------| |
| 233 | +| `aws_db_proxy_name` | String | Name of the database proxy. Defaults to `aws_resource_identifier` | |
| 234 | +| `aws_db_proxy_client_password_auth_type` | String | Overrides auth type. Using `MYSQL_NATIVE_PASSWORD` or `POSTGRES_SCRAM_SHA_256` depending on the database engine. | |
| 235 | +| `aws_db_proxy_tls` | Boolean | Make TLS a requirement for connections. Defaults to `true`.| |
| 236 | +| `aws_db_proxy_security_group_name` | String | Name for the proxy security group. Defaults to `aws_resource_identifier`. | |
| 237 | +| `aws_db_proxy_database_security_group_allow` | Boolean | If true, will add an incoming rule from every security group associated with the DB. | |
| 238 | +| `aws_db_proxy_allowed_security_group` | String | Comma separated list for extra allowed security groups. | |
| 239 | +| `aws_db_proxy_allow_all_incoming` | Boolean | Allow all incoming traffic to the DB Proxy (0.0.0.0/0 rule). Keep in mind that the proxy is only available from the internal network except manually exposed. | |
| 240 | +| `aws_db_proxy_cloudwatch_enable` | Boolean | Toggle Cloudwatch logs. Will be stored in `/aws/rds/proxy/rds_proxy.name`. | |
| 241 | +| `aws_db_proxy_cloudwatch_retention_days` | String | Number of days to retain cloudwatch logs. Defaults to `14`. | |
| 242 | +| `aws_db_proxy_additional_tags` | JSON | Add additional tags to the ter added to aurora provisioned resources.| |
| 243 | +<br/> |
| 244 | + |
| 245 | +#### **VPC Inputs** |
| 246 | +| Name | Type | Description | |
| 247 | +|------------------|---------|------------------------------------| |
| 248 | +| `aws_vpc_create` | Boolean | Define if a VPC should be created. Defaults to `false`. | |
| 249 | +| `aws_vpc_name` | String | Define a name for the VPC. Defaults to `VPC for ${aws_resource_identifier}`. | |
| 250 | +| `aws_vpc_cidr_block` | String | Define Base CIDR block which is divided into subnet CIDR blocks. Defaults to `10.0.0.0/16`. | |
| 251 | +| `aws_vpc_public_subnets` | String | Comma separated list of public subnets. Defaults to `10.10.110.0/24`| |
| 252 | +| `aws_vpc_private_subnets` | String | Comma separated list of private subnets. If no input, no private subnet will be created. Defaults to `<none>`. | |
| 253 | +| `aws_vpc_availability_zones` | String | Comma separated list of availability zones. Defaults to `aws_default_region+<random>` value. If a list is defined, the first zone will be the one used for the EC2 instance. | |
| 254 | +| `aws_vpc_id` | String | **Existing** AWS VPC ID to use. Accepts `vpc-###` values. | |
| 255 | +| `aws_vpc_subnet_id` | String | **Existing** AWS VPC Subnet ID. If none provided, will pick one. (Ideal when there's only one). | |
| 256 | +| `aws_vpc_additional_tags` | JSON | Add additional tags to the terraform [default tags](https://www.hashicorp.com/blog/default-tags-in-the-terraform-aws-provider), any tags put here will be added to vpc provisioned resources.| |
| 257 | +<br/> |
| 258 | + |
| 259 | +#### **Aurora Outputs** |
| 260 | +| Name | Description | |
| 261 | +|------------------|------------------------------------| |
| 262 | +| `aurora_db_endpoint` | Aurora Endpoint. | |
| 263 | +| `aurora_db_secret_details_name` | AWS Secret name containing db credentials. | |
| 264 | +| `aurora_db_sg_id` | SG ID for the Aurora instance. | |
| 265 | +| `aurora_proxy_endpoint` | Database proxy endpoint. | |
| 266 | +| `aurora_proxy_secret_name` | AWS Secret name containing proxy credentials. | |
| 267 | +| `aurora_proxy_sg_id` | SG ID for the Aurora Proxy instance. | |
| 268 | + |
| 269 | +<br/> |
| 270 | + |
| 271 | +## Contributing |
| 272 | +We would love for you to contribute to [`bitovi/github-actions-deploy-rds`](hhttps://github.com/bitovi/github-actions-deploy-rds). [Issues](https://github.com/bitovi/github-actions-deploy-rds/issues) and [Pull Requests](https://github.com/bitovi/github-actions-deploy-rds/pulls) are welcome! |
| 273 | + |
| 274 | +## License |
| 275 | +The scripts and documentation in this project are released under the [MIT License](https://github.com/bitovi/github-actions-deploy-rds/blob/main/LICENSE). |
| 276 | + |
| 277 | +# Provided by Bitovi |
| 278 | +[Bitovi](https://www.bitovi.com/) is a proud supporter of Open Source software. |
| 279 | + |
| 280 | +# We want to hear from you. |
| 281 | +Come chat with us about open source in our Bitovi community [Discord](https://discord.gg/J7ejFsZnJ4Z)! |
0 commit comments