Skip to content

Commit

Permalink
allow setting a project on oslogin ssh key (#4085)
Browse files Browse the repository at this point in the history
  • Loading branch information
danawillow authored Oct 12, 2020
1 parent 6714969 commit da4519a
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 4 deletions.
14 changes: 10 additions & 4 deletions products/oslogin/api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,13 @@ objects:
The user email.
input: true
url_param_only: true
required: true
required: true
- !ruby/object:Api::Type::String
name: fingerprint
name: project
description: |
The SHA-256 fingerprint of the SSH public key.
output: true
The project ID of the Google Cloud Platform project.
input: true
url_param_only: true
properties:
- !ruby/object:Api::Type::String
name: 'key'
Expand All @@ -66,3 +67,8 @@ objects:
description: |
An expiration time in microseconds since epoch.
required: false
- !ruby/object:Api::Type::String
name: fingerprint
description: |
The SHA-256 fingerprint of the SSH public key.
output: true
6 changes: 6 additions & 0 deletions products/oslogin/terraform.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,11 @@ overrides: !ruby/object:Overrides::ResourceOverrides
- !ruby/object:Provider::Terraform::Examples
name: "os_login_ssh_key_provided_user"
primary_resource_id: "cache"
- !ruby/object:Provider::Terraform::Examples
name: "os_login_ssh_key_with_project"
primary_resource_id: "cache"
test_env_vars:
project: :PROJECT_NAME
custom_code: !ruby/object:Provider::Terraform::CustomCode
pre_create: templates/terraform/pre_create/os_login_ssh_public_key.go.erb
post_create: templates/terraform/post_create/sshkeyfingerprint.go.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
data "google_client_openid_userinfo" "me" {
}

resource "google_os_login_ssh_public_key" "<%= ctx[:primary_resource_id] %>" {
user = data.google_client_openid_userinfo.me.email
key = file("path/to/id_rsa.pub")
project = "<%= ctx[:test_env_vars]['project'] -%>"
}
22 changes: 22 additions & 0 deletions templates/terraform/pre_create/os_login_ssh_public_key.go.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<%# The license inside this block applies to this file.
# Copyright 2020 Google Inc.
# 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.
-%>
// Don't use `getProject()` because we only want to set the project in the URL
// if the user set it explicitly on the resource.
if p, ok := d.GetOk("project"); ok {
url, err = addQueryParams(url, map[string]string{"projectId": p.(string)})
if err != nil {
return err
}
}

0 comments on commit da4519a

Please sign in to comment.