zahiar / terraform-provider-bitbucket

Terraform Provider for Bitbucket Cloud
https://registry.terraform.io/providers/zahiar/bitbucket/latest
Mozilla Public License 2.0
19 stars 22 forks source link

Issue in creating groups #89

Closed kevinduterne closed 2 years ago

kevinduterne commented 2 years ago

When trying to create a group the group is created but not found in a refresh

Provider version = 1.0.3 Terraform version = 1.1.2 / 1.1.8

Create a group with this code

data "bitbucket_workspace" "company" {
  id = "company_slug"
}
resource "bitbucket_group" "group" {
  for_each  = var.groups
  workspace = data.bitbucket_workspace.company.uuid
  name      = each.key
}
variable "groups" { 
}

groups.auto.tfvars

groups = {
  "everyone" = {
    everyone = true
  }
}

We get a correct plan

Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols:
  + create

Terraform will perform the following actions:

  # bitbucket_group.group["everyone"] will be created
  + resource "bitbucket_group" "group" {
      + auto_add  = false
      + id        = (known after apply)
      + name      = "everyone"
      + slug      = (known after apply)
      + workspace = "{xxxxxxxxxxxxxxxxxxxxxxxxx}"
    }

Plan: 1 to add, 0 to change, 0 to destroy.

Changes to Outputs:
  + name = {
      + everyone = (known after apply)
    }
╷
│ Warning: Resource targeting is in effect
│ 
│ You are creating a plan with the -target option, which means that the result of this plan may not represent all of the changes requested by the current configuration.
│ 
│ The -target option is not for routine use, and is provided only for exceptional situations such as recovering from errors or mistakes, or when Terraform specifically suggests to use it as part of an
│ error message.
╵
╷
│ Warning: Experimental feature "module_variable_optional_attrs" is active
│ 
│   on providers.tf line 7, in terraform:
│    7:   experiments      = [module_variable_optional_attrs]
│ 
│ Experimental features are subject to breaking changes in future minor or patch releases, based on feedback.
│ 
│ If you have feedback on the design of this feature, please open a GitHub issue to discuss it.
╵

─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────

Saved the plan to: terraform.plan

To perform exactly these actions, run the following command to apply:
    terraform apply "terraform.plan"

But then the apply seems to fail however the group is visible in bitbucket Also dont seem to be able to import the group


bitbucket_group.group["everyone"]: Creating...
╷
│ Warning: Applied changes may be incomplete
│ 
│ The plan was created with the -target option in effect, so some changes requested in the configuration may have been ignored and the output values may not be fully updated. Run the following command to
│ verify that no other changes are pending:
│     terraform plan
│ 
│ Note that the -target option is not suitable for routine use, and is provided only for exceptional situations such as recovering from errors or mistakes, or when Terraform specifically suggests to use it
│ as part of an error message.
╵
╷
│ Warning: Experimental feature "module_variable_optional_attrs" is active
│ 
│   on providers.tf line 7, in terraform:
│    7:   experiments      = [module_variable_optional_attrs]
│ 
│ Experimental features are subject to breaking changes in future minor or patch releases, based on feedback.
│ 
│ If you have feedback on the design of this feature, please open a GitHub issue to discuss it.
╵
╷
│ Error: unable to get group with error: no group found
│ 
│   with bitbucket_group.group["everyone"],
│   on main.tf line 110, in resource "bitbucket_group" "group":
│  110: resource "bitbucket_group" "group" {``` 
kevinduterne commented 2 years ago

Little status update I was able to resolve the issue by manually adding one user and then importing the resource.

I think the issue has something to do with the account being a bitbucket teams account :

It failed import/creation in this state :

 {
        "name": "everyone",
        "permission": null,
        "email_forwarding_disabled": false,
        "auto_add": false,
        "members": [],
        "owner": {
            "display_name": "CompanyOwner",
            "uuid": "{xxxxxxxxxxxxxxxxxxx}",
            "account_id": null,
            "is_team": true,
            "avatar": "https://bitbucket.org/account/company/avatar/?ts=xxxxxxxxxxxxxxxx",
            "nickname": "Company",
            "resource_uri": "/1.0/users/%xxxxxxxxxxxxxxxxxxxxxxxxxxxx"
        },
        "slug": "everyone"
    },

When adding one user in the UI and becoming this state it worked

    {
        "name": "everyone",
        "permission": null,
        "email_forwarding_disabled": false,
        "auto_add": false,
        "members": [
            {
                "display_name": "Kevin Duterne",
                "account_id": "xxxxxxxxxxxxxxxxxxxx",
                "is_active": true,
                "is_team": false,
                "is_staff": false,
                "avatar": "https://avatar-management--avatars.us-west-2.prod.public.atl-paas.net/557058:d9c0821a-55f5-49cf-8e48-571c69cfa9c2/54bf92b4-3ca1-4274-bd90-21551a44de24/128",
                "resource_uri": "/api/1.0/users/%7Bxxxxxxxxxxxxxxxxxxxxxxx%7D",
                "nickname": "Kevin Duterne",
                "uuid": "{xxxxxxxxxxxxxxxxxxxxxx}"
            }
        ],
        "owner": {
            "display_name": "Company-Owner",
            "uuid": "{xxxxxxxxxxxxxxxxxxx}",
            "account_id": null,
            "is_team": true,
            "avatar": "https://bitbucket.org/account/company/avatar/?ts=xxxxxxxxx",
            "nickname": "company",
            "resource_uri": "/1.0/users/%xxxxxxxxxxxxxx
        },
        "slug": "everyone"
    },
zahiar commented 2 years ago

Good to see you were able to resolve it 🙂