Skip to content

Unable to import github repo due to auto_init #148

Closed

Description

@gabrielsyapse

Expected Behavior

Should be able to import an already created github repo and then run terraform apply without it wanting to recreate the repo.

Actual Behavior

In our terraform, we set the argument auto_init = true. Recently, there was a commit which changed the behavior. Before I was able to import an already created github repo into terraform state and then run apply, but now, it wants to recreate it, due to the ForceNew, which has been added. So, I can't safely import a repo.

auto_init:          "" => "true" (forces new resource)

For now, I have pinned to v1.1.0 and then was able to proceed and had the expected behavior. It just wanted to modify the single argument.

auto_init: "" => "true"

References

https://github.com/terraform-providers/terraform-provider-github/pull/135

Version

Terraform v0.11.7

Affected Resource(s)

github_repository

Activity

  1. added
    Type: Bug
    on Sep 7, 2018
  2. radeksimko commented on Sep 11, 2018

    @radeksimko
    Contributor

    Hi @gabrielsyapse
    the behaviour you described is (unfortunately) expected since you're importing an existing repository and the GitHub API doesn't tell us whether the repository was auto-initialized, so we have no way of knowing whether to set auto_init to true or false when importing that resource.

    We have discussed some long-term plans on improving the (currently limited) important functionality, but I'm afraid there isn't much better solution other than setting auto_init = false in your config after importing that resource for now.

    Prior to the 1.2 that field appeared updatable, but was in fact ignored, which may have caused some confusions and bugs. So the previous behaviour was actually wrong and now is fixed.

    I'm going to leave this open for reference, but it needs to be addressed at higher level (helper schema / core) and there's a lot of work currently underway related to 0.12, so I wouldn't expect this to be implemented before shipping that version later this year.

  3. joebowbeer commented on Sep 13, 2018

    @joebowbeer

    @radeksimko Can you be more specific regarding the workaround? I've tried several options and the only one that avoided the recreate is to remove the flag from my module. But then I don't know how to accomplish an auto_init. What are the steps to auto_init on create and also avoid subsequent recreations?

  4. sstarcher commented on Sep 13, 2018

    @sstarcher

    Our decision was to add a lifecycle of ignore_changes to auto_init.

  5. self-assigned this
    on Sep 14, 2018
  6. radeksimko commented on Sep 14, 2018

    @radeksimko
    Contributor

    My sincere apologies to everyone! 😑I drew conclusions before trying to reproduce it as it looked very similar to some other bugs I saw in the wild in the past.

    Basically I was under the impression that we just set auto_init to false by default on import/read, but that's apparently not happening. There's currently no workaround except what @sstarcher mentioned. See below.

    I will raise a PR with patch and aim to get it shipped in 1.3.1.
    Bear with me, please.

  7. radeksimko commented on Sep 14, 2018

    @radeksimko
    Contributor

    Sorry again for the overlook from my side.
    Just a quick update: PR to fix this was just raised in https://github.com/terraform-providers/terraform-provider-github/pull/154

    Also I just realized (while testing my PR) that there is, in fact a workaround, and that is to omit the auto_init argument completely from the config:

    provider "github" {
      organization = "terraform-providers"
    }
    
    resource "github_repository" "github_repository" {
      name               = "terraform-provider-github"
      description        = "Terraform GitHub provider"
      homepage_url       = "https://www.terraform.io/docs/providers/github/"
      topics = ["terraform-provider", "github", "terraform"]
      private            = false
      has_issues         = true
      has_wiki           = false
      has_downloads = true
      allow_merge_commit = true
      allow_squash_merge = true
      allow_rebase_merge = true
      default_branch     = "master"
      archived           = false
    }
    $ terraform init
    
    Initializing provider plugins...
    - Checking for available provider plugins on https://releases.hashicorp.com...
    - Downloading plugin for provider "github" (1.3.0)...
    
    The following providers do not have any version constraints in configuration,
    so the latest version was installed.
    
    To prevent automatic upgrades to new major versions that may contain breaking
    changes, it is recommended to add version = "..." constraints to the
    corresponding provider blocks in configuration, with the constraint strings
    suggested below.
    
    * provider.github: version = "~> 1.3"
    
    Terraform has been successfully initialized!
    
    $ terraform import github_repository.github_repository terraform-provider-github
    github_repository.github_repository: Importing from ID "terraform-provider-github"...
    github_repository.github_repository: Import complete!
      Imported github_repository (ID: terraform-provider-github)
    github_repository.github_repository: Refreshing state... (ID: terraform-provider-github)
    
    Import successful!
    
    The resources that were imported are shown above. These resources are now in
    your Terraform state and will henceforth be managed by Terraform.
    
    $ terraform plan
    Refreshing Terraform state in-memory prior to plan...
    The refreshed state will be used to calculate this plan, but will not be
    persisted to local or remote state storage.
    
    github_repository.github_repository: Refreshing state... (ID: terraform-provider-github)
    
    ------------------------------------------------------------------------
    
    No changes. Infrastructure is up-to-date.
    
    This means that Terraform did not detect any differences between your
    configuration and real physical resources that exist. As a result, no
    actions need to be performed.
    
  8. added a commit that references this issue on Feb 7, 2019
  9. added a commit that references this issue on Jul 26, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type: Bug

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions