From 4dfe89ebbbfb8dc01a61f6d10b2049ce2fc62381 Mon Sep 17 00:00:00 2001 From: arnol377 Date: Tue, 17 Dec 2024 17:56:16 -0500 Subject: [PATCH] Refactor AMI configuration in morpheus.tf and add base_images.tf and variables.tf This commit refactors the AMI configuration in morpheus.tf by introducing a local variable for the AMI ID and updating the module configuration accordingly. Additionally, it adds the base_images.tf file, which contains a data source for the AWS SSM parameter "rhel9_ami". Finally, it includes the variables.tf file, which defines the "use_rhel9_ami" variable to control whether to use the RHEL 9 AMI. --- base_images.tf | 4 ++++ morpheus.tf | 7 ++++--- variables.tf | 5 +++++ 3 files changed, 13 insertions(+), 3 deletions(-) create mode 100644 base_images.tf create mode 100644 variables.tf diff --git a/base_images.tf b/base_images.tf new file mode 100644 index 0000000..ba6a94c --- /dev/null +++ b/base_images.tf @@ -0,0 +1,4 @@ +data aws_ssm_parameter "rhel9_ami" { + count = var.use_rhel9_ami ? 1 : 0 + name = "/enterprise/ami/rhel9" +} \ No newline at end of file diff --git a/morpheus.tf b/morpheus.tf index 3ec5e02..55e7af7 100644 --- a/morpheus.tf +++ b/morpheus.tf @@ -1,5 +1,5 @@ -data aws_ssm_parameter "rhel9_ami" { - name = "/enterprise/ami/rhel9" +locals { + morpheus_ami = "ami-04a32122e0bdbb20f" } module "morpheus" { @@ -23,6 +23,7 @@ module "morpheus" { name = aws_s3_bucket.assets_bucket.bucket key = "linux-image-pipeline.zip" } + packer_config = "morpheus-build.pkr.hcl" ansible_source_type = "S3" ansible_bucket = { name = aws_s3_bucket.assets_bucket.bucket @@ -38,7 +39,7 @@ module "morpheus" { state = local.state_config vpc_config = local.vpc_config ami = { - source_ami = data.aws_ssm_parameter.rhel9_ami.value + source_ami = var.use_rhel9_ami ? one(data.aws_ssm_parameter.rhel9_ami).value : local.morpheus_ami instance_type = "t3.micro" # x86_64 compatible instance type } } diff --git a/variables.tf b/variables.tf new file mode 100644 index 0000000..884103b --- /dev/null +++ b/variables.tf @@ -0,0 +1,5 @@ +variable use_rhel9_ami { + description = "Use RHEL 9 AMI" + type = bool + default = false +} \ No newline at end of file