https://pulumi.com logo
#general
Title
# general
t

tall-microphone-84203

02/18/2024, 1:46 PM
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

elegant-window-55250

02/19/2024, 8:02 AM
Are you using a provider?
t

tall-microphone-84203

02/19/2024, 8:03 AM
Hey @elegant-window-55250 nope
e

elegant-window-55250

02/19/2024, 8:03 AM
Can you show me an example of the repo resource?
t

tall-microphone-84203

02/19/2024, 8:06 AM
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

elegant-window-55250

02/19/2024, 8:07 AM
Can you try to set the
owner
argument?
t

tall-microphone-84203

02/19/2024, 8:09 AM
Yeah I tried that, it says it's an invalid argument 😞 :
Copy code
TypeError: Repository._internal_init() got an unexpected keyword argument 'owner'
e

elegant-window-55250

02/19/2024, 8:09 AM
Try with a GitHub provider
t

tall-microphone-84203

02/19/2024, 8:10 AM
Is there any config I need to add in order to try it with a provider?
e

elegant-window-55250

02/19/2024, 8:11 AM
Not config, but you need to add the provider resource and reference it on each resource.
t

tall-microphone-84203

02/20/2024, 11:32 AM
sorry @elegant-window-55250 do you mind showing me an example I can delete everything, teams, branch protection rules just not repos?
e

elegant-window-55250

02/20/2024, 11:32 AM
Copy code
provider = Provider(name="github", owner="hello")

repo = Repository(name= ...,
I forgot to post that ☝️
t

tall-microphone-84203

02/20/2024, 11:54 AM
and the owner would then the org?
e

elegant-window-55250

02/20/2024, 11:54 AM
Yes 🙂
How has things worked out, @tall-microphone-84203?
t

tall-microphone-84203

02/23/2024, 10:21 AM
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

elegant-window-55250

02/23/2024, 11:20 AM
Okey, can you try with setting the personal access token directly as
token
in the provider?
4 Views