Skip to content

Commit 0695b1f

Browse files
mathieu-lemaytechknowlogick
authored andcommitted
fix: Import all fields when importing a public key (#104)
The setPublicKeyResourceData function previously set the PublicKeyUser, PublicKey, and PublicKeyReadOnlyFlag values from the terraform data itself. While this works fine for data created with terraform, it doesn't work when importing existing public keys. Imported keys would have zero values for those fields, forcing a re-create. While this is not a problem on its own, the delete part of the re-create would then crash due to an empty username. This fixes the import so the username and the key are imported from Gitea's API. Reviewed-on: https://gitea.com/gitea/terraform-provider-gitea/pulls/104 Co-authored-by: Mathieu Lemay <[email protected]> Co-committed-by: Mathieu Lemay <[email protected]>
1 parent 21ba4bb commit 0695b1f

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

gitea/resource_gitea_public_key.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,10 +90,10 @@ func resourcePublicKeyDelete(d *schema.ResourceData, meta interface{}) (err erro
9090

9191
func setPublicKeyResourceData(pubKey *gitea.PublicKey, d *schema.ResourceData) (err error) {
9292
d.SetId(fmt.Sprintf("%d", pubKey.ID))
93-
d.Set(PublicKeyUser, d.Get(PublicKeyUser).(string))
94-
d.Set(PublicKey, d.Get(PublicKey).(string))
93+
d.Set(PublicKeyUser, pubKey.Owner.UserName)
94+
d.Set(PublicKey, pubKey.Key)
9595
d.Set(PublicKeyTitle, pubKey.Title)
96-
d.Set(PublicKeyReadOnlyFlag, d.Get(PublicKeyReadOnlyFlag).(bool))
96+
d.Set(PublicKeyReadOnlyFlag, pubKey.ReadOnly)
9797
d.Set(PublicKeyCreated, pubKey.Created)
9898
d.Set(PublicKeyFingerprint, pubKey.Fingerprint)
9999
d.Set(PublicKeyType, pubKey.KeyType)

0 commit comments

Comments
 (0)