From ec59da6fb711a6581cc0d35732ddee77f28714b2 Mon Sep 17 00:00:00 2001 From: Ryan Ahearn Date: Thu, 21 Nov 2024 16:28:23 -0500 Subject: [PATCH] Update s3 to official provider --- README.md | 11 +++++------ s3/main.tf | 19 ++++++++++--------- s3/providers.tf | 4 ++-- s3/tests/creation.tftest.hcl | 20 ++++++++++---------- s3/variables.tf | 11 +++-------- 5 files changed, 30 insertions(+), 35 deletions(-) diff --git a/README.md b/README.md index 0dbc294..4cd3fbc 100644 --- a/README.md +++ b/README.md @@ -52,14 +52,13 @@ Creates an s3 bucket and outputs the `bucket_id` for use elsewhere. ``` module "s3" { - source = "github.com/GSA-TTS/terraform-cloudgov//s3?ref=v1.1.0" + source = "github.com/GSA-TTS/terraform-cloudgov//s3?ref=v2.0.0-beta.1" - cf_org_name = local.cf_org_name - cf_space_name = local.cf_space_name - name = "${local.app_name}-s3-${local.env}" - tags = ["tag1", "tag2"] + cf_space_id = data.cloudfoundry_space.app_space.id + name = "${local.app_name}-s3-${local.env}" + tags = ["tag1", "tag2"] # See options at https://cloud.gov/docs/services/s3/#setting-optional-parameters - json_params = jsonencode( + json_params = jsonencode( { "object_ownership" : "ObjectWriter", } diff --git a/s3/main.tf b/s3/main.tf index 0bf8c3c..3b66a46 100644 --- a/s3/main.tf +++ b/s3/main.tf @@ -1,16 +1,17 @@ -data "cloudfoundry_space" "space" { - org_name = var.cf_org_name - name = var.cf_space_name +locals { + tags = setunion(["terraform-cloudgov"], var.tags) } -data "cloudfoundry_service" "s3" { - name = "s3" +data "cloudfoundry_service_plans" "s3" { + name = var.s3_plan_name + service_offering_name = "s3" } resource "cloudfoundry_service_instance" "bucket" { name = var.name - space = data.cloudfoundry_space.space.id - service_plan = data.cloudfoundry_service.s3.service_plans[var.s3_plan_name] - tags = var.tags - json_params = var.json_params + space = var.cf_space_id + type = "managed" + service_plan = data.cloudfoundry_service_plans.s3.service_plans.0.id + tags = local.tags + parameters = var.json_params } diff --git a/s3/providers.tf b/s3/providers.tf index aa59fd5..b6ad4a3 100644 --- a/s3/providers.tf +++ b/s3/providers.tf @@ -2,8 +2,8 @@ terraform { required_version = "~> 1.0" required_providers { cloudfoundry = { - source = "cloudfoundry-community/cloudfoundry" - version = ">=0.53.1" + source = "cloudfoundry/cloudfoundry" + version = ">=1.1.0" } } } diff --git a/s3/tests/creation.tftest.hcl b/s3/tests/creation.tftest.hcl index 00850ce..8f6f220 100644 --- a/s3/tests/creation.tftest.hcl +++ b/s3/tests/creation.tftest.hcl @@ -4,11 +4,11 @@ provider "cloudfoundry" { } variables { - cf_org_name = "gsa-tts-devtools-prototyping" - cf_space_name = "terraform-cloudgov-ci-tests" - s3_plan_name = "basic" - name = "terraform-cloudgov-s3-test" - tags = ["terraform-cloudgov", "tests"] + # this is the ID of the terraform-cloudgov-ci-tests space + cf_space_id = "15836eb6-a57e-4579-bca7-99764c5a01a4" + s3_plan_name = "basic-sandbox" + name = "terraform-cloudgov-s3-test" + tags = ["terraform-cloudgov", "tests"] } run "test_bucket_creation" { @@ -23,7 +23,7 @@ run "test_bucket_creation" { } assert { - condition = cloudfoundry_service_instance.bucket.service_plan == data.cloudfoundry_service.s3.service_plans[var.s3_plan_name] + condition = cloudfoundry_service_instance.bucket.service_plan == data.cloudfoundry_service_plans.s3.service_plans.0.id error_message = "Service Plan should match the s3_plan_name variable" } @@ -33,12 +33,12 @@ run "test_bucket_creation" { } assert { - condition = cloudfoundry_service_instance.bucket.tags == var.tags + condition = cloudfoundry_service_instance.bucket.tags == tolist(var.tags) error_message = "Service instance tags should match the tags variable" } } -run "test_json_params" { +run "test_parameters" { command = plan variables { @@ -48,7 +48,7 @@ run "test_json_params" { } assert { - condition = cloudfoundry_service_instance.bucket.json_params == "{\"object_ownership\":\"BucketOwnerEnforced\"}" - error_message = "Service instance json_params should be configurable" + condition = cloudfoundry_service_instance.bucket.parameters == "{\"object_ownership\":\"BucketOwnerEnforced\"}" + error_message = "Service instance parameters should be configurable" } } diff --git a/s3/variables.tf b/s3/variables.tf index 635004f..d241ab2 100644 --- a/s3/variables.tf +++ b/s3/variables.tf @@ -1,11 +1,6 @@ -variable "cf_org_name" { +variable "cf_space_id" { type = string - description = "cloud.gov organization name" -} - -variable "cf_space_name" { - type = string - description = "cloud.gov space name (staging or prod)" + description = "cloud.gov space id" } variable "name" { @@ -22,7 +17,7 @@ variable "s3_plan_name" { variable "tags" { description = "A list of tags to add to the resource" - type = list(string) + type = set(string) default = [] }