Hi Team, has anyone ran into the below issue when ...
# general
t
Hi Team, has anyone ran into the below issue when trying to destroy a GitHub repo? I am the owner of the org and the one that ran the pulumi up but when I try and destroy, I get a 403 error yet my PAT has all the scopes:
Copy code
DELETE <https://api.github.com/repos/xxxx>: 403 Must have admin rights to Repository. []
e
Are you using a provider?
t
Hey @elegant-window-55250 nope
e
Can you show me an example of the repo resource?
t
Yeah sure:
Copy code
import pulumi
from pulumi_github import Repository, RepositoryFile
from utilities.naming import generate_repo_name

def create_repository(param1, param2):
    """
    Creates a GitHub repository with a generated name and adds a README.md from a template.
    """

    # Generate the repository name
    repo_name = generate_repo_name(param1, param2)

    # Create the repository
    repo = Repository(name=repo_name, # repo name
                      resource_name=repo_name,
                      description=f"Repository for {repo_name}",
                      visibility="private", 
                      auto_init=True)

    # Read the README content from the template file
    with open("repos/README_TEMPLATE.md", "r") as readme_file:
        readme_content = readme_file.read()

    # Wait for the repository name to be available and then create the README.md file in the new repo
    pulumi.Output.all(repo.name).apply(lambda args: 
        RepositoryFile("README.md",
                       repository=args[0],
                       file="README.md",
                       content=readme_content,
                       branch="main",
                       overwrite_on_create=True  # Overwrite if a file already exists due to repo init
        )
    )

    pulumi.export('repository_name', repo.name)
e
Can you try to set the
owner
argument?
t
Yeah I tried that, it says it's an invalid argument 😞 :
Copy code
TypeError: Repository._internal_init() got an unexpected keyword argument 'owner'
e
Try with a GitHub provider
t
Is there any config I need to add in order to try it with a provider?
e
Not config, but you need to add the provider resource and reference it on each resource.
t
sorry @elegant-window-55250 do you mind showing me an example I can delete everything, teams, branch protection rules just not repos?
e
Copy code
provider = Provider(name="github", owner="hello")

repo = Repository(name= ...,
I forgot to post that ☝️
t
and the owner would then the org?
e
Yes 🙂
How has things worked out, @tall-microphone-84203?
t
Hey @elegant-window-55250 thanks for the follow up. Even using the provider I get the same error, but teams and branch protection can be deleted...
e
Okey, can you try with setting the personal access token directly as
token
in the provider?