Skip to content

Commit

Permalink
Changed how to setid
Browse files Browse the repository at this point in the history
  • Loading branch information
wrighbr committed Jun 11, 2020
1 parent f6552c6 commit 89baca4
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
12 changes: 10 additions & 2 deletions provider/resource_project.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func resourceProjectCreate(d *schema.ResourceData, m interface{}) error {
return err
}

d.SetId(randomString(15))
// d.SetId(randomString(15))
return resourceProjectRead(d, m)
}

Expand All @@ -98,7 +98,15 @@ func resourceProjectRead(d *schema.ResourceData, m interface{}) error {
return fmt.Errorf("[ERROR] JsonData is empty")
}

d.Set("project_id", jsonData[0].ProjectID)
for _, v := range jsonData {
if v.Name == d.Get("name").(string) {
d.SetId(strconv.Itoa(v.ProjectID))
d.Set("project_id", strconv.Itoa(v.ProjectID))
}

}

// d.Set("project_id", jsonData[0].ProjectID)
return nil
}

Expand Down
2 changes: 1 addition & 1 deletion provider/resource_robot_account.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@ func resourceRobotAccountCreate(d *schema.ResourceData, m interface{}) error {
return fmt.Errorf("[ERROR] Unable to unmarshal: %s", err)
}

d.SetId(randomString(15))
d.Set("token", jsonData.Token)
return resourceRobotAccountRead(d, m)
}
Expand Down Expand Up @@ -128,6 +127,7 @@ func resourceRobotAccountRead(d *schema.ResourceData, m interface{}) error {

for _, v := range jsonData {
if v.Name == "robot$"+name {
d.SetId(strconv.Itoa(v.RobotID))
d.Set("robot_id", strconv.Itoa(v.RobotID))
}
}
Expand Down

0 comments on commit 89baca4

Please sign in to comment.