Skip to content

Commit c56b451

Browse files
authored
API key (#30)
* Added possibility to use existing API key
1 parent 4cdfa5c commit c56b451

File tree

6 files changed

+34
-8
lines changed

6 files changed

+34
-8
lines changed

config-repo.tf

+3-3
Original file line numberDiff line numberDiff line change
@@ -20,20 +20,20 @@ resource "oci_devops_repository" "config_repo" {
2020
resource "tls_private_key" "rsa_api_key" {
2121
algorithm = "RSA"
2222
rsa_bits = 4096
23-
count = (local.use-image ? 0 : 1)
23+
count = (local.use-image && !var.use_existing_api_key ? 0 : 1)
2424
}
2525

2626
resource "oci_identity_api_key" "user_api_key" {
2727
#Required
2828
key_value = tls_private_key.rsa_api_key[0].public_key_pem
2929
user_id = var.current_user_ocid
30-
count = (local.use-image ? 0 : 1)
30+
count = (local.use-image || var.use_existing_api_key ? 0 : 1)
3131
}
3232

3333
resource "local_file" "api_private_key" {
3434
depends_on = [ tls_private_key.rsa_api_key ]
3535
filename = "${path.module}/api-private-key.pem"
36-
content = tls_private_key.rsa_api_key[0].private_key_pem
36+
content = (var.use_existing_api_key ? base64decode(var.api_key) : tls_private_key.rsa_api_key[0].private_key_pem)
3737
count = (local.use-image ? 0 : 1)
3838
}
3939

interface.yaml

+13
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ variableGroups:
3131
###APPLICATION_GROUP###
3232
- title: "Stack authentication"
3333
variables:
34+
- use_existing_api_key
35+
- api_key
3436
- use_existing_vault
3537
- new_vault_display_name
3638
- vault_compartment_id
@@ -203,6 +205,17 @@ variables:
203205
and:
204206
- use_existing_database
205207
# Vault
208+
use_existing_api_key:
209+
type: boolean
210+
title: Use an existing API key
211+
required: true
212+
default: false
213+
description: The API key will be used to authenticate the user when using the OCI devops repository
214+
api_key:
215+
type: file
216+
title: Private key
217+
required: true
218+
visible: use_existing_api_key
206219
use_existing_vault:
207220
type: boolean
208221
title: Use an existing key vault

listing/usage-information.html

+5-5
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,10 @@
5151
</li>
5252
</ul>
5353

54-
<p><strong>Stack authentication</strong>: a Vault is used to store sensitive information such as authentication tokens
55-
and passwords.&nbsp;The stack can either use an existing vault or create a new one.&nbsp;To use an existing key vault,
56-
the stack will let you select the existing vault and key (AES). To create a new vault you must provide
57-
the&nbsp;user-friendly name of the vault to create.</p>
54+
<p><strong>Stack authentication</strong>: the stack uses an API key to connect to the repository. A&nbsp;Vault is used
55+
to store sensitive information such as passwords.&nbsp;The stack can either use an existing vault or create a new
56+
one.&nbsp;To use an existing key vault, the stack will let you select the existing vault and key (AES). To create a
57+
new vault you must provide the&nbsp;user-friendly name of the vault to create.</p>
5858

5959
<p><strong>Database</strong>: The stack assumes that the persistence is handled by a database and this section lets you
6060
configure that database. You can either choose an existing database by selecting the database or create a new one.</p>
@@ -167,7 +167,7 @@
167167
balancer and the application. If you chose to <em>open the load balancer to the internet</em>, the load balancer
168168
subnet will be a public subnet and an Internet Gateway will be created. A <strong>reserved IP</strong> address can
169169
be used as the load balancer&#39;s public IP.</li>
170-
<li>A c<strong>ertificate</strong> can be provided for the application URL</li>
170+
<li>A <strong>certificate </strong>can be provided for the application URL</li>
171171
</ul>
172172

173173
<p>By default the <em>load balancer</em> is configured with minimum and maximum bandwidth of 10Mbps, the health check

screenshots/7_Vault.png

11.6 KB
Loading

usage_instructions.md

+3
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ The stack supports different kinds of deployments: *source code* deployment, jav
4242

4343
![](./screenshots/7_Vault.png)
4444

45+
46+
An **API key** is used to authenticate the user when connecting to the code repository. The stack can either create a new API key or use an existing API key if the **private key** is provided.
47+
4548
A **Vault** is used to store sensitive information such as authentication tokens and passwords. The stack can either use an existing vault (which can be in a different compartment) or create a new one.
4649

4750
To use an existing key vault :

variables.tf

+10
Original file line numberDiff line numberDiff line change
@@ -410,6 +410,16 @@ variable "reserved_ip_address" {
410410
default = ""
411411
}
412412

413+
variable "use_existing_api_key" {
414+
type = bool
415+
default = false
416+
}
417+
418+
variable "api_key" {
419+
type = string
420+
default = "none"
421+
}
422+
413423
locals {
414424
# application name with branch
415425
application_name = (var.branch == "" ? var.application_name : "${var.application_name}-${var.branch}")

0 commit comments

Comments
 (0)