|
| 1 | +// Copyright (c) 2017, 2021, Oracle and/or its affiliates. All rights reserved. |
| 2 | +// Licensed under the Mozilla Public License v2.0 |
| 3 | + |
| 4 | +variable "tenancy_ocid" {} |
| 5 | +variable "user_ocid" {} |
| 6 | +variable "fingerprint" {} |
| 7 | +variable "private_key_path" {} |
| 8 | +variable "region" {} |
| 9 | +variable "compartment_ocid" {} |
| 10 | + |
| 11 | +provider "oci" { |
| 12 | + tenancy_ocid = var.tenancy_ocid |
| 13 | + user_ocid = var.user_ocid |
| 14 | + fingerprint = var.fingerprint |
| 15 | + private_key_path = var.private_key_path |
| 16 | + region = var.region |
| 17 | +} |
| 18 | + |
| 19 | +variable "container_image_signature_compartment_id_in_subtree" {} |
| 20 | + |
| 21 | +// specify the container image to upload to |
| 22 | +variable "container_image_id" {} |
| 23 | + |
| 24 | +// specify the management endpoint for the key |
| 25 | +variable "crypto_endpoint" {} |
| 26 | + |
| 27 | +// specify the kms key to sign the message |
| 28 | +variable "kms_rsa_key_id" {} |
| 29 | + |
| 30 | +// specify the kms key version to sign the message |
| 31 | +variable "kms_rsa_key_version_id" {} |
| 32 | + |
| 33 | +// the algorithm to sign with the key |
| 34 | +variable "kms_signing_algorithm" {} |
| 35 | + |
| 36 | +// user inputted description to include in the signature |
| 37 | +variable "description" {} |
| 38 | + |
| 39 | +// user defined a json string to include in the signature (eg. use escape character for the key/value string) |
| 40 | +// ex. "{\\\"buildNumber\\\":\\\"123\\\"}" |
| 41 | +variable "metadata" {} |
| 42 | + |
| 43 | +data "oci_artifacts_container_image" "test_container_image" { |
| 44 | + image_id = var.container_image_id |
| 45 | +} |
| 46 | + |
| 47 | +output "oci_test_container_image" { |
| 48 | + value = data.oci_artifacts_container_image.test_container_image.repository_name |
| 49 | +} |
| 50 | + |
| 51 | +locals { |
| 52 | + message = templatefile("./artifacts_container_image_signature_message_json.tmpl", { |
| 53 | + "description" = var.description |
| 54 | + "digest" = data.oci_artifacts_container_image.test_container_image.digest |
| 55 | + "kms_key_id" = var.kms_rsa_key_id |
| 56 | + "kms_key_version_id" = var.kms_rsa_key_version_id |
| 57 | + "metadata" = var.metadata |
| 58 | + "region" = var.region |
| 59 | + "repository_name" = data.oci_artifacts_container_image.test_container_image.repository_name |
| 60 | + "signing_algorithm" = var.kms_signing_algorithm |
| 61 | + }) |
| 62 | +} |
| 63 | + |
| 64 | +resource "oci_kms_sign" "test_sign" { |
| 65 | + crypto_endpoint = var.crypto_endpoint |
| 66 | + key_id = var.kms_rsa_key_id |
| 67 | + message = base64encode(local.message) |
| 68 | + signing_algorithm = var.kms_signing_algorithm |
| 69 | + |
| 70 | + key_version_id = var.kms_rsa_key_version_id |
| 71 | + message_type = "RAW" |
| 72 | +} |
| 73 | + |
| 74 | +resource "oci_artifacts_container_image_signature" "test_container_image_signature" { |
| 75 | + #Required |
| 76 | + compartment_id = var.compartment_ocid |
| 77 | + image_id = var.container_image_id |
| 78 | + kms_key_id = var.kms_rsa_key_id |
| 79 | + kms_key_version_id = var.kms_rsa_key_version_id |
| 80 | + message = base64encode(local.message) |
| 81 | + signature = oci_kms_sign.test_sign.signature |
| 82 | + signing_algorithm = var.kms_signing_algorithm |
| 83 | +} |
| 84 | + |
| 85 | +data "oci_artifacts_container_image_signatures" "test_container_image_signatures" { |
| 86 | + #Required |
| 87 | + compartment_id = var.compartment_ocid |
| 88 | + |
| 89 | + #Optional |
| 90 | + compartment_id_in_subtree = var.container_image_signature_compartment_id_in_subtree |
| 91 | + image_id = var.container_image_id |
| 92 | + kms_key_id = var.kms_rsa_key_id |
| 93 | +} |
0 commit comments