@hiiretail/gcp-infra-generators 1.10.0 → 1.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/generators/common-resources/firebase/README.md +70 -0
- package/dist/generators/common-resources/firebase/generator.json +4 -0
- package/dist/generators/common-resources/firebase/index.js +102 -0
- package/dist/generators/common-resources/firebase/templates/firebase/apps/terragrunt.hcl +38 -0
- package/dist/generators/common-resources/firebase/templates/firebase/firebase.yaml +17 -0
- package/dist/generators/common-resources/firebase/templates/firebase/terragrunt.hcl +38 -0
- package/dist/node_modules/.package-lock.json +1 -1
- package/dist/package.json +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
# Firebase Generator
|
|
2
|
+
|
|
3
|
+
This generator scaffolds Firebase infrastructure configuration for use with Terragrunt and the [terraform-google-firebase](https://github.com/GoogleCloudPlatform/terraform-google-firebase) module (v0.2.3).
|
|
4
|
+
|
|
5
|
+
## Generated Files
|
|
6
|
+
|
|
7
|
+
Located at `infra/{env}/firebase/`:
|
|
8
|
+
|
|
9
|
+
1. **firebase.yaml** - Platform configuration
|
|
10
|
+
2. **terragrunt.hcl** - Firebase multi-platform app registration
|
|
11
|
+
|
|
12
|
+
## File Architecture
|
|
13
|
+
|
|
14
|
+
```text
|
|
15
|
+
infra/
|
|
16
|
+
prod/firebase/
|
|
17
|
+
firebase.yaml
|
|
18
|
+
terragrunt.hcl
|
|
19
|
+
staging/firebase/
|
|
20
|
+
firebase.yaml
|
|
21
|
+
terragrunt.hcl
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
## firebase.yaml Format
|
|
25
|
+
|
|
26
|
+
```yaml
|
|
27
|
+
apps:
|
|
28
|
+
android:
|
|
29
|
+
package_name: "com.example.app"
|
|
30
|
+
ios:
|
|
31
|
+
bundle_id: "com.example.app"
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
- **android.package_name**: Android application ID in reverse-domain format
|
|
35
|
+
- **ios.bundle_id**: iOS bundle identifier in reverse-domain format
|
|
36
|
+
|
|
37
|
+
Either platform section can be removed to stop managing that platform. At least one must remain.
|
|
38
|
+
|
|
39
|
+
## Apps Module Outputs (FCM Config Files)
|
|
40
|
+
|
|
41
|
+
After `terragrunt apply`, the platform SDK config files are available as Terraform outputs:
|
|
42
|
+
|
|
43
|
+
| Output | Platform | File |
|
|
44
|
+
| ---------------- | -------- | ------------------------------------------- |
|
|
45
|
+
| `android_config` | Android | `google-services.json` (base64-encoded) |
|
|
46
|
+
| `apple_config` | iOS | `GoogleService-Info.plist` (base64-encoded) |
|
|
47
|
+
|
|
48
|
+
Decode and save the files from `infra/{env}/firebase/`:
|
|
49
|
+
|
|
50
|
+
```bash
|
|
51
|
+
# Android
|
|
52
|
+
terragrunt output -raw android_config | base64 --decode > google-services.json
|
|
53
|
+
|
|
54
|
+
# iOS
|
|
55
|
+
terragrunt output -raw apple_config | base64 --decode > GoogleService-Info.plist
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
## Terragrunt Configuration
|
|
59
|
+
|
|
60
|
+
The `terragrunt.hcl` reads from the `firebase.yaml` in the same directory:
|
|
61
|
+
|
|
62
|
+
```hcl
|
|
63
|
+
locals {
|
|
64
|
+
config = yamldecode(file("${get_terragrunt_dir()}/firebase.yaml"))
|
|
65
|
+
}
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
```bash
|
|
69
|
+
terragrunt apply --terragrunt-working-dir infra/prod/firebase
|
|
70
|
+
```
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
const path = require('path');
|
|
2
|
+
const chalk = require('chalk');
|
|
3
|
+
const BaseGenerator = require('../../../src/BaseGenerator');
|
|
4
|
+
const { required } = require('../../../src/validators');
|
|
5
|
+
|
|
6
|
+
module.exports = class extends BaseGenerator {
|
|
7
|
+
prompting() {
|
|
8
|
+
const prompts = [
|
|
9
|
+
{
|
|
10
|
+
type: 'input',
|
|
11
|
+
name: 'appDisplayName',
|
|
12
|
+
message: 'App display name (shared across all platforms):',
|
|
13
|
+
validate: required,
|
|
14
|
+
},
|
|
15
|
+
{
|
|
16
|
+
type: 'checkbox',
|
|
17
|
+
name: 'platforms',
|
|
18
|
+
message: 'Which platforms do you want to register Firebase apps for?',
|
|
19
|
+
choices: [
|
|
20
|
+
{ name: 'Android', value: 'android', checked: true },
|
|
21
|
+
{ name: 'iOS', value: 'ios', checked: true },
|
|
22
|
+
],
|
|
23
|
+
validate: (selected) =>
|
|
24
|
+
selected.length > 0 || 'Select at least one platform.',
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
when: (response) => response.platforms.includes('android'),
|
|
28
|
+
type: 'input',
|
|
29
|
+
name: 'androidPackageName',
|
|
30
|
+
message:
|
|
31
|
+
'Android package name - letters, digits, underscores, and dots only, no hyphens (e.g. com.example_app.checkout):',
|
|
32
|
+
validate: required,
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
when: (response) => response.platforms.includes('ios'),
|
|
36
|
+
type: 'input',
|
|
37
|
+
name: 'iosBundleId',
|
|
38
|
+
message:
|
|
39
|
+
'iOS bundle ID - letters, digits, hyphens, and dots only, no underscores (e.g. com.example-app.checkout):',
|
|
40
|
+
validate: required,
|
|
41
|
+
},
|
|
42
|
+
];
|
|
43
|
+
|
|
44
|
+
return this.prompt(prompts).then((props) => {
|
|
45
|
+
this.answers = props;
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
writing() {
|
|
50
|
+
const {
|
|
51
|
+
appDisplayName,
|
|
52
|
+
platforms = [],
|
|
53
|
+
androidPackageName,
|
|
54
|
+
iosBundleId,
|
|
55
|
+
} = this.answers;
|
|
56
|
+
|
|
57
|
+
const yamlContext = {
|
|
58
|
+
appDisplayName,
|
|
59
|
+
platforms,
|
|
60
|
+
androidPackageName,
|
|
61
|
+
iosBundleId,
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
['prod', 'staging'].forEach((env) => {
|
|
65
|
+
const firebaseDest = path.join('infra', env, 'firebase');
|
|
66
|
+
|
|
67
|
+
this.fs.copyTpl(
|
|
68
|
+
this.templatePath('firebase', 'firebase.yaml'),
|
|
69
|
+
this.destinationPath(firebaseDest, 'firebase.yaml'),
|
|
70
|
+
yamlContext,
|
|
71
|
+
);
|
|
72
|
+
|
|
73
|
+
this.fs.copy(
|
|
74
|
+
this.templatePath('firebase', 'terragrunt.hcl'),
|
|
75
|
+
this.destinationPath(firebaseDest, 'terragrunt.hcl'),
|
|
76
|
+
);
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
end() {
|
|
81
|
+
const header = chalk.green(
|
|
82
|
+
'Your Firebase configuration has been created. Review the generated files:',
|
|
83
|
+
);
|
|
84
|
+
let message = header;
|
|
85
|
+
let i = 1;
|
|
86
|
+
|
|
87
|
+
message += `\n${chalk.green(`${i++}.`)} ${chalk.cyan(path.join('firebase', 'firebase.yaml'))} - Shared Firebase configuration`;
|
|
88
|
+
message += `\n${chalk.green(`${i++}.`)} ${chalk.cyan(path.join('firebase', 'terragrunt.hcl'))} - Firebase apps module`;
|
|
89
|
+
|
|
90
|
+
message += chalk.yellow(
|
|
91
|
+
'\n\nAfter applying, retrieve the FCM config files from infra/{env}/firebase/:',
|
|
92
|
+
);
|
|
93
|
+
message += chalk.cyan(
|
|
94
|
+
'\n terragrunt output -raw android_config | base64 --decode > google-services.json',
|
|
95
|
+
);
|
|
96
|
+
message += chalk.cyan(
|
|
97
|
+
'\n terragrunt output -raw apple_config | base64 --decode > GoogleService-Info.plist',
|
|
98
|
+
);
|
|
99
|
+
|
|
100
|
+
this.log(`\n${message}\n`);
|
|
101
|
+
}
|
|
102
|
+
};
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
# Terragrunt configuration for Firebase multi-platform application
|
|
2
|
+
# https://github.com/GoogleCloudPlatform/terraform-google-firebase
|
|
3
|
+
|
|
4
|
+
terraform {
|
|
5
|
+
source = "git::https://github.com/extenda/terraform-google-firebase//modules/firebase_multi_platform_application/apps?ref=feat/Add-wrapper-apps-around-multi-application-module"
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
include {
|
|
9
|
+
path = find_in_parent_folders("terragrunt_root.hcl")
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
generate "firebase_providers" {
|
|
13
|
+
path = "firebase_providers.tf"
|
|
14
|
+
if_exists = "overwrite_terragrunt"
|
|
15
|
+
contents = <<EOF
|
|
16
|
+
provider "google" {
|
|
17
|
+
project = var.project_id
|
|
18
|
+
billing_project = var.project_id
|
|
19
|
+
user_project_override = true
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
provider "google-beta" {
|
|
23
|
+
project = var.project_id
|
|
24
|
+
billing_project = var.project_id
|
|
25
|
+
user_project_override = true
|
|
26
|
+
}
|
|
27
|
+
EOF
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
locals {
|
|
31
|
+
project_vars = read_terragrunt_config(find_in_parent_folders("project.hcl"))
|
|
32
|
+
config = yamldecode(file("${get_terragrunt_dir()}/../firebase.yaml"))
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
inputs = {
|
|
36
|
+
project_id = local.project_vars.locals.project_id
|
|
37
|
+
apps = local.config.apps
|
|
38
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# Firebase configuration
|
|
2
|
+
#
|
|
3
|
+
# Naming conventions per platform:
|
|
4
|
+
# android.package_name — Java package notation: letters, digits, underscores, and dots only.
|
|
5
|
+
# No hyphens. Example: com.example_app.checkout
|
|
6
|
+
# ios.bundle_id — Reverse DNS notation: letters, digits, hyphens, and dots only.
|
|
7
|
+
# No underscores. Example: com.example-app.checkout
|
|
8
|
+
apps:
|
|
9
|
+
- display_name: "<%- appDisplayName %>"
|
|
10
|
+
<% if (platforms.includes('android')) { -%>
|
|
11
|
+
android:
|
|
12
|
+
package_name: <%- androidPackageName %>
|
|
13
|
+
<% } -%>
|
|
14
|
+
<% if (platforms.includes('ios')) { -%>
|
|
15
|
+
ios:
|
|
16
|
+
bundle_id: <%- iosBundleId %>
|
|
17
|
+
<% } -%>
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
# Terragrunt configuration for Firebase multi-platform application
|
|
2
|
+
# https://github.com/GoogleCloudPlatform/terraform-google-firebase
|
|
3
|
+
|
|
4
|
+
terraform {
|
|
5
|
+
source = "git::https://github.com/extenda/terraform-google-firebase//modules/firebase_multi_platform_application/apps?ref=v1.0.0"
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
include {
|
|
9
|
+
path = find_in_parent_folders("terragrunt_root.hcl")
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
generate "firebase_providers" {
|
|
13
|
+
path = "firebase_providers.tf"
|
|
14
|
+
if_exists = "overwrite_terragrunt"
|
|
15
|
+
contents = <<EOF
|
|
16
|
+
provider "google" {
|
|
17
|
+
project = var.project_id
|
|
18
|
+
billing_project = var.project_id
|
|
19
|
+
user_project_override = true
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
provider "google-beta" {
|
|
23
|
+
project = var.project_id
|
|
24
|
+
billing_project = var.project_id
|
|
25
|
+
user_project_override = true
|
|
26
|
+
}
|
|
27
|
+
EOF
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
locals {
|
|
31
|
+
project_vars = read_terragrunt_config(find_in_parent_folders("project.hcl"))
|
|
32
|
+
config = yamldecode(file("${get_terragrunt_dir()}/firebase.yaml"))
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
inputs = {
|
|
36
|
+
project_id = local.project_vars.locals.project_id
|
|
37
|
+
apps = local.config.apps
|
|
38
|
+
}
|
|
@@ -11528,7 +11528,7 @@
|
|
|
11528
11528
|
},
|
|
11529
11529
|
"packages/generators": {
|
|
11530
11530
|
"name": "@hiiretail/gcp-infra-generators",
|
|
11531
|
-
"version": "1.
|
|
11531
|
+
"version": "1.11.0",
|
|
11532
11532
|
"license": "MIT",
|
|
11533
11533
|
"dependencies": {
|
|
11534
11534
|
"@google-cloud/storage": "^7.18.0",
|
package/dist/package.json
CHANGED