Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to import github repo due to auto_init #148

Closed
gabrielsyapse opened this issue Sep 7, 2018 · 5 comments
Closed

Unable to import github repo due to auto_init #148

gabrielsyapse opened this issue Sep 7, 2018 · 5 comments
Assignees
Labels
Type: Bug Something isn't working as documented

Comments

@gabrielsyapse
Copy link

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

@radeksimko radeksimko added Type: Bug Something isn't working as documented upstream-terraform labels Sep 7, 2018
@radeksimko
Copy link
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.

@joebowbeer
Copy link

@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?

@sstarcher
Copy link

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

@radeksimko
Copy link
Contributor

radeksimko commented Sep 14, 2018

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.

@radeksimko
Copy link
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.

jordane added a commit to jordane/terraform-provider-github that referenced this issue Feb 7, 2019
After PR integrations#135, auto_init, license_template, and gitignore_template now all
have ForceNew set to true, which means they *will* affect the resource after
initial creation. See also PR integrations#148, integrations#155, integrations#164

Signed-off-by: Jordan Evans <jevans@linuxfoundation.org>
kfcampbell pushed a commit to kfcampbell/terraform-provider-github that referenced this issue Jul 26, 2022
After PR integrations#135, auto_init, license_template, and gitignore_template now all
have ForceNew set to true, which means they *will* affect the resource after
initial creation. See also PR integrations#148, integrations#155, integrations#164

Signed-off-by: Jordan Evans <jevans@linuxfoundation.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Bug Something isn't working as documented
Projects
None yet
Development

No branches or pull requests

4 participants