From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5A2393C3C for ; Tue, 1 Apr 2025 01:00:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743469216; cv=none; b=JdYXGw4odAavFz8f0VYHhH/Vf3B+jJbhuKnDf2KEimmURTcKSUAgCkp7ZoWnaCXpf1L5hL8PbpcCgwqofHMdqDy7aXkcgcWHL3iSRU4Ore1SSzXsTavuDM7uPW3iIk3iNOPp9M7+d29bWX9EkfRYjP9IrZv+hbvbJEnAFIQ1mNQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743469216; c=relaxed/simple; bh=/iMVqgvzS2P0/8744cRcjOpp3/smKm7ZfThWLtgmGNg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=O1w50BIZ4J0RhVgOM0M3G9PK7hevcgwaeZMA0Uzya7YssT4li20zsGdEvV+Wk6MvSE+UozXNdsDH5rJ2cp/qFoxDmPF8xBQby1dGYAjA8oVXeH24BWqM25wtiSitw79pSU2C62FYT6rZTIO3K2N1s/p29Sng+FjuJabZi1G7PW4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=TK/bCS6u; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="TK/bCS6u" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7A84DC4CEE3; Tue, 1 Apr 2025 01:00:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1743469215; bh=/iMVqgvzS2P0/8744cRcjOpp3/smKm7ZfThWLtgmGNg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=TK/bCS6uZ+dy921zD1ZhMFX/nDcvyk2lzV6XIBcR2wty4TWq5k1LpVaNwL9lP1mk1 sDXlWrQfucW4TmocZLDDFyrB3EFfleAV4IAnzMbfdP9yYjwv4MMuegCmqbaz0zSGAS uYbZ2l3XfCC8/itXuXKH9cgaCs6kdxRQjFnVdq64GV/sC/mt4GHZFAn20bi5rNTYRZ jYg7szBb2cvLvcPzqO15FkQxkt21d/TTEFexTCGMdzyS90tKUqIgUQy+UfUimAu/RR Dv86+PmnHvAsyhZlmiwKKsBB+2b36cKE7i9YvsZc3L5Gq4es/RriQd4zi+KvIYu6e6 DyR4MnvMG4Y1g== From: cel@kernel.org To: Cc: Chandan Babu R , Chuck Lever Subject: [RFC PATCH 14/31] terraform/OCI: Select your compartment by name instead of by OCID Date: Mon, 31 Mar 2025 20:59:43 -0400 Message-ID: <20250401010000.764234-15-cel@kernel.org> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250401010000.764234-1-cel@kernel.org> References: <20250401010000.764234-1-cel@kernel.org> Precedence: bulk X-Mailing-List: kdevops@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Chuck Lever Terraform provides a data source that can map a human-readable compartment name to an OCID. This avoids the need to copy and paste the compartment OCID blob from the OCI cloud console. Just use the human-readable compartment name. Signed-off-by: Chuck Lever --- .../templates/oci/terraform.tfvars.j2 | 2 +- scripts/terraform.Makefile | 1 - terraform/oci/kconfigs/Kconfig.location | 9 ++++----- terraform/oci/main.tf | 18 +++++++++++++----- terraform/oci/vars.tf | 10 +++++----- 5 files changed, 23 insertions(+), 17 deletions(-) diff --git a/playbooks/roles/gen_tfvars/templates/oci/terraform.tfvars.j2 b/playbooks/roles/gen_tfvars/templates/oci/terraform.tfvars.j2 index 864d5d5a89f0..be0c154802ff 100644 --- a/playbooks/roles/gen_tfvars/templates/oci/terraform.tfvars.j2 +++ b/playbooks/roles/gen_tfvars/templates/oci/terraform.tfvars.j2 @@ -4,7 +4,7 @@ oci_user_ocid = "{{ terraform_oci_user_ocid }}" oci_user_private_key_path = "{{ terraform_oci_user_private_key_path }}" oci_user_fingerprint = "{{ terraform_oci_user_fingerprint }}" oci_ad_number = {{ terraform_oci_ad_number }} -oci_compartment_ocid = "{{ terraform_oci_compartment_ocid }}" +oci_compartment_name = "{{ terraform_oci_compartment_name }}" oci_shape = "{{ terraform_oci_shape }}" oci_instance_flex_ocpus = {{ terraform_oci_instance_flex_ocpus }} oci_instance_flex_memory_in_gbs = {{ terraform_oci_instance_flex_memory_in_gbs }} diff --git a/scripts/terraform.Makefile b/scripts/terraform.Makefile index 0aca0b508086..02db2569ee08 100644 --- a/scripts/terraform.Makefile +++ b/scripts/terraform.Makefile @@ -95,7 +95,6 @@ TERRAFORM_EXTRA_VARS += terraform_gce_credentials=$(subst ",,$(CONFIG_TERRAFORM_ endif ifeq (y,$(CONFIG_TERRAFORM_OCI)) -TERRAFORM_EXTRA_VARS += terraform_oci_compartment_ocid=$(subst ",,$(CONFIG_TERRAFORM_OCI_COMPARTMENT_OCID)) TERRAFORM_EXTRA_VARS += terraform_oci_shape=$(subst ",,$(CONFIG_TERRAFORM_OCI_SHAPE)) TERRAFORM_EXTRA_VARS += terraform_oci_instance_flex_ocpus=$(subst ",,$(CONFIG_TERRAFORM_OCI_INSTANCE_FLEX_OCPUS)) TERRAFORM_EXTRA_VARS += terraform_oci_instance_flex_memory_in_gbs=$(subst ",,$(CONFIG_TERRAFORM_OCI_INSTANCE_FLEX_MEMORY_IN_GBS)) diff --git a/terraform/oci/kconfigs/Kconfig.location b/terraform/oci/kconfigs/Kconfig.location index 7bf5ae49ba03..eff58202f8c7 100644 --- a/terraform/oci/kconfigs/Kconfig.location +++ b/terraform/oci/kconfigs/Kconfig.location @@ -45,9 +45,8 @@ source "terraform/oci/kconfigs/regions/Kconfig.us-chicago-1" source "terraform/oci/kconfigs/regions/Kconfig.us-phoenix-1" source "terraform/oci/kconfigs/regions/Kconfig.us-sanjose-1" -config TERRAFORM_OCI_COMPARTMENT_OCID - string "OCI compartment OCID" +config TERRAFORM_OCI_COMPARTMENT_NAME + string "OCI compartment name" + output yaml help - The OCI ID of user's compartment. - Read this: - https://docs.oracle.com/en-us/iaas/Content/API/SDKDocs/terraformproviderconfiguration.htm + The compartment name where your instances are to be created. diff --git a/terraform/oci/main.tf b/terraform/oci/main.tf index 5520fdbed517..6991644d83b8 100644 --- a/terraform/oci/main.tf +++ b/terraform/oci/main.tf @@ -1,3 +1,11 @@ +data "oci_identity_compartments" "kdevops_compartment" { + access_level = "ANY" + compartment_id = var.oci_tenancy_ocid + compartment_id_in_subtree = true + name = var.oci_compartment_name + state = "ACTIVE" +} + data "oci_identity_availability_domain" "kdevops_av_domain" { ad_number = var.oci_ad_number compartment_id = var.oci_tenancy_ocid @@ -7,8 +15,8 @@ resource "oci_core_instance" "kdevops_instance" { count = local.kdevops_num_boxes availability_domain = data.oci_identity_availability_domain.kdevops_av_domain.name - compartment_id = var.oci_compartment_ocid - shape = var.oci_shape + compartment_id = data.oci_identity_compartments.kdevops_compartment.compartments[0].id + shape = var.oci_shape shape_config { memory_in_gbs = var.oci_instance_flex_memory_in_gbs ocpus = var.oci_instance_flex_ocpus @@ -36,7 +44,7 @@ resource "oci_core_volume" "kdevops_data_disk" { count = var.oci_volumes_enable_extra == "true" ? 0 : local.kdevops_num_boxes availability_domain = data.oci_identity_availability_domain.kdevops_av_domain.name - compartment_id = var.oci_compartment_ocid + compartment_id = data.oci_identity_compartments.kdevops_compartment.compartments[0].id display_name = var.oci_data_volume_display_name size_in_gbs = 50 } @@ -45,7 +53,7 @@ resource "oci_core_volume" "kdevops_sparse_disk" { count = var.oci_volumes_enable_extra == "true" ? 0 : local.kdevops_num_boxes availability_domain = data.oci_identity_availability_domain.kdevops_av_domain.name - compartment_id = var.oci_compartment_ocid + compartment_id = data.oci_identity_compartments.kdevops_compartment.compartments[0].id display_name = var.oci_sparse_volume_display_name size_in_gbs = 120 } @@ -75,7 +83,7 @@ module "volumes" { source = "./volumes" vol_availability_domain = data.oci_identity_availability_domain.kdevops_av_domain.name - vol_compartment_ocid = var.oci_compartment_ocid + vol_compartment_ocid = data.oci_identity_compartments.kdevops_compartment.compartments[0].id vol_instance_id = element(oci_core_instance.kdevops_instance.*.id, count.index) vol_instance_name = element(var.kdevops_nodes, count.index) vol_volume_count = var.oci_volumes_per_instance diff --git a/terraform/oci/vars.tf b/terraform/oci/vars.tf index 05c3f3769e94..f760fbb776fa 100644 --- a/terraform/oci/vars.tf +++ b/terraform/oci/vars.tf @@ -3,6 +3,11 @@ variable "oci_ad_number" { type = number } +variable "oci_compartment_name" { + description = "Name of compartment in which to create resources" + type = string +} + variable "oci_region" { description = "An OCI region" type = string @@ -28,11 +33,6 @@ variable "oci_user_fingerprint" { type = string } -variable "oci_compartment_ocid" { - description = "OCID of compartment" - type = string -} - variable "oci_shape" { description = "Shape name" type = string -- 2.48.1