Skip to content

Commit 40435ce

Browse files
committed
Update README.md
1 parent daf9541 commit 40435ce

File tree

9 files changed

+344
-225
lines changed

9 files changed

+344
-225
lines changed

README.md

Lines changed: 99 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,96 @@
1+
# Features
2+
- Conditional and Dynamic Resource Creation
3+
- Automatic and Manual Branch Creation Support
4+
- Automatic and Manual Branch Deletion Support
5+
- Automatic Build for Branches Support
6+
- Customizable Automatic Branch Creation Patterns Support
7+
- Pull Request Previews Support Support
8+
- CodeCommit, GitHub, GitLab support with examples
9+
- Related workshop for deeper explanation
10+
- [**Automated Deployment of AWS Amplify Apps with Terraform**](https://catalog.workshops.aws/amplify-with-terraform/)
11+
12+
# Basic Usage - CodeCommit Repo with Automatic Branch Creation
13+
14+
```hcl
15+
// This is a template file for a basic deployment.
16+
// Modify the parameters below with actual values
17+
module "sample-qs" {
18+
// location of the module - can be local or git repo
19+
source = "./modules/novekm-static-website-amplify"
20+
21+
22+
app_name = "my-app"
23+
create_codecommit_repo = true
24+
lookup_existing_codecommit_repo = false
25+
// see /examples for sample_build_spec
26+
path_to_build_spec = "novekm/amplify-app/aws"
27+
28+
29+
30+
// Auto Branch Creation
31+
enable_auto_branch_creation = true
32+
enable_auto_branch_deletion = true
33+
auto_branch_creation_patterns = ["main"]
34+
enable_auto_build = true
35+
enable_app_pr_preview = true
36+
app_framework = "Something bloated and hard to maintain"
37+
38+
39+
// - Custom Domain -
40+
create_domain_associations = false
41+
domain_name = "yourdomain.com"
42+
domain_associations = {
43+
core = {
44+
branch_name = "main"
45+
prefix = ""
46+
},
47+
www = {
48+
branch_name = "main"
49+
prefix = "www"
50+
},
51+
}
52+
53+
custom_rewrite_and_redirect = {
54+
// Static website rewrite/redirect
55+
static_site = {
56+
source = "/<*>"
57+
status = "404"
58+
target = "/index.html"
59+
},
60+
// Rewrite/redirect for single page apps - default if you don't specify anything else
61+
# single_page_app = {
62+
# source = "</^[^.]+$|\\.(?!(css|gif|ico|jpg|js|png|txt|svg|woff|ttf|map|json)$)([^.]+$)/>"
63+
# status = "200"
64+
# target = "/index.html"
65+
# },
66+
// Rewrite/redirect for `yourdomain.com/app2` to `yourotherdomain.com`
67+
# app2 = {
68+
# source = "/app2"
69+
# status = "302"
70+
# target = "https://yourotherdomain.com"
71+
# },
72+
}
73+
}
74+
```
75+
76+
# Examples
77+
78+
- [CodeCommit Repo with Auto Branch Creation](https://github.com/novekm/terraform-aws-amplify-app/examples/codecommit-deployment/auto-branch-creation/main.tf)
79+
- [CodeCommit Repo with Manual Branch Creation](https://github.com/novekm/terraform-aws-amplify-app/examples/codecommit-deployment/manual-branch-creation/main.tf)
80+
- [GitHub Repo with Auto Branch Creation](https://github.com/novekm/terraform-aws-amplify-app/examples/github-deployment/auto-branch-creation/main.tf)
81+
- [GitHub Repo with Manual Branch Creation](https://github.com/novekm/terraform-aws-amplify-app/examples/github-deployment/auto-branch-creation/main.tf)
82+
- [GitLab Repo with Auto Branch Creation](https://github.com/novekm/terraform-aws-amplify-app/examples/gitlab-deployment/auto-branch-creation/main.tf)
83+
- [GitLab Repo with Manual Branch Creation](https://github.com/novekm/terraform-aws-amplify-app/examples/gitlab-deployment/auto-branch-creation/main.tf)
84+
85+
# Contributing
86+
87+
Report issues/questions/feature requests on the [issues] page. Reach out to me if you'd like to be a contributor!
88+
89+
90+
# Workshop
91+
For more information, check out my workshop [**Automating Deployment of AWS Amplify Apps with Terraform**](https://catalog.workshops.aws/amplify-with-terraform/)
92+
93+
194
## Requirements
295

396
| Name | Version |
@@ -46,7 +139,7 @@ No modules.
46139
| <a name="input_codecommit_repo_name"></a> [codecommit\_repo\_name](#input\_codecommit\_repo\_name) | n/a | `string` | `"codecommit_repo"` | no |
47140
| <a name="input_create_codecommit_repo"></a> [create\_codecommit\_repo](#input\_create\_codecommit\_repo) | - CodeCommit - | `bool` | `false` | no |
48141
| <a name="input_create_domain_associations"></a> [create\_domain\_associations](#input\_create\_domain\_associations) | Enables default association of your domain with the 'main' branch of the Amplify App. | `bool` | `false` | no |
49-
| <a name="input_custom_rewrite_and_redirect"></a> [custom\_rewrite\_and\_redirect](#input\_custom\_rewrite\_and\_redirect) | Custom rewrites and redirects for the domain associations. | `map(any)` | <pre>{<br> "single_page_app": {<br> "source": "</^[^.]+$|\\.(?!(css|gif|ico|jpg|js|png|txt|svg|woff|ttf|map|json)$)([^.]+$)/>",<br> "status": "200",<br> "target": "/index.html"<br> }<br>}</pre> | no |
142+
| <a name="input_custom_rewrite_and_redirect"></a> [custom\_rewrite\_and\_redirect](#input\_custom\_rewrite\_and\_redirect) | Custom rewrites and redirects for the domain associations. | `map(any)` | `{}` | no |
50143
| <a name="input_domain_associations"></a> [domain\_associations](#input\_domain\_associations) | The domains/subdomains you wish to associate with the Amplify App. These are mapped to git branches. | `map(any)` | `{}` | no |
51144
| <a name="input_domain_name"></a> [domain\_name](#input\_domain\_name) | The name of your domain. Ex. naruto.ninja | `string` | `"example.com"` | no |
52145
| <a name="input_enable_app_pr_preview"></a> [enable\_app\_pr\_preview](#input\_enable\_app\_pr\_preview) | Enables pull request previews for the autocreated branch. | `bool` | `false` | no |
@@ -72,9 +165,9 @@ No modules.
72165

73166
| Name | Description |
74167
|------|-------------|
75-
| <a name="output_amplify_app_arn"></a> [amplify\_app\_arn](#output\_amplify\_app\_arn) | n/a |
76-
| <a name="output_amplify_app_default_domain"></a> [amplify\_app\_default\_domain](#output\_amplify\_app\_default\_domain) | n/a |
77-
| <a name="output_amplify_app_id"></a> [amplify\_app\_id](#output\_amplify\_app\_id) | n/a |
78-
| <a name="output_amplify_app_production_branch"></a> [amplify\_app\_production\_branch](#output\_amplify\_app\_production\_branch) | n/a |
79-
| <a name="output_amplify_app_tags_all"></a> [amplify\_app\_tags\_all](#output\_amplify\_app\_tags\_all) | n/a |
168+
| <a name="output_amplify_app_arn"></a> [amplify\_app\_arn](#output\_amplify\_app\_arn) | The ARN for the Amplify App |
169+
| <a name="output_amplify_app_default_domain"></a> [amplify\_app\_default\_domain](#output\_amplify\_app\_default\_domain) | The default domain for the Amplify App |
170+
| <a name="output_amplify_app_id"></a> [amplify\_app\_id](#output\_amplify\_app\_id) | The App ID for the Amplify App |
171+
| <a name="output_amplify_app_production_branch"></a> [amplify\_app\_production\_branch](#output\_amplify\_app\_production\_branch) | The production branch for the Amplify App |
172+
| <a name="output_amplify_app_tags_all"></a> [amplify\_app\_tags\_all](#output\_amplify\_app\_tags\_all) | All tags for the Amplify App |
80173
| <a name="output_aws_current_region"></a> [aws\_current\_region](#output\_aws\_current\_region) | AWS Current Region |

examples/codecommit-deployment/auto-branch-creation/main.tf

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -4,31 +4,31 @@ module "sample-qs" {
44
// location of the module - can be local or git repo
55
source = "./modules/novekm-static-website-amplify"
66

7-
app_name = "my-app" // Name of the Amplify App - default is 'sample-amplify-app'
8-
create_codecommit_repo = true // Creates CodeCommit repo and necessary permissions for Amplify App to read from it. Default value is `false`
9-
lookup_existing_codecommit_repo = false // Default value - set to `true` if you wish to use an existing CodeCommit repo
7+
app_name = "my-app" // Name of the Amplify App - default is 'sample-amplify-app'
8+
create_codecommit_repo = true // Creates CodeCommit repo and necessary permissions for Amplify App to read from it. Default value is `false`
9+
lookup_existing_codecommit_repo = false // Default value - set to `true` if you wish to use an existing CodeCommit repo
1010
# existing_repo_url = "" // If using the module to create a CodeCommit Repo, the repo's url is already referenced. If using your own repo, change this value to that repo url.
1111

1212
path_to_build_spec = "../amplify.yml" // If you want build_spec to be in a specific file. Only use if you are not using `build_spec
1313

1414
# buildspec = "" // If you want to have your build_spec defined in main.tf - Only use if you are not using `path_to_build_spec`
1515

16-
// For this to work with domain associations, the branch(es) must already exist in your
17-
// connected git repo. See the README for more information.
16+
// For this to work with domain associations, the branch(es) must already exist in your
17+
// connected git repo. See the README for more information.
1818
// Auto Branch Creation
19-
enable_auto_branch_creation = true // Default value is `false` - enables Amplify branches to be automatically created based on the `auto_branch_creation_patterns`. For these to build, `enable_auto_build` must be set to true, and they must exist in your connected git repo.
20-
enable_auto_branch_deletion = true // Default value is `false` Allows for branches in Amplify to automatically be deleted if you delete a branch with the same name from your connected git repo.
19+
enable_auto_branch_creation = true // Default value is `false` - enables Amplify branches to be automatically created based on the `auto_branch_creation_patterns`. For these to build, `enable_auto_build` must be set to true, and they must exist in your connected git repo.
20+
enable_auto_branch_deletion = true // Default value is `false` Allows for branches in Amplify to automatically be deleted if you delete a branch with the same name from your connected git repo.
2121
auto_branch_creation_patterns = ["main"] // Default value - this is the pattern that Amplify will use to decide which branches to auto build. Add additional strings inside the list to add additional branches. Ex. ["main", "dev", "staging"]
22-
enable_auto_build = true // Default value is `false` - auto builds the connected branch if code already exists in it, or is pushed to it.
23-
enable_app_pr_preview = true // Default value is false - adds preview to pull request
24-
enable_performance_mode = false // Default value - caches data longer in CDN
25-
app_framework = "Something bloated and hard to maintain"
22+
enable_auto_build = true // Default value is `false` - auto builds the connected branch if code already exists in it, or is pushed to it.
23+
enable_app_pr_preview = true // Default value is false - adds preview to pull request
24+
enable_performance_mode = false // Default value - caches data longer in CDN
25+
app_framework = "Something bloated and hard to maintain"
2626

2727

2828

2929

3030
// - Custom Domain -
31-
create_domain_associations = false // Default value - set this to `true` after you create branches in your connected git repo and push to them
31+
create_domain_associations = false // Default value - set this to `true` after you create branches in your connected git repo and push to them
3232
domain_name = "yourdomain.com" // The domain you wish to associate with the Amplify App. Do not include the `www.` This value is unused unless `create_domain_associations` is set to true. If set to true, you must also define the associations in `domain_associations`. It is recommended to use a domain managed by Route53 because if it's in the same account/region as your Amplify App, Amplify will automatically do the domain validation for you
3333

3434
// Associates your domain/desired subdomains to git branches. Only takes effect if `create_domain_associations` is set to `true`
@@ -52,25 +52,25 @@ module "sample-qs" {
5252
# }
5353
}
5454

55-
# custom_rewrite_and_redirect = {
56-
# // Static website rewrite/redirect
57-
# # static_site = {
58-
# # source = "/<*>"
59-
# # status = "404"
60-
# # target = "/index.html"
61-
# # }
62-
# // Rewrite/redirect for single page apps - default if you don't specify anything else
63-
# # single_page_app = {
64-
# # source = "</^[^.]+$|\\.(?!(css|gif|ico|jpg|js|png|txt|svg|woff|ttf|map|json)$)([^.]+$)/>"
65-
# # status = "200"
66-
# # target = "/index.html"
67-
# # }
68-
# // Rewrite/redirect for `yourdomain.com/app2` to `yourotherdomain.com`
69-
# # app2 = {
70-
# # source = "/app2"
71-
# # status = "302"
72-
# # target = "https://yourotherdomain.com"
73-
# # }
74-
# }
55+
custom_rewrite_and_redirect = {
56+
// Static website rewrite/redirect
57+
static_site = {
58+
source = "/<*>"
59+
status = "404"
60+
target = "/index.html"
61+
},
62+
// Rewrite/redirect for single page apps - default if you don't specify anything else
63+
# single_page_app = {
64+
# source = "</^[^.]+$|\\.(?!(css|gif|ico|jpg|js|png|txt|svg|woff|ttf|map|json)$)([^.]+$)/>"
65+
# status = "200"
66+
# target = "/index.html"
67+
# },
68+
// Rewrite/redirect for `yourdomain.com/app2` to `yourotherdomain.com`
69+
# app2 = {
70+
# source = "/app2"
71+
# status = "302"
72+
# target = "https://yourotherdomain.com"
73+
# },
74+
}
7575

7676
}

examples/codecommit-deployment/manual-branch-creation/main.tf

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,25 @@ module "sample-qs" {
44
// location of the module - can be local or git repo
55
source = "./modules/novekm-static-website-amplify"
66

7-
app_name = "my-app" // Name of the Amplify App - default is 'sample-amplify-app'
8-
create_codecommit_repo = true // Creates CodeCommit repo and necessary permissions for Amplify App to read from it. Default value is `false`
9-
lookup_existing_codecommit_repo = false // Default value - set to `true` if you wish to use an existing CodeCommit repo
7+
app_name = "my-app" // Name of the Amplify App - default is 'sample-amplify-app'
8+
create_codecommit_repo = true // Creates CodeCommit repo and necessary permissions for Amplify App to read from it. Default value is `false`
9+
lookup_existing_codecommit_repo = false // Default value - set to `true` if you wish to use an existing CodeCommit repo
1010
# existing_repo_url = "" // If using the module to create a CodeCommit Repo, the repo's url is already referenced. If using your own repo, change this value to that repo url.
1111

1212
path_to_build_spec = "../amplify.yml" // If you want build_spec to be in a specific file. Only use if you are not using `build_spec
1313

1414
# buildspec = "" // If you want to have your build_spec defined in main.tf - Only use if you are not using `path_to_build_spec`
1515

16-
// For this to work with domain associations, the branches must already exist in your
17-
// connected git repo. See the README for more information.
16+
// For this to work with domain associations, the branches must already exist in your
17+
// connected git repo. See the README for more information.
1818
// Auto Branch Creation
19-
enable_auto_branch_creation = false // default value is false - enables Amplify branches to be automatically created based on the `auto_branch_creation_patterns`. For these to build, `enable_auto_build` must be set to true, and they must exist in your connected git repo.
20-
enable_auto_branch_deletion = false // allows for branches in Amplify to automatically be deleted if you delete a branch with the same name from your connected git repo.
19+
enable_auto_branch_creation = false // default value is false - enables Amplify branches to be automatically created based on the `auto_branch_creation_patterns`. For these to build, `enable_auto_build` must be set to true, and they must exist in your connected git repo.
20+
enable_auto_branch_deletion = false // allows for branches in Amplify to automatically be deleted if you delete a branch with the same name from your connected git repo.
2121
auto_branch_creation_patterns = ["main", "dev"] // default values - this is the pattern that Amplify will use to decide which branches to auto build. Add additional strings inside the list to add additional branches. Ex. ["main", "dev", "staging"]
22-
enable_auto_build = false // auto builds the connected branch when code exists in it, or is pushed to it.
23-
enable_app_pr_preview = false // default value - adds preview to pull request
24-
enable_performance_mode = false // default value - caches data longer in CDN
25-
app_framework = "Something bloated and hard to maintain"
22+
enable_auto_build = false // auto builds the connected branch when code exists in it, or is pushed to it.
23+
enable_app_pr_preview = false // default value - adds preview to pull request
24+
enable_performance_mode = false // default value - caches data longer in CDN
25+
app_framework = "Something bloated and hard to maintain"
2626

2727

2828
// Use this variable if you wish to create your own branches manually.
@@ -50,7 +50,7 @@ module "sample-qs" {
5050
}
5151

5252
// - Custom Domain -
53-
create_domain_associations = false // Default value - set this to `true` after you create branches in your connected git repo and push to them
53+
create_domain_associations = false // Default value - set this to `true` after you create branches in your connected git repo and push to them
5454
domain_name = "yourdomain.com" // The domain you wish to associate with the Amplify App. Do not include the `www.` This value is unused unless `create_domain_associations` is set to true. If set to true, you must also define the associations in `domain_associations`. It is recommended to use a domain managed by Route53 because if it's in the same account/region as your Amplify App, Amplify will automatically do the domain validation for you
5555

5656
// Associates your domain/desired subdomains to git branches. Only takes effect if `create_domain_associations` is set to `true`
@@ -70,28 +70,28 @@ module "sample-qs" {
7070
# },
7171
dev = {
7272
branch_name = "dev"
73-
prefix = "dev" // Adds association for `dev.yourdomain.com`
73+
prefix = "dev" // Adds association for `dev.yourdomain.com`
7474
}
7575
}
7676

77-
# custom_rewrite_and_redirect = {
78-
# // Static website rewrite/redirect
79-
# # static_site = {
80-
# # source = "/<*>"
81-
# # status = "404"
82-
# # target = "/index.html"
83-
# # }
84-
# // Rewrite/redirect for single page apps - default if you don't specify anything else
85-
# # single_page_app = {
86-
# # source = "</^[^.]+$|\\.(?!(css|gif|ico|jpg|js|png|txt|svg|woff|ttf|map|json)$)([^.]+$)/>"
87-
# # status = "200"
88-
# # target = "/index.html"
89-
# # }
90-
# // Rewrite/redirect for `yourdomain.com/app2` to `yourotherdomain.com`
91-
# # app2 = {
92-
# # source = "/app2"
93-
# # status = "302"
94-
# # target = "https://yourotherdomain.com"
95-
# # }
96-
# }
77+
custom_rewrite_and_redirect = {
78+
// Static website rewrite/redirect
79+
static_site = {
80+
source = "/<*>"
81+
status = "404"
82+
target = "/index.html"
83+
},
84+
// Rewrite/redirect for single page apps - default if you don't specify anything else
85+
# single_page_app = {
86+
# source = "</^[^.]+$|\\.(?!(css|gif|ico|jpg|js|png|txt|svg|woff|ttf|map|json)$)([^.]+$)/>"
87+
# status = "200"
88+
# target = "/index.html"
89+
# },
90+
// Rewrite/redirect for `yourdomain.com/app2` to `yourotherdomain.com`
91+
# app2 = {
92+
# source = "/app2"
93+
# status = "302"
94+
# target = "https://yourotherdomain.com"
95+
# },
96+
}
9797
}

0 commit comments

Comments
 (0)