diff --git a/github/resource_github_repository_autolink_reference.go b/github/resource_github_repository_autolink_reference.go index 20efb3ffb4..ac976c8ef9 100644 --- a/github/resource_github_repository_autolink_reference.go +++ b/github/resource_github_repository_autolink_reference.go @@ -41,22 +41,15 @@ func resourceGithubRepositoryAutolinkReference() *schema.Resource { "key_prefix": { Type: schema.TypeString, Required: true, - ForceNew: true, Description: "This prefix appended by a number will generate a link any time it is found in an issue, pull request, or commit", + ForceNew: true, }, "target_url_template": { Type: schema.TypeString, Required: true, - ForceNew: true, Description: "The template of the target URL used for the links; must be a valid URL and contain `` for the reference number", ValidateFunc: validation.StringMatch(regexp.MustCompile(`^http[s]?:\/\/[a-z0-9-.]*\/.*?.*?$`), "must be a valid URL and contain token"), - }, - "is_alphanumeric": { - Type: schema.TypeBool, - Optional: true, - ForceNew: true, - Default: true, - Description: "Whether this autolink reference matches alphanumeric characters. If false, this autolink reference only matches numeric characters.", + ForceNew: true, }, "etag": { Type: schema.TypeString, @@ -73,13 +66,11 @@ func resourceGithubRepositoryAutolinkReferenceCreate(d *schema.ResourceData, met repoName := d.Get("repository").(string) keyPrefix := d.Get("key_prefix").(string) targetURLTemplate := d.Get("target_url_template").(string) - isAlphanumeric := d.Get("is_alphanumeric").(bool) ctx := context.Background() opts := &github.AutolinkOptions{ - KeyPrefix: &keyPrefix, - URLTemplate: &targetURLTemplate, - IsAlphanumeric: &isAlphanumeric, + KeyPrefix: &keyPrefix, + URLTemplate: &targetURLTemplate, } autolinkRef, _, err := client.Repositories.AddAutolink(ctx, owner, repoName, opts) @@ -115,7 +106,6 @@ func resourceGithubRepositoryAutolinkReferenceRead(d *schema.ResourceData, meta d.Set("repository", repoName) d.Set("key_prefix", autolinkRef.KeyPrefix) d.Set("target_url_template", autolinkRef.URLTemplate) - d.Set("is_alphanumeric", autolinkRef.IsAlphanumeric) return nil } diff --git a/github/resource_github_repository_autolink_reference_test.go b/github/resource_github_repository_autolink_reference_test.go index b220dae965..4d7cadd22a 100644 --- a/github/resource_github_repository_autolink_reference_test.go +++ b/github/resource_github_repository_autolink_reference_test.go @@ -15,65 +15,25 @@ func TestAccGithubRepositoryAutolinkReference(t *testing.T) { t.Run("creates repository autolink reference without error", func(t *testing.T) { config := fmt.Sprintf(` - resource "github_repository" "test" { - name = "test-%s" - description = "Test autolink creation" + resource "github_repository" "oof" { + name = "oof-%s" + description = "Test autolink creation" } - resource "github_repository_autolink_reference" "autolink_default" { - repository = github_repository.test.name + resource "github_repository_autolink_reference" "autolink" { + repository = github_repository.oof.name - key_prefix = "TEST1-" - target_url_template = "https://example.com/TEST-" - } - - resource "github_repository_autolink_reference" "autolink_alphanumeric" { - repository = github_repository.test.name - - key_prefix = "TEST2-" - target_url_template = "https://example.com/TEST-" - is_alphanumeric = true - } - - resource "github_repository_autolink_reference" "autolink_numeric" { - repository = github_repository.test.name - - key_prefix = "TEST3-" - target_url_template = "https://example.com/TEST-" - is_alphanumeric = false + key_prefix = "OOF-" + target_url_template = "https://awesome.com/find/OOF-" } `, randomID) check := resource.ComposeTestCheckFunc( - // autolink_default - resource.TestCheckResourceAttr( - "github_repository_autolink_reference.autolink_default", "key_prefix", "TEST1-", - ), - resource.TestCheckResourceAttr( - "github_repository_autolink_reference.autolink_default", "target_url_template", "https://example.com/TEST-", - ), - resource.TestCheckResourceAttr( - "github_repository_autolink_reference.autolink_default", "is_alphanumeric", "true", - ), - // autolink_alphanumeric - resource.TestCheckResourceAttr( - "github_repository_autolink_reference.autolink_alphanumeric", "key_prefix", "TEST2-", - ), resource.TestCheckResourceAttr( - "github_repository_autolink_reference.autolink_alphanumeric", "target_url_template", "https://example.com/TEST-", + "github_repository_autolink_reference.autolink", "key_prefix", "OOF-", ), resource.TestCheckResourceAttr( - "github_repository_autolink_reference.autolink_alphanumeric", "is_alphanumeric", "true", - ), - // autolink_numeric - resource.TestCheckResourceAttr( - "github_repository_autolink_reference.autolink_numeric", "key_prefix", "TEST3-", - ), - resource.TestCheckResourceAttr( - "github_repository_autolink_reference.autolink_numeric", "target_url_template", "https://example.com/TEST-", - ), - resource.TestCheckResourceAttr( - "github_repository_autolink_reference.autolink_numeric", "is_alphanumeric", "false", + "github_repository_autolink_reference.autolink", "target_url_template", "https://awesome.com/find/OOF-", ), ) @@ -107,68 +67,19 @@ func TestAccGithubRepositoryAutolinkReference(t *testing.T) { t.Run("imports repository autolink reference without error", func(t *testing.T) { config := fmt.Sprintf(` - resource "github_repository" "test" { - name = "test-%s" - description = "Test autolink creation" - } - - resource "github_repository_autolink_reference" "autolink_default" { - repository = github_repository.test.name - - key_prefix = "TEST1-" - target_url_template = "https://example.com/TEST-" + resource "github_repository" "oof" { + name = "oof-%s" + description = "Test autolink creation" } - resource "github_repository_autolink_reference" "autolink_alphanumeric" { - repository = github_repository.test.name + resource "github_repository_autolink_reference" "autolink" { + repository = github_repository.oof.name - key_prefix = "TEST2-" - target_url_template = "https://example.com/TEST-" - is_alphanumeric = true - } - - resource "github_repository_autolink_reference" "autolink_numeric" { - repository = github_repository.test.name - - key_prefix = "TEST3-" - target_url_template = "https://example.com/TEST-" - is_alphanumeric = false + key_prefix = "OOF-" + target_url_template = "https://awesome.com/find/OOF-" } `, randomID) - check := resource.ComposeTestCheckFunc( - // autolink_default - resource.TestCheckResourceAttr( - "github_repository_autolink_reference.autolink_default", "key_prefix", "TEST1-", - ), - resource.TestCheckResourceAttr( - "github_repository_autolink_reference.autolink_default", "target_url_template", "https://example.com/TEST-", - ), - resource.TestCheckResourceAttr( - "github_repository_autolink_reference.autolink_default", "is_alphanumeric", "true", - ), - // autolink_alphanumeric - resource.TestCheckResourceAttr( - "github_repository_autolink_reference.autolink_alphanumeric", "key_prefix", "TEST2-", - ), - resource.TestCheckResourceAttr( - "github_repository_autolink_reference.autolink_alphanumeric", "target_url_template", "https://example.com/TEST-", - ), - resource.TestCheckResourceAttr( - "github_repository_autolink_reference.autolink_alphanumeric", "is_alphanumeric", "true", - ), - // autolink_numeric - resource.TestCheckResourceAttr( - "github_repository_autolink_reference.autolink_numeric", "key_prefix", "TEST3-", - ), - resource.TestCheckResourceAttr( - "github_repository_autolink_reference.autolink_numeric", "target_url_template", "https://example.com/TEST-", - ), - resource.TestCheckResourceAttr( - "github_repository_autolink_reference.autolink_numeric", "is_alphanumeric", "false", - ), - ) - testCase := func(t *testing.T, mode string) { resource.Test(t, resource.TestCase{ PreCheck: func() { skipUnlessMode(t, mode) }, @@ -176,28 +87,12 @@ func TestAccGithubRepositoryAutolinkReference(t *testing.T) { Steps: []resource.TestStep{ { Config: config, - Check: check, - }, - // autolink_default - { - ResourceName: "github_repository_autolink_reference.autolink_default", - ImportState: true, - ImportStateVerify: true, - ImportStateIdPrefix: fmt.Sprintf("test-%s/", randomID), - }, - // autolink_alphanumeric - { - ResourceName: "github_repository_autolink_reference.autolink_alphanumeric", - ImportState: true, - ImportStateVerify: true, - ImportStateIdPrefix: fmt.Sprintf("test-%s/", randomID), }, - // autolink_numeric { - ResourceName: "github_repository_autolink_reference.autolink_numeric", + ResourceName: "github_repository_autolink_reference.autolink", ImportState: true, ImportStateVerify: true, - ImportStateIdPrefix: fmt.Sprintf("test-%s/", randomID), + ImportStateIdPrefix: fmt.Sprintf("oof-%s/", randomID), }, }, }) @@ -220,16 +115,16 @@ func TestAccGithubRepositoryAutolinkReference(t *testing.T) { t.Run("deletes repository autolink reference without error", func(t *testing.T) { config := fmt.Sprintf(` - resource "github_repository" "test" { - name = "test-%s" - description = "Test autolink creation" + resource "github_repository" "oof" { + name = "oof-%s" + description = "Test autolink creation" } - resource "github_repository_autolink_reference" "autolink_default" { - repository = github_repository.test.name + resource "github_repository_autolink_reference" "autolink" { + repository = github_repository.oof.name - key_prefix = "TEST1-" - target_url_template = "https://example.com/TEST-" + key_prefix = "OOF-" + target_url_template = "https://awesome.com/find/OOF-" } `, randomID) diff --git a/website/docs/r/repository_autolink_reference.html.markdown b/website/docs/r/repository_autolink_reference.html.markdown index c0406dae4d..8f9ed6870a 100644 --- a/website/docs/r/repository_autolink_reference.html.markdown +++ b/website/docs/r/repository_autolink_reference.html.markdown @@ -13,18 +13,18 @@ This resource allows you to create and manage an autolink reference for a single ```hcl resource "github_repository" "repo" { - name = "my-repo" + name = "oof" description = "GitHub repo managed by Terraform" private = false } -resource "github_repository_autolink_reference" "autolink" { +resource "github_repository_autolink_reference" "auto" { repository = github_repository.repo.name key_prefix = "TICKET-" - target_url_template = "https://example.com/TICKET?query=" + target_url_template = "https://hello.there/TICKET?query=" } ``` @@ -38,8 +38,6 @@ The following arguments are supported: * `target_url_template` - (Required) The template of the target URL used for the links; must be a valid URL and contain `` for the reference number -* `is_alphanumeric` - (Optional) Whether this autolink reference matches alphanumeric characters. If false, this autolink reference only matches numeric characters. Default is true. - ## Attributes Reference The following additional attributes are exported: @@ -51,7 +49,5 @@ The following additional attributes are exported: Autolink references can be imported using the `name` of the repository, combined with the `id` of the autolink reference and a `/` character for separating components, e.g. ```sh -terraform import github_repository_autolink_reference.auto my-repo/123 +terraform import github_repository_autolink_reference.auto oof/123 ``` - -See the GitHub documentation for how to [list all autolinks of a repository](https://docs.github.com/en/rest/repos/autolinks#list-all-autolinks-of-a-repository) to learn the autolink ids to use with the import command. \ No newline at end of file