Skip to content

Commit

Permalink
feat: added option to make amplience resources unmanaged
Browse files Browse the repository at this point in the history
  • Loading branch information
demeyerthom committed Jun 14, 2024
1 parent 61a5da4 commit 3fd047d
Show file tree
Hide file tree
Showing 11 changed files with 340 additions and 66 deletions.
5 changes: 5 additions & 0 deletions .changeset/red-cheetahs-report.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"amplience-graphql-codegen-terraform": minor
---

Added option to make amplience resources unmanaged
29 changes: 29 additions & 0 deletions packages/plugin-terraform/examples/managed/codegen.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
overwrite: true
schema: ./examples/schema.graphql
hooks:
afterAllFileWrite:
- terraform fmt
generates:
examples/managed/output/example.tf:
plugins:
- ./dist/index.js
config:
add_amplience_is_managed_switch: true
hostname: "https://schema-examples.com"
visualization:
- for_each: var.variables["VISUALIZATION_HOST"]
label: visualization.key
templated_uri: "${visualization.value}/preview/with-layout?vse={{vse.domain}}&content={{content.sys.id}}"
default: false
- label: Localhost with layout
templated_uri: http://localhost:3000/preview/with-layout?vse={{vse.domain}}&content={{content.sys.id}}
default: false
- label: Localhost without layout
templated_uri: http://localhost:3000/preview/without-layout?vse={{vse.domain}}&content={{content.sys.id}}
default: false
# content_repositories:
# website1: var.variables["CONTENT_REPO1_ID"]
# website2: var.variables["CONTENT_REPO2_ID"]
# slot_repositories:
# slot1: var.variables["SLOT_REPO1_ID"]
# slot2: var.variables["SLOT_REPO2_ID"]
Original file line number Diff line number Diff line change
Expand Up @@ -6,139 +6,124 @@ terraform {
}
}

data "amplience_content_repository" "website1" {
id = var.variables["CONTENT_REPO1_ID"]
}

data "amplience_content_repository" "website2" {
id = var.variables["CONTENT_REPO2_ID"]
}

data "amplience_content_repository" "slot1" {
id = var.variables["SLOT_REPO1_ID"]
}

data "amplience_content_repository" "slot2" {
id = var.variables["SLOT_REPO2_ID"]
}

resource "amplience_content_type_schema" "test" {
body = file("${path.module}/schemas/test.json")
schema_id = "https://schema-examples.com/test"
validation_level = "CONTENT_TYPE"
auto_sync = true
count = var.amplience_is_managed ? 1 : 0
}

resource "amplience_content_type" "test" {
content_type_uri = amplience_content_type_schema.test.schema_id
content_type_uri = "https://schema-examples.com/test"
label = "Test"
status = "ACTIVE"
}

resource "amplience_content_type_assignment" "test" {
content_type_id = amplience_content_type.test.id
repository_id = data.amplience_content_repository.website1.id
depends_on = [
amplience_content_type_schema.test
]
count = var.amplience_is_managed ? 1 : 0
}

resource "amplience_content_type_schema" "test_auto_sync_false" {
body = file("${path.module}/schemas/test-auto-sync-false.json")
schema_id = "https://schema-examples.com/test-auto-sync-false"
validation_level = "CONTENT_TYPE"
auto_sync = false
count = var.amplience_is_managed ? 1 : 0
}

resource "amplience_content_type" "test_auto_sync_false" {
content_type_uri = amplience_content_type_schema.test_auto_sync_false.schema_id
content_type_uri = "https://schema-examples.com/test-auto-sync-false"
label = "Test Auto Sync False"
status = "ACTIVE"
}

resource "amplience_content_type_assignment" "test_auto_sync_false" {
content_type_id = amplience_content_type.test_auto_sync_false.id
repository_id = data.amplience_content_repository.website1.id
depends_on = [
amplience_content_type_schema.test_auto_sync_false
]
count = var.amplience_is_managed ? 1 : 0
}

resource "amplience_content_type_schema" "test_auto_sync_true" {
body = file("${path.module}/schemas/test-auto-sync-true.json")
schema_id = "https://schema-examples.com/test-auto-sync-true"
validation_level = "CONTENT_TYPE"
auto_sync = true
count = var.amplience_is_managed ? 1 : 0
}

resource "amplience_content_type" "test_auto_sync_true" {
content_type_uri = amplience_content_type_schema.test_auto_sync_true.schema_id
content_type_uri = "https://schema-examples.com/test-auto-sync-true"
label = "Test Auto Sync True"
status = "ACTIVE"
}

resource "amplience_content_type_assignment" "test_auto_sync_true" {
content_type_id = amplience_content_type.test_auto_sync_true.id
repository_id = data.amplience_content_repository.website1.id
depends_on = [
amplience_content_type_schema.test_auto_sync_true
]
count = var.amplience_is_managed ? 1 : 0
}

resource "amplience_content_type_schema" "test_no_auto_sync" {
body = file("${path.module}/schemas/test-no-auto-sync.json")
schema_id = "https://schema-examples.com/test-no-auto-sync"
validation_level = "CONTENT_TYPE"
auto_sync = true
count = var.amplience_is_managed ? 1 : 0
}

resource "amplience_content_type" "test_no_auto_sync" {
content_type_uri = amplience_content_type_schema.test_no_auto_sync.schema_id
content_type_uri = "https://schema-examples.com/test-no-auto-sync"
label = "Test No Auto Sync"
status = "ACTIVE"
}

resource "amplience_content_type_assignment" "test_no_auto_sync" {
content_type_id = amplience_content_type.test_no_auto_sync.id
repository_id = data.amplience_content_repository.website1.id
depends_on = [
amplience_content_type_schema.test_no_auto_sync
]
count = var.amplience_is_managed ? 1 : 0
}

resource "amplience_content_type_schema" "test_other_repository" {
body = file("${path.module}/schemas/test-other-repository.json")
schema_id = "https://schema-examples.com/test-other-repository"
validation_level = "CONTENT_TYPE"
auto_sync = true
count = var.amplience_is_managed ? 1 : 0
}

resource "amplience_content_type" "test_other_repository" {
content_type_uri = amplience_content_type_schema.test_other_repository.schema_id
content_type_uri = "https://schema-examples.com/test-other-repository"
label = "Test Other Repository"
status = "ACTIVE"
}

resource "amplience_content_type_assignment" "test_other_repository" {
content_type_id = amplience_content_type.test_other_repository.id
repository_id = data.amplience_content_repository.website2.id
depends_on = [
amplience_content_type_schema.test_other_repository
]
count = var.amplience_is_managed ? 1 : 0
}

resource "amplience_content_type_schema" "test_slot" {
body = file("${path.module}/schemas/test-slot.json")
schema_id = "https://schema-examples.com/test-slot"
validation_level = "SLOT"
auto_sync = true
count = var.amplience_is_managed ? 1 : 0
}

resource "amplience_content_type" "test_slot" {
content_type_uri = amplience_content_type_schema.test_slot.schema_id
content_type_uri = "https://schema-examples.com/test-slot"
label = "Test Slot"
status = "ACTIVE"
}

resource "amplience_content_type_assignment" "test_slot" {
content_type_id = amplience_content_type.test_slot.id
repository_id = data.amplience_content_repository.slot1.id
depends_on = [
amplience_content_type_schema.test_slot
]
count = var.amplience_is_managed ? 1 : 0
}

resource "amplience_content_type_schema" "test_visualizations" {
body = file("${path.module}/schemas/test-visualizations.json")
schema_id = "https://schema-examples.com/test-visualizations"
validation_level = "CONTENT_TYPE"
auto_sync = true
count = var.amplience_is_managed ? 1 : 0
}

resource "amplience_content_type" "test_visualizations" {
content_type_uri = amplience_content_type_schema.test_visualizations.schema_id
content_type_uri = "https://schema-examples.com/test-visualizations"
label = "Test Visualizations"
status = "ACTIVE"
dynamic "visualization" {
Expand All @@ -159,10 +144,15 @@ resource "amplience_content_type" "test_visualizations" {
templated_uri = "http://localhost:3000/preview/without-layout?vse={{vse.domain}}&content={{content.sys.id}}"
default = false
}
depends_on = [
amplience_content_type_schema.test_visualizations
]
count = var.amplience_is_managed ? 1 : 0
}

resource "amplience_content_type_assignment" "test_visualizations" {
content_type_id = amplience_content_type.test_visualizations.id
repository_id = data.amplience_content_repository.website1.id
variable "amplience_is_managed" {
type = bool
default = true
description = "Set to false to disable all the Amplience resources"
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"$id": "https://schema-examples.com/test",
"$schema": "http://json-schema.org/draft-07/schema#",
"allOf": [
{
"$ref": "http://bigcontent.io/cms/schema/v1/core#/definitions/content"
}
],
"title": "Accordion Block",
"properties": {
"accordions": {
"title": "Accordions",
"type": "array",
"minItems": 1,
"items": {
"type": "object",
"properties": {
"content": {
"title": "Content",
"type": "string",
"format": "markdown"
},
"title": { "title": "Title", "type": "string" }
},
"propertyOrder": ["content", "title"],
"required": []
}
},
"heading": { "title": "Heading", "type": "string" }
},
"description": "Accordion Block",
"type": "object",
"propertyOrder": ["accordions", "heading"],
"required": ["accordions"]
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ hooks:
afterAllFileWrite:
- terraform fmt
generates:
examples/output/example.tf:
examples/regular/output/example.tf:
plugins:
- ./dist/index.js
config:
Expand All @@ -20,9 +20,9 @@ generates:
- label: Localhost without layout
templated_uri: http://localhost:3000/preview/without-layout?vse={{vse.domain}}&content={{content.sys.id}}
default: false
content_repositories:
website1: var.variables["CONTENT_REPO1_ID"]
website2: var.variables["CONTENT_REPO2_ID"]
slot_repositories:
slot1: var.variables["SLOT_REPO1_ID"]
slot2: var.variables["SLOT_REPO2_ID"]
# content_repositories:
# website1: var.variables["CONTENT_REPO1_ID"]
# website2: var.variables["CONTENT_REPO2_ID"]
# slot_repositories:
# slot1: var.variables["SLOT_REPO1_ID"]
# slot2: var.variables["SLOT_REPO2_ID"]
Loading

0 comments on commit 3fd047d

Please sign in to comment.