Skip to content

Commit

Permalink
feat: [IAC-2081]: Support for IACM default pipelines (#994)
Browse files Browse the repository at this point in the history
  • Loading branch information
scottyw-harness committed Jun 25, 2024
1 parent 20566fd commit 66e27e5
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 4 deletions.
2 changes: 1 addition & 1 deletion examples/resources/harness_platform_workspace/resource.tf
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ resource "harness_platform_workspace" "example" {
identifier = "example"
org_id = harness_platform_organization.test.id
project_id = harness_platform_project.test.id
provisioner = "terraform"
provisioner_type = "terraform"
provisioner_version = "1.5.6"
repository = "https://github.com/org/repo"
repository_branch = "main"
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ require (
github.com/antihax/optional v1.0.0
github.com/aws/aws-sdk-go v1.46.4
github.com/docker/docker v24.0.5+incompatible
github.com/harness/harness-go-sdk v0.3.90
github.com/harness/harness-go-sdk v0.3.91
github.com/harness/harness-openapi-go-client v0.0.19
github.com/hashicorp/go-cleanhttp v0.5.2
github.com/hashicorp/go-cty v1.4.1-0.20200414143053-d3edf31b6320
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMyw
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/harness/harness-go-sdk v0.3.90 h1:BLZb9Yzhs/ZNivdLQ1VJNnNhL2M9OGArdvvvJPdNkCg=
github.com/harness/harness-go-sdk v0.3.90/go.mod h1:CPXydorp4zd5Dz2u2FXiHyWL4yd5PQafOMN69cgPSvk=
github.com/harness/harness-go-sdk v0.3.91 h1:akho0cjMd/1nHlLgc2GzhMh/l8HARVlwxjYk/KkVjPI=
github.com/harness/harness-go-sdk v0.3.91/go.mod h1:CPXydorp4zd5Dz2u2FXiHyWL4yd5PQafOMN69cgPSvk=
github.com/harness/harness-openapi-go-client v0.0.19 h1:8XuZvSPZrNqKRLh7Qksdz78WvRMRzRf88LgzxoT5u7k=
github.com/harness/harness-openapi-go-client v0.0.19/go.mod h1:u0vqYb994BJGotmEwJevF4L3BNAdU9i8ui2d22gmLPA=
github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4=
Expand Down
5 changes: 5 additions & 0 deletions internal/service/platform/workspace/data_source_workspace.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,11 @@ func DataSourceWorkspace() *schema.Resource {
},
},
},
"default_pipelines": {
Description: "Default pipelines associated with this workspace",
Type: schema.TypeMap,
Computed: true,
},
},
}
return resource
Expand Down
38 changes: 38 additions & 0 deletions internal/service/platform/workspace/resource_workspace.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,11 @@ func ResourceWorkspace() *schema.Resource {
},
},
},
"default_pipelines": {
Description: "Default pipelines associated with this workspace",
Type: schema.TypeMap,
Optional: true,
},
},
}

Expand Down Expand Up @@ -331,6 +336,13 @@ func readWorkspace(d *schema.ResourceData, ws *nextgen.IacmShowWorkspaceResponse
})
}
d.Set("terraform_variable_file", terraformVariableFiles)
defaultPipelines := map[string]string{}
for k, v := range ws.DefaultPipelines {
if v.WorkspacePipeline != "" {
defaultPipelines[k] = v.WorkspacePipeline
}
}
d.Set("default_pipelines", defaultPipelines)
}

func buildUpdateWorkspace(d *schema.ResourceData) (nextgen.IacmUpdateWorkspaceRequestBody, error) {
Expand Down Expand Up @@ -375,6 +387,12 @@ func buildUpdateWorkspace(d *schema.ResourceData) (nextgen.IacmUpdateWorkspaceRe

ws.TerraformVariableFiles = buildTerraformVariableFiles(d)

defaultPipelines, err := buildDefaultPipelines(d)
if err != nil {
return nextgen.IacmUpdateWorkspaceRequestBody{}, err
}
ws.DefaultPipelines = defaultPipelines

return ws, nil
}

Expand Down Expand Up @@ -421,6 +439,12 @@ func buildCreateWorkspace(d *schema.ResourceData) (nextgen.IacmCreateWorkspaceRe

ws.TerraformVariableFiles = buildTerraformVariableFiles(d)

defaultPipelines, err := buildDefaultPipelines(d)
if err != nil {
return nextgen.IacmCreateWorkspaceRequestBody{}, err
}
ws.DefaultPipelines = defaultPipelines

return ws, nil
}

Expand Down Expand Up @@ -461,6 +485,20 @@ func buildVariables(d *schema.ResourceData, attribute string) (map[string]nextge
return variables, nil
}

func buildDefaultPipelines(d *schema.ResourceData) (map[string]nextgen.IacmDefaultPipelineOverride, error) {
defaultPipelines := map[string]nextgen.IacmDefaultPipelineOverride{}
if pipelines, ok := d.GetOk("default_pipelines"); ok {
if pipelinesMap, ok := pipelines.(map[string]interface{}); ok {
for operation, pipeline := range pipelinesMap {
if pipelineStr, ok := pipeline.(string); ok {
defaultPipelines[operation] = nextgen.IacmDefaultPipelineOverride{WorkspacePipeline: pipelineStr}
}
}
}
}
return defaultPipelines, nil
}

// iacm errors are in a different format from other harness services
// this function parses iacm errors and attempts to return them in way
// that is consistent with the provider.
Expand Down

0 comments on commit 66e27e5

Please sign in to comment.