Skip to content

Commit

Permalink
Merge pull request #5 from Scalr/feature/SCALRCORE-16085
Browse files Browse the repository at this point in the history
SCALRCORE-16085 Add created-by to workspace res and data source
  • Loading branch information
emocharnik authored Jul 1, 2020
2 parents 9b6ea41 + 04494e5 commit 487af98
Show file tree
Hide file tree
Showing 9 changed files with 75 additions and 39 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased]
### Added
- **New data source:** `scalr_current_run` ([#2](https://github.com/Scalr/terraform-provider-scalr/pull/2))
- **New attributes:** `scalr_workspace.created_by` ([#5](https://github.com/Scalr/terraform-provider-scalr/pull/5))

## [0.0.0-rc2] - 2020-03-30
### Added
Expand Down
7 changes: 3 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
module github.com/scalr/terraform-provider-scalr

require (
github.com/hashicorp/go-hclog v0.0.0-20190109152822-4783caec6f2e // indirect
github.com/hashicorp/go-version v1.2.0
github.com/hashicorp/hcl v0.0.0-20180404174102-ef8a98b0bbce
github.com/hashicorp/terraform v0.12.0
github.com/hashicorp/terraform-svchost v0.0.0-20191011084731-65d371908596
github.com/logrusorgru/aurora v0.0.0-20200102142835-e9ef32dff381 // indirect
github.com/scalr/go-tfe v0.3.31-0.20200508174800-8c75b5daa29b
github.com/terraform-providers/terraform-provider-tfe v0.11.4
github.com/urfave/cli/v2 v2.2.0 // indirect
github.com/mitchellh/go-homedir v1.1.0 // indirect
github.com/scalr/go-tfe v0.3.31-0.20200623115601-a17754fc9156
)

go 1.13
32 changes: 2 additions & 30 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,6 @@ github.com/coreos/go-semver v0.2.0 h1:3Jm3tLmsgAYcjC+4Up7hJrFBPr+n7rAqYeSw/SZazu
github.com/coreos/go-semver v0.2.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk=
github.com/coreos/go-systemd v0.0.0-20181012123002-c6f51f82210d/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4=
github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f/go.mod h1:E3G3o1h8I7cfcXa63jLwjI0eiQQMgzzUDFVpN/nH/eA=
github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d h1:U+s90UTSYgptZMwQh2aRr3LuazLJIa+Pg3Kc1ylSYVY=
github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU=
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
Expand Down Expand Up @@ -179,8 +177,6 @@ github.com/hashicorp/go-slug v0.4.1/go.mod h1:I5tq5Lv0E2xcNXNkmx7BSfzi1PsJ2cNjs3
github.com/hashicorp/go-sockaddr v0.0.0-20180320115054-6d291a969b86/go.mod h1:7Xibr9yA9JjQq1JpNB2Vw7kxv8xerXegt+ozgdvDeDU=
github.com/hashicorp/go-tfe v0.3.16 h1:GS2yv580p0co4j3FBVaC6Zahd9mxdCGehhJ0qqzFMH0=
github.com/hashicorp/go-tfe v0.3.16/go.mod h1:SuPHR+OcxvzBZNye7nGPfwZTEyd3rWPfLVbCgyZPezM=
github.com/hashicorp/go-tfe v0.3.30 h1:rFgHipleCO2vvCumrRIe4Lcvit6uU/r+T3dGkkURmRE=
github.com/hashicorp/go-tfe v0.3.30/go.mod h1:DVPSW2ogH+M9W1/i50ASgMht8cHP7NxxK0nrY9aFikQ=
github.com/hashicorp/go-uuid v1.0.0 h1:RS8zrF7PhGwyNPOtxSClXXj9HA8feRnJzgnI1RJCSnM=
github.com/hashicorp/go-uuid v1.0.0/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro=
github.com/hashicorp/go-uuid v1.0.1 h1:fv1ep09latC32wFoVwnqcnKJGnMSdBanPczbHAYm1BE=
Expand Down Expand Up @@ -208,8 +204,6 @@ github.com/hashicorp/terraform-config-inspect v0.0.0-20190327195015-8022a2663a70
github.com/hashicorp/terraform-config-inspect v0.0.0-20190327195015-8022a2663a70/go.mod h1:ItvqtvbC3K23FFET62ZwnkwtpbKZm8t8eMcWjmVVjD8=
github.com/hashicorp/terraform-svchost v0.0.0-20191011084731-65d371908596 h1:hjyO2JsNZUKT1ym+FAdlBEkGPevazYsmVgIMw7dVELg=
github.com/hashicorp/terraform-svchost v0.0.0-20191011084731-65d371908596/go.mod h1:kNDNcF7sN4DocDLBkQYz73HGKwN1ANB1blq4lIYLYvg=
github.com/hashicorp/terraform-svchost v0.0.0-20191119180714-d2e4933b9136 h1:81Dg7SK6Q5vzqFItO8e1iIF2Nj8bLXV23NXjEgbev/s=
github.com/hashicorp/terraform-svchost v0.0.0-20191119180714-d2e4933b9136/go.mod h1:kNDNcF7sN4DocDLBkQYz73HGKwN1ANB1blq4lIYLYvg=
github.com/hashicorp/vault v0.10.4/go.mod h1:KfSyffbKxoVyspOdlaGVjIuwLobi07qD1bAbosPMpP0=
github.com/hashicorp/yamux v0.0.0-20180604194846-3520598351bb h1:b5rjCoWHc7eqmAS4/qyk21ZsHyb6Mxv/jykxvNTkU4M=
github.com/hashicorp/yamux v0.0.0-20180604194846-3520598351bb/go.mod h1:+NfK9FKeTrX5uv1uIXGdwYDTeHna2qgaIlx54MXqjAM=
Expand Down Expand Up @@ -241,8 +235,6 @@ github.com/kylelemons/godebug v0.0.0-20170820004349-d65d576e9348 h1:MtvEpTB6LX3v
github.com/kylelemons/godebug v0.0.0-20170820004349-d65d576e9348/go.mod h1:B69LEHPfb2qLo0BaaOLcbitczOKLWTsrBG9LczfCD4k=
github.com/lib/pq v1.0.0 h1:X5PMW56eZitiTeO7tKzZxFCSpbFZJtkMMooicw2us9A=
github.com/lib/pq v1.0.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo=
github.com/logrusorgru/aurora v0.0.0-20200102142835-e9ef32dff381 h1:bqDmpDG49ZRnB5PcgP0RXtQvnMSgIF14M7CBd2shtXs=
github.com/logrusorgru/aurora v0.0.0-20200102142835-e9ef32dff381/go.mod h1:7rIyQOR62GCctdiQpZ/zOJlFyk6y+94wXzv6RNZgaR4=
github.com/lusis/go-artifactory v0.0.0-20160115162124-7e4ce345df82 h1:wnfcqULT+N2seWf6y4yHzmi7GD2kNx4Ute0qArktD48=
github.com/lusis/go-artifactory v0.0.0-20160115162124-7e4ce345df82/go.mod h1:y54tfGmO3NKssKveTEFFzH8C/akrSOy/iW9qEAUDV84=
github.com/marstr/guid v1.1.0 h1:/M4H/1G4avsieL6BbUwCOBzulmoeKVP5ux/3mQNnbyI=
Expand Down Expand Up @@ -322,24 +314,11 @@ github.com/prometheus/common v0.0.0-20180801064454-c7de2306084e/go.mod h1:daVV7q
github.com/prometheus/procfs v0.0.0-20180725123919-05ee40e3a273/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk=
github.com/russross/blackfriday v1.5.2 h1:HyvC0ARfnZBqnXwABFeSZHpKvJHJJfPz81GNueLj0oo=
github.com/russross/blackfriday v1.5.2/go.mod h1:JO/DiYxRf+HjHt06OyowR9PTA263kcR/rfWxYHBV53g=
github.com/russross/blackfriday/v2 v2.0.1 h1:lPqVAte+HuHNfhJ/0LC98ESWRz8afy9tM/0RK8m9o+Q=
github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/satori/go.uuid v1.2.0 h1:0uYX9dsZ2yD7q2RtLRtPSdGDWzjeM3TbMJP9utgA0ww=
github.com/satori/go.uuid v1.2.0/go.mod h1:dA0hQrYB0VpLJoorglMZABFdXlWrHn1NEOzdhQKdks0=
github.com/scalr/go-tfe v0.3.31-0.20200207091958-8dba4e8a4cd9 h1:srG4BRwmb+RY+cO08m1fZNEgc37o7VzBUpDSmpbbAq4=
github.com/scalr/go-tfe v0.3.31-0.20200207091958-8dba4e8a4cd9/go.mod h1:uyEJQDK0ta8lypIrJoonGgY3/NBaYQewwc28FNF+g6c=
github.com/scalr/go-tfe v0.3.31-0.20200505125511-c059cefa25b4 h1:aqVgN3mkbwGgAQe6R9JCyh7ZXr/JhTOPkJGO1W3q9Ew=
github.com/scalr/go-tfe v0.3.31-0.20200505125511-c059cefa25b4/go.mod h1:uyEJQDK0ta8lypIrJoonGgY3/NBaYQewwc28FNF+g6c=
github.com/scalr/go-tfe v0.3.31-0.20200505143845-03cb47242450 h1:/nEjB5bKA8VZQlaUtIK3O5ZWQh4ncGlbTdIiUzPStE4=
github.com/scalr/go-tfe v0.3.31-0.20200505143845-03cb47242450/go.mod h1:uyEJQDK0ta8lypIrJoonGgY3/NBaYQewwc28FNF+g6c=
github.com/scalr/go-tfe v0.3.31-0.20200505153523-81ea7b5ae646 h1:xXZSBK5zPJgisSGkBhfDQigAKtRnIhOGdXwvtvRvT8k=
github.com/scalr/go-tfe v0.3.31-0.20200505153523-81ea7b5ae646/go.mod h1:uyEJQDK0ta8lypIrJoonGgY3/NBaYQewwc28FNF+g6c=
github.com/scalr/go-tfe v0.3.31-0.20200505180333-4c273973eaa4 h1:lRaXgUq6gJRBTtcS4sdoJRMQ1Hyos8OK7fUC9P41jLg=
github.com/scalr/go-tfe v0.3.31-0.20200505180333-4c273973eaa4/go.mod h1:uyEJQDK0ta8lypIrJoonGgY3/NBaYQewwc28FNF+g6c=
github.com/scalr/go-tfe v0.3.31-0.20200508174800-8c75b5daa29b h1:l9YSsBbGTgbJ4Wk0shqvK/7AafrmgzPrumIz9eup+dg=
github.com/scalr/go-tfe v0.3.31-0.20200508174800-8c75b5daa29b/go.mod h1:uyEJQDK0ta8lypIrJoonGgY3/NBaYQewwc28FNF+g6c=
github.com/scalr/go-tfe v0.3.32-0.20200505123408-38958aee3e30 h1:APb91E3GK6iG41DM2/diFCGTLIAH9yTmXfsyLxirnbU=
github.com/scalr/go-tfe v0.3.32-0.20200505123408-38958aee3e30/go.mod h1:5vDvTw6XQ+JRz4tlHJB8mZv8O1EEWnUUEI2UTYBnAWk=
github.com/scalr/go-tfe v0.3.31-0.20200623115601-a17754fc9156 h1:VziGgoIJYhHBB9QEqjpkPQFcK+fwNd0o1CFkaHc6CgA=
github.com/scalr/go-tfe v0.3.31-0.20200623115601-a17754fc9156/go.mod h1:uyEJQDK0ta8lypIrJoonGgY3/NBaYQewwc28FNF+g6c=
github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529/go.mod h1:DxrIzT+xaE7yg65j358z/aeFdxmN0P9QXhEzd20vsDc=
github.com/sergi/go-diff v1.0.0 h1:Kpca3qRNrduNnOQeazBd0ysaKrUJiIuISHxogkT9RPQ=
github.com/sergi/go-diff v1.0.0/go.mod h1:0CfEIISq7TuYL3j771MWULgwwjU+GofnZX9QAmXWZgo=
Expand All @@ -363,8 +342,6 @@ github.com/shurcooL/notifications v0.0.0-20181007000457-627ab5aea122/go.mod h1:b
github.com/shurcooL/octicon v0.0.0-20181028054416-fa4f57f9efb2/go.mod h1:eWdoE5JD4R5UVWDucdOPg1g2fqQRq78IQa9zlOV1vpQ=
github.com/shurcooL/reactions v0.0.0-20181006231557-f2e0b4ca5b82/go.mod h1:TCR1lToEk4d2s07G3XGfz2QrgHXg4RJBvjrOozvoWfk=
github.com/shurcooL/sanitized_anchor_name v0.0.0-20170918181015-86672fcb3f95/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc=
github.com/shurcooL/sanitized_anchor_name v1.0.0 h1:PdmoCO6wvbs+7yrJyMORt4/BmY5IYyJwS/kOiWx8mHo=
github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc=
github.com/shurcooL/users v0.0.0-20180125191416-49c67e49c537/go.mod h1:QJTqeLYEDaXHZDBsXlPCDqdhQuJkuw4NOtaxYe3xii4=
github.com/shurcooL/webdavfs v0.0.0-20170829043945-18c3829fa133/go.mod h1:hKmq5kWdCj2z2KEozexVbfEZIWiTjhE0+UjmZgPqehw=
github.com/sirupsen/logrus v1.1.1/go.mod h1:zrgwTnHtNr00buQ1vSptGe8m1f/BbgsPukg8qsT7A+A=
Expand All @@ -385,16 +362,11 @@ github.com/svanharmelen/jsonapi v0.0.0-20180618144545-0c0828c3f16d/go.mod h1:BST
github.com/tarm/serial v0.0.0-20180830185346-98f6abe2eb07/go.mod h1:kDXzergiv9cbyO7IOYJZWg1U88JhDg3PB6klq9Hg2pA=
github.com/terraform-providers/terraform-provider-openstack v1.15.0 h1:adpjqej+F8BAX9dHmuPF47sUIkgifeqBu6p7iCsyj0Y=
github.com/terraform-providers/terraform-provider-openstack v1.15.0/go.mod h1:2aQ6n/BtChAl1y2S60vebhyJyZXBsuAI5G4+lHrT1Ew=
github.com/terraform-providers/terraform-provider-tfe v0.11.4 h1:Bu51+jg6ckZOCTKZ9DEs4ET/jmaZOfJ16KMJTjtlctg=
github.com/terraform-providers/terraform-provider-tfe v0.11.4/go.mod h1:70YOB5xDkR7gum2/6kyCHEcOMOAbZIG1H1H5gMBWCz0=
github.com/tmc/grpc-websocket-proxy v0.0.0-20171017195756-830351dc03c6/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U=
github.com/ugorji/go v0.0.0-20180813092308-00b869d2f4a5 h1:cMjKdf4PxEBN9K5HaD9UMW8gkTbM0kMzkTa9SJe0WNQ=
github.com/ugorji/go v0.0.0-20180813092308-00b869d2f4a5/go.mod h1:hnLbHMwcvSihnDhEfx2/BzKp2xb0Y+ErdfYcrs9tkJQ=
github.com/ulikunitz/xz v0.5.5 h1:pFrO0lVpTBXLpYw+pnLj6TbvHuyjXMfjGeCwSqCVwok=
github.com/ulikunitz/xz v0.5.5/go.mod h1:2bypXElzHzzJZwzH67Y6wb67pO62Rzfn7BSiF4ABRW8=
github.com/urfave/cli v1.22.3 h1:FpNT6zq26xNpHZy08emi755QwzLPs6Pukqjlc7RfOMU=
github.com/urfave/cli/v2 v2.2.0 h1:JTTnM6wKzdA0Jqodd966MVj4vWbbquZykeX1sKbe2C4=
github.com/urfave/cli/v2 v2.2.0/go.mod h1:SE9GqnLQmjVa0iPEY0f1w3ygNIYcIJ0OKPMoW2caLfQ=
github.com/vmihailenco/msgpack v3.3.3+incompatible/go.mod h1:fy3FlTQTDXWkZ7Bh6AcGMlsjHatGryHQYUTf1ShIgkk=
github.com/vmihailenco/msgpack v4.0.1+incompatible h1:RMF1enSPeKTlXrXdOcqjFUElywVZjjC6pqse21bKbEU=
github.com/vmihailenco/msgpack v4.0.1+incompatible/go.mod h1:fy3FlTQTDXWkZ7Bh6AcGMlsjHatGryHQYUTf1ShIgkk=
Expand Down
31 changes: 29 additions & 2 deletions scalr/data_source_workspace.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,27 @@ func dataSourceTFEWorkspace() *schema.Resource {
},
},

"created_by": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"username": {
Type: schema.TypeString,
Computed: true,
},
"email": {
Type: schema.TypeString,
Computed: true,
},
"full_name": {
Type: schema.TypeString,
Computed: true,
},
},
},
},

"external_id": {
Type: schema.TypeString,
Computed: true,
Expand Down Expand Up @@ -108,9 +129,15 @@ func dataSourceTFEWorkspaceRead(d *schema.ResourceData, meta interface{}) error
d.Set("working_directory", workspace.WorkingDirectory)
d.Set("external_id", workspace.ID)

if workspace.SSHKey != nil {
d.Set("ssh_key_id", workspace.SSHKey.ID)
var createdBy []interface{}
if workspace.CreatedBy != nil {
createdBy = append(createdBy, map[string]interface{}{
"username": workspace.CreatedBy.Username,
"email": workspace.CreatedBy.Email,
"full_name": workspace.CreatedBy.FullName,
})
}
d.Set("created_by", createdBy)

var vcsRepo []interface{}
if workspace.VCSRepo != nil {
Expand Down
4 changes: 3 additions & 1 deletion scalr/data_source_workspace_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,10 @@ func TestAccTFEWorkspaceDataSource_basic(t *testing.T) {
"data.scalr_workspace.foobar", "terraform_version", "0.12.19"),
resource.TestCheckResourceAttr(
"data.scalr_workspace.foobar", "working_directory", "terraform/test"),

resource.TestCheckResourceAttrSet("data.scalr_workspace.foobar", "external_id"),
resource.TestCheckResourceAttrSet("data.scalr_workspace.foobar", "created_by.0.full_name"),
resource.TestCheckResourceAttrSet("data.scalr_workspace.foobar", "created_by.0.email"),
resource.TestCheckResourceAttrSet("data.scalr_workspace.foobar", "created_by.0.username"),
),
},
},
Expand Down
2 changes: 1 addition & 1 deletion scalr/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
"github.com/hashicorp/terraform/helper/schema"
"github.com/hashicorp/terraform/terraform"
tfe "github.com/scalr/go-tfe"
providerVersion "github.com/terraform-providers/terraform-provider-tfe/version"
providerVersion "github.com/scalr/terraform-provider-scalr/version"
)

const defaultHostname = "my.scalr.com"
Expand Down
2 changes: 1 addition & 1 deletion scalr/provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"github.com/hashicorp/terraform-svchost/disco"
"github.com/hashicorp/terraform/helper/schema"
"github.com/hashicorp/terraform/terraform"
"github.com/terraform-providers/terraform-provider-tfe/version"
"github.com/scalr/terraform-provider-scalr/version"
)

var testAccProviders map[string]terraform.ResourceProvider
Expand Down
31 changes: 31 additions & 0 deletions scalr/resource_scalr_workspace.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,27 @@ func resourceTFEWorkspace() *schema.Resource {
},
},

"created_by": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"username": {
Type: schema.TypeString,
Computed: true,
},
"email": {
Type: schema.TypeString,
Computed: true,
},
"full_name": {
Type: schema.TypeString,
Computed: true,
},
},
},
},

"external_id": {
Type: schema.TypeString,
Computed: true,
Expand Down Expand Up @@ -246,6 +267,16 @@ func resourceTFEWorkspaceRead(d *schema.ResourceData, meta interface{}) error {
}
d.Set("ssh_key_id", sshKeyID)

var createdBy []interface{}
if workspace.CreatedBy != nil {
createdBy = append(createdBy, map[string]interface{}{
"username": workspace.CreatedBy.Username,
"email": workspace.CreatedBy.Email,
"full_name": workspace.CreatedBy.FullName,
})
}
d.Set("created_by", createdBy)

var vcsRepo []interface{}
if workspace.VCSRepo != nil {
vcsConfig := map[string]interface{}{
Expand Down
4 changes: 4 additions & 0 deletions scalr/resource_scalr_workspace_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,10 @@ func TestAccTFEWorkspace_basic(t *testing.T) {
"scalr_workspace.foobar", "queue_all_runs", "true"),
resource.TestCheckResourceAttr(
"scalr_workspace.foobar", "working_directory", ""),
resource.TestCheckResourceAttrSet("scalr_workspace.foobar", "external_id"),
resource.TestCheckResourceAttrSet("scalr_workspace.foobar", "created_by.0.full_name"),
resource.TestCheckResourceAttrSet("scalr_workspace.foobar", "created_by.0.email"),
resource.TestCheckResourceAttrSet("scalr_workspace.foobar", "created_by.0.username"),
),
},
},
Expand Down

0 comments on commit 487af98

Please sign in to comment.