Skip to content

Commit

Permalink
Update s3 to official provider
Browse files Browse the repository at this point in the history
  • Loading branch information
rahearn committed Nov 21, 2024
1 parent d9cac23 commit ec59da6
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 35 deletions.
11 changes: 5 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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",
}
Expand Down
19 changes: 10 additions & 9 deletions s3/main.tf
Original file line number Diff line number Diff line change
@@ -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
}
4 changes: 2 additions & 2 deletions s3/providers.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
}
20 changes: 10 additions & 10 deletions s3/tests/creation.tftest.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -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" {
Expand All @@ -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"
}

Expand All @@ -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 {
Expand All @@ -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"
}
}
11 changes: 3 additions & 8 deletions s3/variables.tf
Original file line number Diff line number Diff line change
@@ -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" {
Expand All @@ -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 = []
}

Expand Down

0 comments on commit ec59da6

Please sign in to comment.