From fec7d2d66d1960cc085c8d4d98f92074843ff7f3 Mon Sep 17 00:00:00 2001 From: mark roberts Date: Fri, 3 May 2024 16:38:51 +0100 Subject: [PATCH] code changes to fix unit tests --- main.tf | 52 ++++++++++++++++++------------------- test/module_test.go | 2 +- test/unit-test/main.tf | 2 +- test/unit-test/variables.tf | 14 ++++++++++ 4 files changed, 42 insertions(+), 28 deletions(-) create mode 100644 test/unit-test/variables.tf diff --git a/main.tf b/main.tf index 5c6d1e7..fb30fcd 100644 --- a/main.tf +++ b/main.tf @@ -1,10 +1,10 @@ -provider "aws" { - alias = "core-vpc" - region = "eu-west-2" - assume_role { - role_arn = "arn:aws:iam::${var.environment_management.account_ids[var.provider_name]}:role/member-delegation-${local.vpc_name}-${var.app_name}" - } -} +# provider "aws" { +# alias = "core-vpc" +# region = "eu-west-2" +# assume_role { +# role_arn = "arn:aws:iam::${var.environment_management.account_ids[var.provider_name]}:role/member-delegation-${local.vpc_name}-${var.app_name}" +# } +# } resource "aws_acm_certificate" "certificate" { @@ -18,24 +18,24 @@ resource "aws_acm_certificate" "certificate" { } -# resource "aws_route53_record" "cert_validation" { -# provider = aws.core-network-services -# depends_on = [ aws_acm_certificate.certificate ] -# for_each = { -# for val in aws_acm_certificate.certificate.domain_validation_options : val.domain_name => { -# name = val.resource_record_name -# record = val.resource_record_value -# type = val.resource_record_type -# } -# } -# zone_id = var.fqdn -# name = each.value.name -# records = [each.value.record] -# type = var.record_type -# } +resource "aws_route53_record" "cert_validation" { + provider = aws.core-vpc + depends_on = [ aws_acm_certificate.certificate ] + for_each = { + for val in aws_acm_certificate.certificate.domain_validation_options : val.domain_name => { + name = val.resource_record_name + record = val.resource_record_value + type = val.resource_record_type + } + } + zone_id = var.fqdn + name = each.value.name + records = [each.value.record] + type = var.record_type +} -# resource "aws_acm_certificate_validation" "example" { -# certificate_arn = aws_acm_certificate.certificate.arn -# validation_record_fqdns = [for record in aws_route53_record.cert_validation : record.fqdn] -# } \ No newline at end of file +resource "aws_acm_certificate_validation" "example" { + certificate_arn = aws_acm_certificate.certificate.arn + validation_record_fqdns = [for record in aws_route53_record.cert_validation : record.fqdn] +} \ No newline at end of file diff --git a/test/module_test.go b/test/module_test.go index aec8b59..5e01e39 100644 --- a/test/module_test.go +++ b/test/module_test.go @@ -15,7 +15,7 @@ import ( func TestCertificateCreation(t *testing.T) { t.Parallel() - fqdn := "platforms-test.modernisation-platform.service.justice.gov.uk" + fqdn := "modernisation-platform.service.justice.gov.uk" recordType := "CNAME" terraformDir := "./unit-test" diff --git a/test/unit-test/main.tf b/test/unit-test/main.tf index 8b85b21..86f63df 100644 --- a/test/unit-test/main.tf +++ b/test/unit-test/main.tf @@ -9,7 +9,7 @@ module "cert_module" { source = "../../" providers = { - aws.core-network-services = aws.core-network-services + aws.core-vpc = aws.core-vpc } aws_account_id = local.environment_management.account_ids diff --git a/test/unit-test/variables.tf b/test/unit-test/variables.tf new file mode 100644 index 0000000..6d95fd1 --- /dev/null +++ b/test/unit-test/variables.tf @@ -0,0 +1,14 @@ +variable "fqdn" { + description = "The fully qualified domain name (FQDN) for which the DNS record should be created" + type = string +} + +variable "record_type" { + description = "The type of DNS record to create (e.g., CNAME, A, etc.)" + type = string +} + +variable "environment" { + type = string + +} \ No newline at end of file