Skip to content

Commit

Permalink
Merge branch 'master' into enable-multiple-display-name
Browse files Browse the repository at this point in the history
  • Loading branch information
dkuji committed May 23, 2024
2 parents 036a07d + 6905817 commit af33427
Show file tree
Hide file tree
Showing 20 changed files with 1,541 additions and 8 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ crash.log
**/*.tfvars

credentials.json
**/go.sum
**/*.gpg
**/get-key
**/*.zip
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
# Make will use bash instead of sh
SHELL := /usr/bin/env bash

DOCKER_TAG_VERSION_DEVELOPER_TOOLS := 1.19
DOCKER_TAG_VERSION_DEVELOPER_TOOLS := 1.20
DOCKER_IMAGE_DEVELOPER_TOOLS := cft/developer-tools
REGISTRY_URL := gcr.io/cloud-foundation-cicd

Expand Down
22 changes: 21 additions & 1 deletion build/int.cloudbuild.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ steps:
- id: create
name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
args: ['/bin/bash', '-c', 'source /usr/local/bin/task_helper_functions.sh && kitchen_do create']
- id: create-all
waitFor:
- prepare
name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
args: ['/bin/bash', '-c', 'cft test run all --stage init --verbose']
- id: converge
name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
args: ['/bin/bash', '-c', 'source /usr/local/bin/task_helper_functions.sh && kitchen_do converge']
Expand All @@ -36,9 +41,24 @@ steps:
- id: destroy
name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
args: ['/bin/bash', '-c', 'source /usr/local/bin/task_helper_functions.sh && kitchen_do destroy']
- id: apply simple-sa
waitFor:
- create-all
name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
args: ['/bin/bash', '-c', 'cft test run TestSimpleSA --stage apply --verbose']
- id: verify simple-sa
waitFor:
- apply simple-sa
name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
args: ['/bin/bash', '-c', 'cft test run TestSimpleSA --stage verify --verbose']
- id: teardown simple-sa
waitFor:
- verify simple-sa
name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
args: ['/bin/bash', '-c', 'cft test run TestSimpleSA --stage teardown --verbose']
tags:
- 'ci'
- 'integration'
substitutions:
_DOCKER_IMAGE_DEVELOPER_TOOLS: 'cft/developer-tools'
_DOCKER_TAG_VERSION_DEVELOPER_TOOLS: '1.19'
_DOCKER_TAG_VERSION_DEVELOPER_TOOLS: '1.20'
2 changes: 1 addition & 1 deletion build/lint.cloudbuild.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ tags:
- 'lint'
substitutions:
_DOCKER_IMAGE_DEVELOPER_TOOLS: 'cft/developer-tools'
_DOCKER_TAG_VERSION_DEVELOPER_TOOLS: '1.19'
_DOCKER_TAG_VERSION_DEVELOPER_TOOLS: '1.20'
24 changes: 24 additions & 0 deletions examples/simple_sa/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Simple Example

This example shows how to use the `simple-sa` submodule.

<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
## Inputs

| Name | Description | Type | Default | Required |
|------|-------------|------|---------|:--------:|
| project\_id | The ID of the project in which to provision resources. | `string` | n/a | yes |

## Outputs

| Name | Description |
|------|-------------|
| email | Service account email |

<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->

To provision this example, run the following from within this directory:
- `terraform init` to get the plugins
- `terraform plan` to see the infrastructure plan
- `terraform apply` to apply the infrastructure build
- `terraform destroy` to destroy the built infrastructure
27 changes: 27 additions & 0 deletions examples/simple_sa/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/**
* Copyright 2024 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

module "sa" {
source = "terraform-google-modules/service-accounts/google//modules/simple-sa"
version = "~> 4.0"

project_id = var.project_id
name = "simple-account"
project_roles = [
"roles/compute.imageUser",
"roles/compute.networkUser"
]
}
20 changes: 20 additions & 0 deletions examples/simple_sa/outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/**
* Copyright 2024 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

output "email" {
description = "Service account email"
value = module.sa.email
}
20 changes: 20 additions & 0 deletions examples/simple_sa/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/**
* Copyright 2024 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

variable "project_id" {
description = "The ID of the project in which to provision resources."
type = string
}
6 changes: 3 additions & 3 deletions modules/key-distributor/files/function/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/terraform-google-modules/terraform-google-service-accounts/mod
go 1.18

require (
golang.org/x/crypto v0.17.0
golang.org/x/crypto v0.21.0
google.golang.org/api v0.114.0
)

Expand All @@ -16,9 +16,9 @@ require (
github.com/googleapis/enterprise-certificate-proxy v0.2.3 // indirect
github.com/googleapis/gax-go/v2 v2.7.1 // indirect
go.opencensus.io v0.24.0 // indirect
golang.org/x/net v0.17.0 // indirect
golang.org/x/net v0.23.0 // indirect
golang.org/x/oauth2 v0.7.0 // indirect
golang.org/x/sys v0.15.0 // indirect
golang.org/x/sys v0.18.0 // indirect
golang.org/x/text v0.14.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/genproto v0.0.0-20230410155749-daa745c078e1 // indirect
Expand Down
41 changes: 41 additions & 0 deletions modules/simple-sa/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Terraform Simple Service Account module

This submodule creates a service account and optionally grants specified roles on the project.

## Usage

Basic usage of this submodule is as follows:

```hcl
module "sa" {
source = "terraform-google-modules/service-accounts/google//modules/simple-sa"
version = "~> 4.0"
project_id = "<PROJECT ID>"
name = "sa-name"
project_roles = [
"roles/compute.imageUser",
"roles/compute.networkUser"
]
}
```

<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
## Inputs

| Name | Description | Type | Default | Required |
|------|-------------|------|---------|:--------:|
| description | Default description of the created service accounts (defaults to no description) | `string` | `""` | no |
| display\_name | Display name of the created service accounts (defaults to 'Terraform-managed service account') | `string` | `"Terraform-managed service account"` | no |
| name | Name of service account | `string` | n/a | yes |
| project\_id | Project id where service account will be created | `string` | n/a | yes |
| project\_roles | Roles to grant the SA in specified project | `list(string)` | n/a | yes |

## Outputs

| Name | Description |
|------|-------------|
| email | Service account email |
| id | Service account id and email |

<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
29 changes: 29 additions & 0 deletions modules/simple-sa/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/**
* Copyright 2024 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

resource "google_service_account" "sa" {
project = var.project_id
account_id = var.name
display_name = var.display_name
description = var.description
}

resource "google_project_iam_member" "roles" {
for_each = toset(var.project_roles)
project = var.project_id
role = each.value
member = google_service_account.sa.member
}
86 changes: 86 additions & 0 deletions modules/simple-sa/metadata.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
# Copyright 2024 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

apiVersion: blueprints.cloud.google.com/v1alpha1
kind: BlueprintMetadata
metadata:
name: terraform-google-service-accounts
annotations:
config.kubernetes.io/local-config: "true"
spec:
info:
title: Terraform Simple Service Account module
source:
repo: https://github.com/terraform-google-modules/terraform-google-service-accounts.git
sourceType: git
dir: /modules/simple-sa
version: 4.2.3
actuationTool:
flavor: Terraform
version: ">= 0.13.0"
description: {}
content:
examples:
- name: key_distributor
location: examples/key_distributor
- name: multiple_service_accounts
location: examples/multiple_service_accounts
- name: simple_sa
location: examples/simple_sa
- name: single_service_account
location: examples/single_service_account
interfaces:
variables:
- name: description
description: Default description of the created service accounts (defaults to no description)
varType: string
defaultValue: ""
- name: display_name
description: Display name of the created service accounts (defaults to 'Terraform-managed service account')
varType: string
defaultValue: Terraform-managed service account
- name: name
description: Name of service account
varType: string
required: true
- name: project_id
description: Project id where service account will be created
varType: string
required: true
- name: project_roles
description: Roles to grant the SA in specified project
varType: list(string)
required: true
outputs:
- name: email
description: Service account email
- name: id
description: Service account id and email
requirements:
roles:
- level: Project
roles:
- roles/resourcemanager.projectIamAdmin
- roles/iam.serviceAccountAdmin
- roles/iam.serviceAccountUser
- roles/iam.serviceAccountKeyAdmin
- roles/storage.admin
- roles/cloudfunctions.admin
- roles/serviceusage.serviceUsageAdmin
services:
- cloudresourcemanager.googleapis.com
- iam.googleapis.com
- serviceusage.googleapis.com
- cloudfunctions.googleapis.com
- cloudbuild.googleapis.com
28 changes: 28 additions & 0 deletions modules/simple-sa/outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/**
* Copyright 2024 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

output "email" {
description = "Service account email"
value = google_service_account.sa.email
}

output "id" {
description = "Service account id and email"
value = {
id = google_service_account.sa.account_id,
email = google_service_account.sa.email
}
}
Loading

0 comments on commit af33427

Please sign in to comment.