diff --git a/README.md b/README.md index 93402c7..fcd0ce5 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,7 @@ terraform { required_providers { gitea = { source = "Lerentis/gitea" - version = "0.7.1" + version = "0.7.2" } } } diff --git a/docs/index.md b/docs/index.md index c353dba..e5e038b 100644 --- a/docs/index.md +++ b/docs/index.md @@ -17,7 +17,7 @@ terraform { required_providers { gitea = { source = "Lerentis/gitea" - version = "0.3.0" + version = "0.7.2" } } } diff --git a/examples/main.tf b/examples/main.tf index 79b3707..d3fe2ac 100644 --- a/examples/main.tf +++ b/examples/main.tf @@ -18,7 +18,8 @@ resource "gitea_repository" "mirror" { } resource "gitea_org" "test_org" { - name = "test-org" + name = "test-org" + description = "test description" } resource "gitea_repository" "org_repo" { diff --git a/examples/provider.tf b/examples/provider.tf index 65f23dd..24f0fca 100644 --- a/examples/provider.tf +++ b/examples/provider.tf @@ -2,7 +2,7 @@ terraform { required_providers { gitea = { source = "terraform.local/lerentis/gitea" - version = "0.7.1" + version = "0.7.2" } } } diff --git a/examples/provider/provider.tf b/examples/provider/provider.tf index c88cb79..4e8d17a 100644 --- a/examples/provider/provider.tf +++ b/examples/provider/provider.tf @@ -2,7 +2,7 @@ terraform { required_providers { gitea = { source = "Lerentis/gitea" - version = "0.3.0" + version = "0.7.2" } } } diff --git a/gitea/resource_gitea_organisation.go b/gitea/resource_gitea_organisation.go index 362b0d6..f13ca93 100644 --- a/gitea/resource_gitea_organisation.go +++ b/gitea/resource_gitea_organisation.go @@ -17,20 +17,60 @@ const ( RepoAdminChangeTeamAccess string = "repo_admin_change_team_access" ) +// might come in handy if we want to stick to numeric IDs +/*func searchOrgByClientId(c *gitea.Client, id int64) (res *gitea.Organization, err error) { + + page := 1 + + for { + orgs, _, err := c.AdminListOrgs(gitea.AdminListOrgsOptions{ + ListOptions: gitea.ListOptions{ + Page: page, + PageSize: 50, + }, + }) + if err != nil { + return nil, err + } + + if len(orgs) == 0 { + return nil, fmt.Errorf("Organisation with ID %d could not be found", id) + } + + for _, org := range orgs { + if org.ID == id { + return org, nil + } + } + + page += 1 + } +}*/ + func resourceOrgRead(d *schema.ResourceData, meta interface{}) (err error) { client := meta.(*gitea.Client) var org *gitea.Organization var resp *gitea.Response + var tmpOrgName string - org, resp, err = client.GetOrg(d.Get(orgName).(string)) + if d.Get(orgName).(string) == "" { + // terraform import as only access to the ID, therfore we set the ID to the name + tmpOrgName = d.Id() + } else { + tmpOrgName = d.Get(orgName).(string) + } + + org, resp, err = client.GetOrg(tmpOrgName) if err != nil { - if resp.StatusCode == 404 { - d.SetId("") - return nil + if resp != nil { + if resp.StatusCode == 404 { + d.SetId("") + return + } } else { - return err + return fmt.Errorf("Error response from client: %s\nOrg Name %s", err, tmpOrgName) } } @@ -114,7 +154,7 @@ func resourceOrgDelete(d *schema.ResourceData, meta interface{}) (err error) { } func setOrgResourceData(org *gitea.Organization, d *schema.ResourceData) (err error) { - d.SetId(fmt.Sprintf("%d", org.ID)) + d.SetId(org.UserName) d.Set("name", org.UserName) d.Set("full_name", org.FullName) d.Set("avatar_url", org.AvatarURL) @@ -133,7 +173,7 @@ func resourceGiteaOrg() *schema.Resource { Update: resourceOrgUpdate, Delete: resourceOrgDelete, Importer: &schema.ResourceImporter{ - State: schema.ImportStatePassthrough, + StateContext: schema.ImportStatePassthroughContext, }, Schema: map[string]*schema.Schema{ "name": {