Skip to content

Commit

Permalink
Update Github resources
Browse files Browse the repository at this point in the history
  • Loading branch information
lawliet89 committed Jul 29, 2019
1 parent 2848fe6 commit 95dbb5b
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 8 deletions.
1 change: 1 addition & 0 deletions vault/auth_token.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ func updateTokenFields(d *schema.ResourceData, data map[string]interface{}, crea
if d.HasChange("token_policies") {
data["token_policies"] = d.Get("token_policies").(*schema.Set).List()
}

if d.HasChange("token_explicit_max_ttl") {
data["token_explicit_max_ttl"] = d.Get("token_explicit_max_ttl").(int)
}
Expand Down
9 changes: 5 additions & 4 deletions vault/resource_github_team.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,9 @@ func githubTeamResource() *schema.Resource {
}
}

func githubTeamUpdateFields(d *schema.ResourceData, data map[string]interface{}, create bool) error {
updateTokenFields(d, data, create)
func githubTeamUpdateFields(d *schema.ResourceData, data map[string]interface{}) error {
// Always in "create" mode because this endpoint unsets fields that are omitted during updates
updateTokenFields(d, data, true)

data["key"] = d.Get("team").(string)
if v, ok := d.GetOk("policies"); ok {
Expand All @@ -74,7 +75,7 @@ func githubTeamCreate(d *schema.ResourceData, meta interface{}) error {
d.MarkNewResource()

data := map[string]interface{}{}
githubTeamUpdateFields(d, data, true)
githubTeamUpdateFields(d, data)

log.Printf("[INFO] Creating new github team map at '%v'", id)

Expand All @@ -94,7 +95,7 @@ func githubTeamUpdate(d *schema.ResourceData, meta interface{}) error {
path := d.Id()

data := map[string]interface{}{}
githubTeamUpdateFields(d, data, true)
githubTeamUpdateFields(d, data)

_, err := client.Logical().Write(path, data)
if err != nil {
Expand Down
4 changes: 4 additions & 0 deletions vault/resource_github_team_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ func TestAccGithubTeam_basic(t *testing.T) {
resource.TestCheckResourceAttr(resName, "team", "my-team-slugified"),
resource.TestCheckResourceAttr(resName, "token_policies.#", "2"),
resource.TestCheckResourceAttr(resName, "token_ttl", "300"),
resource.TestCheckResourceAttr(resName, "token_max_ttl", "1800"),
),
},
{
Expand All @@ -40,6 +41,8 @@ func TestAccGithubTeam_basic(t *testing.T) {
resource.TestCheckResourceAttr(resName, "backend", backend),
resource.TestCheckResourceAttr(resName, "team", "my-team-slugified"),
resource.TestCheckResourceAttr(resName, "token_policies.#", "0"),
resource.TestCheckResourceAttr(resName, "token_ttl", "300"),
resource.TestCheckResourceAttr(resName, "token_max_ttl", "1800"),
),
},
},
Expand Down Expand Up @@ -126,6 +129,7 @@ resource "vault_github_team" "team" {
team = "%s"
token_policies = %s
token_ttl = 300
token_max_ttl = 1800
}
`, backend, team, p)
}
9 changes: 5 additions & 4 deletions vault/resource_github_user.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,9 @@ func githubUserResource() *schema.Resource {
}
}

func githubUserUpdateFields(d *schema.ResourceData, data map[string]interface{}, create bool) error {
updateTokenFields(d, data, create)
func githubUserUpdateFields(d *schema.ResourceData, data map[string]interface{}) error {
// Always in "create" mode because this endpoint unsets fields that are omitted during updates
updateTokenFields(d, data, true)

data["key"] = d.Get("user").(string)
if v, ok := d.GetOk("policies"); ok {
Expand All @@ -74,7 +75,7 @@ func githubUserCreate(d *schema.ResourceData, meta interface{}) error {
d.MarkNewResource()

data := map[string]interface{}{}
githubUserUpdateFields(d, data, true)
githubUserUpdateFields(d, data)

log.Printf("[INFO] Creating new github user map at '%v'", id)
_, err := client.Logical().Write(id, data)
Expand All @@ -93,7 +94,7 @@ func githubUserUpdate(d *schema.ResourceData, meta interface{}) error {
path := d.Id()

data := map[string]interface{}{}
githubUserUpdateFields(d, data, false)
githubUserUpdateFields(d, data)

_, err := client.Logical().Write(path, data)
if err != nil {
Expand Down
6 changes: 6 additions & 0 deletions vault/resource_github_user_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ func TestAccGithubUser_basic(t *testing.T) {
resource.TestCheckResourceAttr(resName, "backend", backend),
resource.TestCheckResourceAttr(resName, "user", "john_doe"),
resource.TestCheckResourceAttr(resName, "token_policies.#", "2"),
resource.TestCheckResourceAttr(resName, "token_ttl", "300"),
resource.TestCheckResourceAttr(resName, "token_max_ttl", "1800"),
),
},
{
Expand All @@ -37,6 +39,8 @@ func TestAccGithubUser_basic(t *testing.T) {
resource.TestCheckResourceAttr(resName, "backend", backend),
resource.TestCheckResourceAttr(resName, "user", "john_doe"),
resource.TestCheckResourceAttr(resName, "token_policies.#", "0"),
resource.TestCheckResourceAttr(resName, "token_ttl", "300"),
resource.TestCheckResourceAttr(resName, "token_max_ttl", "1800"),
),
},
},
Expand Down Expand Up @@ -106,6 +110,8 @@ resource "vault_github_user" "user" {
backend = "${vault_github_auth_backend.gh.id}"
user = "%s"
token_policies = %s
token_ttl = 300
token_max_ttl = 1800
}
`, backend, user, p)
}

0 comments on commit 95dbb5b

Please sign in to comment.