From 445084aaf04502c570b9918259d66fe4f46eaa87 Mon Sep 17 00:00:00 2001 From: Kenneth Garza Date: Fri, 27 Oct 2023 13:20:04 -0400 Subject: [PATCH] updating tag_sets to return list of canonical tags that are assigned to them as part of the data call --- .devcontainer/devcontainer.json | 14 +++++++ .devcontainer/docker-compose.yml | 43 ++++++++++++++++++++ .devcontainer/dockerfile | 8 ++++ .gitignore | 6 ++- octopusdeploy/data_source_tag_sets.go | 1 + octopusdeploy/schema_tag_set.go | 57 ++++++++++++++++++++++++++- 6 files changed, 126 insertions(+), 3 deletions(-) create mode 100644 .devcontainer/devcontainer.json create mode 100644 .devcontainer/docker-compose.yml create mode 100644 .devcontainer/dockerfile diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 000000000..b1111dd40 --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,14 @@ +{ + "name": "golang build env", + "dockerComposeFile" : [ + "docker-compose.yml" + ], + "service" : "dev_env", + "workspaceFolder": "/src", + "forwardPorts": [ + 0 + ], + "extensions": [ + "ms-azuretools.vscode-docker" + ] +} diff --git a/.devcontainer/docker-compose.yml b/.devcontainer/docker-compose.yml new file mode 100644 index 000000000..94e262fde --- /dev/null +++ b/.devcontainer/docker-compose.yml @@ -0,0 +1,43 @@ +version: "3.8" +name: terraform-provider-octopusdeploy +services: + + sql_server: + image: mcr.microsoft.com/mssql/server:2022-latest + environment: + ACCEPT_EULA: Y + MSSQL_SA_PASSWORD: MyVeryStrongPassword123! + healthcheck: + test: [ "CMD", "/opt/mssql-tools/bin/sqlcmd", "-U", "sa", "-P", "MyVeryStrongPassword123!", "-Q", "select 1"] + interval: 10s + retries: 10 + ports: + - 8433:1433 + + octopus: + depends_on: + sql_server: + condition: service_healthy + image: octopusdeploy/octopusdeploy + environment: + ACCEPT_EULA: "Y" + ADMIN_USERNAME: admin + ADMIN_PASSWORD: "P@ssw0rd!" + ADMIN_API_KEY: API-L2GV2ELTCZDRANT1OQO045GPZHXFGWR + DB_CONNECTION_STRING: Server=sql_server;Database=octopus;User Id=sa;Password=MyVeryStrongPassword123! + ports: + - 8080:8080 + + dev_env: + depends_on: + sql_server: + condition: service_healthy + octopus: + condition: service_started + build: + context: . + dockerfile: dockerfile + command: sleep infinity + volumes: + - ../:/src + \ No newline at end of file diff --git a/.devcontainer/dockerfile b/.devcontainer/dockerfile new file mode 100644 index 000000000..4eae5768c --- /dev/null +++ b/.devcontainer/dockerfile @@ -0,0 +1,8 @@ +FROM hashicorp/terraform + +COPY --from=golang /usr/local/go /usr/local/go +ENV PATH="/usr/local/go/bin:${PATH}" + +RUN apk add --no-cache make + +ENTRYPOINT [ ] diff --git a/.gitignore b/.gitignore index 501744f78..d312750fd 100644 --- a/.gitignore +++ b/.gitignore @@ -54,4 +54,8 @@ terraform/**/terrform.tfstate terraform/**/.terraform/* # Ignore the test results file -results.xml \ No newline at end of file +results.xml + +## test container stuff +**/*/terraform.lock* +.devcontainer/integration_tests/ \ No newline at end of file diff --git a/octopusdeploy/data_source_tag_sets.go b/octopusdeploy/data_source_tag_sets.go index 63395248b..0293b9a5a 100644 --- a/octopusdeploy/data_source_tag_sets.go +++ b/octopusdeploy/data_source_tag_sets.go @@ -34,6 +34,7 @@ func dataSourceTagSetsRead(ctx context.Context, d *schema.ResourceData, m interf } flattenedTagSets := []interface{}{} + for _, tagSet := range existingTagSets.Items { flattenedTagSets = append(flattenedTagSets, flattenTagSet(tagSet)) } diff --git a/octopusdeploy/schema_tag_set.go b/octopusdeploy/schema_tag_set.go index db5c31a23..503a48bc3 100644 --- a/octopusdeploy/schema_tag_set.go +++ b/octopusdeploy/schema_tag_set.go @@ -28,19 +28,41 @@ func expandTagSet(d *schema.ResourceData) *tagsets.TagSet { return tagSet } +func flattenTag(tag *tagsets.Tag) map[string]interface{} { + if tag == nil { + return nil + } + + return map[string]interface{}{ + "canonical_tag_name": tag.CanonicalTagName, + "color": tag.Color, + "description": tag.Description, + "name": tag.Name, + "sort_order": tag.SortOrder, + } + +} + func flattenTagSet(tagSet *tagsets.TagSet) map[string]interface{} { if tagSet == nil { return nil } + flattened_tags := []interface{}{} + + for _, tag := range tagSet.Tags { + flattened_tags = append(flattened_tags, flattenTag(tag)) + } + return map[string]interface{}{ "description": tagSet.Description, "id": tagSet.GetID(), "name": tagSet.Name, "sort_order": tagSet.SortOrder, "space_id": tagSet.SpaceID, - } -} + "tags": flattened_tags, + }} + func getTagSetDataSchema() map[string]*schema.Schema { dataSchema := getTagSetSchema() @@ -62,13 +84,44 @@ func getTagSetDataSchema() map[string]*schema.Schema { } } +func getTagSchemaForTagSet() map[string]*schema.Schema { + return map[string]*schema.Schema{ + "canonical_tag_name": { + Computed: true, + Type: schema.TypeString, + }, + "color": { + Required: true, + Type: schema.TypeString, + }, + "description": getDescriptionSchema("tag"), + "name": getNameSchema(true), + "sort_order": { + Computed: true, + Optional: true, + Type: schema.TypeInt, + }, + } +} + func getTagSetSchema() map[string]*schema.Schema { + tagSchema := getTagSchemaForTagSet() + setDataSchema(&tagSchema) + + return map[string]*schema.Schema{ "description": getDescriptionSchema("tag set"), "id": getIDSchema(), "name": getNameSchema(true), "sort_order": getSortOrderSchema(), "space_id": getSpaceIDSchema(), + "tags": { + Computed: true, + Description: "A list of tags within the tagset", + Elem: &schema.Resource{Schema: tagSchema}, + Optional: true, + Type: schema.TypeList, + }, } }