Skip to content

Commit 83a7142

Browse files
authored
Merge pull request #1 from ludoo/fabric-import-from-internal-module
Initial import from internal modules
2 parents 4e933ac + e6e4b18 commit 83a7142

File tree

26 files changed

+490
-140
lines changed

26 files changed

+490
-140
lines changed

README.md

Lines changed: 42 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
1-
# terraform-google-service-accounts
1+
# Terraform Service Accounts Module
22

3-
This module was generated from [terraform-google-module-template](https://github.com/terraform-google-modules/terraform-google-module-template/), which by default generates a module that simply creates a GCS bucket. As the module develops, this README should be updated.
3+
This module allows easy creation of one or more service accounts, and granting them basic roles.
44

55
The resources/services/activations/deletions that this module will create/trigger are:
66

7-
- Create a GCS bucket with the provided name
7+
- one or more service accounts
8+
- optional project-level IAM role bindings for each service account
9+
- one optional billing IAM role binding per service account, at the organization or billing account level
10+
- two optional organization-level IAM bindings per service account, to enable the service accounts to create and manage Shared VPC networks
11+
- one optional service account key per service account
812

913
## Usage
1014

@@ -14,9 +18,13 @@ Basic usage of this module is as follows:
1418
module "service_accounts" {
1519
source = "terraform-google-modules/service-accounts/google"
1620
version = "~> 0.1"
17-
1821
project_id = "<PROJECT ID>"
19-
bucket_name = "gcs-test-bucket"
22+
prefix = ""
23+
names = ["test-first", "test-second"]
24+
project_roles = [
25+
"project-foo=>roles/viewer",
26+
"project-spam=>roles/storage.objectViewer",
27+
]
2028
}
2129
```
2230

@@ -25,6 +33,30 @@ Functional examples are included in the
2533

2634
[^]: (autogen_docs_start)
2735

36+
## Inputs
37+
38+
| Name | Description | Type | Default | Required |
39+
|------|-------------|:----:|:-----:|:-----:|
40+
| billing\_account\_id | If assigning billing role, specificy a billing account (default is to assign at the organizational level). | string | `""` | no |
41+
| generate\_keys | Generate keys for service accounts. | string | `"false"` | no |
42+
| grant\_billing\_role | Grant billing user role. | string | `"false"` | no |
43+
| grant\_xpn\_roles | Grant roles for shared VPC management. | string | `"true"` | no |
44+
| names | Names of the service accounts to create. | list | `<list>` | no |
45+
| org\_id | Id of the organization for org-level roles. | string | `""` | no |
46+
| prefix | Prefix applied to service account names. | string | `""` | no |
47+
| project\_id | Project id where service account will be created. | string | n/a | yes |
48+
| project\_roles | Common roles to apply to all service accounts, project=>role as elements. | list | `<list>` | no |
49+
50+
## Outputs
51+
52+
| Name | Description |
53+
|------|-------------|
54+
| email | Service account email (single-use case). |
55+
| emails | Map of service account emails. |
56+
| iam\_email | IAM-format service account email (single-use case). |
57+
| iam\_emails | IAM-format service account emails. |
58+
| keys | Map of service account keys. |
59+
2860
[^]: (autogen_docs_end)
2961

3062
## Requirements
@@ -36,28 +68,14 @@ These sections describe requirements for using this module.
3668
The following dependencies must be available:
3769

3870
- [Terraform][terraform] v0.11
39-
- [Terraform Provider for GCP][terraform-provider-gcp] plugin v2.0
40-
41-
### Service Account
42-
43-
A service account with the following roles must be used to provision
44-
the resources of this module:
45-
46-
- Storage Admin: `roles/storage.admin`
47-
48-
The [Project Factory module][project-factory-module] and the
49-
[IAM module][iam-module] may be used in combination to provision a
50-
service account with the necessary roles applied.
51-
52-
### APIs
71+
- [Terraform Provider for GCP][terraform-provider-gcp] plugin >= v2.0
5372

54-
A project with the following APIs enabled must be used to host the
55-
resources of this module:
73+
### IAM
5674

57-
- Google Cloud Storage JSON API: `storage-api.googleapis.com`
75+
Service account or user credentials with the following roles must be used to provision the resources of this module:
5876

59-
The [Project Factory module][project-factory-module] can be used to
60-
provision a project with the necessary APIs enabled.
77+
- Service Account Admin: `roles/iam.serviceAccountAdmin`
78+
- roles needed to grant optional IAM roles at the project or organizational level
6179

6280
## Contributing
6381

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Multiple Service Accounts
2+
3+
This example illustrates how to use the `service-accounts` module to generate multiple service accounts.
4+
5+
[^]: (autogen_docs_start)
6+
7+
## Inputs
8+
9+
| Name | Description | Type | Default | Required |
10+
|------|-------------|:----:|:-----:|:-----:|
11+
| project\_id | The ID of the project in which to provision resources. | string | n/a | yes |
12+
13+
## Outputs
14+
15+
| Name | Description |
16+
|------|-------------|
17+
| emails | The service account emails. |
18+
| iam\_emails | The service account IAM-format emails. |
19+
| keys | The service account keys. |
20+
21+
[^]: (autogen_docs_end)
22+
23+
To provision this example, run the following from within this directory:
24+
- `terraform init` to get the plugins
25+
- `terraform plan` to see the infrastructure plan
26+
- `terraform apply` to apply the infrastructure build
27+
- `terraform destroy` to destroy the built infrastructure
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/**
2+
* Copyright 2019 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
provider "google" {
18+
version = "~> 2.7.0"
19+
}
20+
21+
module "service_accounts" {
22+
source = "../.."
23+
project_id = "${var.project_id}"
24+
prefix = ""
25+
names = ["test-first", "test-second"]
26+
generate_keys = true
27+
28+
project_roles = [
29+
"${var.project_id}=>roles/viewer",
30+
"${var.project_id}=>roles/storage.objectViewer",
31+
]
32+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/**
2+
* Copyright 2019 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
output "emails" {
18+
description = "The service account emails."
19+
value = "${values(module.service_accounts.emails)}"
20+
}
21+
22+
output "iam_emails" {
23+
description = "The service account IAM-format emails."
24+
value = "${values(module.service_accounts.iam_emails)}"
25+
}
26+
27+
output "keys" {
28+
description = "The service account keys."
29+
value = "${module.service_accounts.keys}"
30+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/**
2+
* Copyright 2019 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
variable "project_id" {
18+
description = "The ID of the project in which to provision resources."
19+
type = "string"
20+
}

examples/simple_example/README.md

Lines changed: 0 additions & 13 deletions
This file was deleted.
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Single Service Account
2+
3+
This example illustrates how to use the `service-accounts` module to generate a single service account.
4+
5+
[^]: (autogen_docs_start)
6+
7+
## Inputs
8+
9+
| Name | Description | Type | Default | Required |
10+
|------|-------------|:----:|:-----:|:-----:|
11+
| project\_id | The ID of the project in which to provision resources. | string | n/a | yes |
12+
13+
## Outputs
14+
15+
| Name | Description |
16+
|------|-------------|
17+
| email | The service account email. |
18+
| iam\_email | The service account IAM-format email. |
19+
20+
[^]: (autogen_docs_end)
21+
22+
To provision this example, run the following from within this directory:
23+
- `terraform init` to get the plugins
24+
- `terraform plan` to see the infrastructure plan
25+
- `terraform apply` to apply the infrastructure build
26+
- `terraform destroy` to destroy the built infrastructure
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/**
2+
* Copyright 2019 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
provider "google" {
18+
version = "~> 2.7.0"
19+
}
20+
21+
module "service_accounts" {
22+
source = "../.."
23+
project_id = "${var.project_id}"
24+
prefix = "${var.prefix}"
25+
names = ["single-account"]
26+
project_roles = ["${var.project_id}=>roles/viewer"]
27+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/**
2+
* Copyright 2019 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
output "email" {
18+
description = "The service account email."
19+
value = "${module.service_accounts.email}"
20+
}
21+
22+
output "iam_email" {
23+
description = "The service account IAM-format email."
24+
value = "${module.service_accounts.iam_email}"
25+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/**
2+
* Copyright 2019 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
variable "project_id" {
18+
description = "The ID of the project in which to provision resources."
19+
type = "string"
20+
}
21+
22+
variable "prefix" {
23+
description = "Prefix applied to service account names."
24+
default = ""
25+
}

0 commit comments

Comments
 (0)