Skip to content

Commit

Permalink
Merge pull request #262 from stackhpc/rename-roles
Browse files Browse the repository at this point in the history
Rename Ansible roles, stop pushing linters on cephadm collection
  • Loading branch information
markgoddard authored Nov 23, 2023
2 parents 6df6095 + d7eb014 commit 909e2c2
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 8 deletions.
10 changes: 6 additions & 4 deletions ansible/inventory/group_vars/all/source-repositories
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ source_repositories:
- codeowners:
content: "{{ community_files.codeowners.ansible }}"
dest: ".github/CODEOWNERS"
ansible-role-os-networks:
os-networks:
repository_type: "ansible"
workflows: "{{ ansible_workflows.role }}"
community_files:
Expand Down Expand Up @@ -502,7 +502,7 @@ source_repositories:
- codeowners:
content: "{{ community_files.codeowners.ansible }}"
dest: ".github/CODEOWNERS"
ansible-role-dell-powerconnect-switch:
dell-powerconnect-switch:
repository_type: "ansible"
workflows: "{{ ansible_workflows.role }}"
community_files:
Expand All @@ -523,7 +523,7 @@ source_repositories:
- codeowners:
content: "{{ community_files.codeowners.ansible }}"
dest: ".github/CODEOWNERS"
ansible-role-mellanox-switch:
mellanox-switch:
repository_type: "ansible"
workflows: "{{ ansible_workflows.role }}"
community_files:
Expand Down Expand Up @@ -553,7 +553,9 @@ source_repositories:
dest: ".github/CODEOWNERS"
ansible-collection-cephadm:
repository_type: "ansible"
workflows: "{{ ansible_workflows.collection }}"
workflows:
# Linters workflows not currently working on the Cephadm collection.
- publish-collection
community_files:
- codeowners:
content: "{{ community_files.codeowners.ansible }}"
Expand Down
65 changes: 64 additions & 1 deletion docs/usage/github-organisation-management.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,4 +117,67 @@ terraform state rm 'github_branch_protection.ansible_branch_protection["ansible-

The general form for `state rm` is `${resource_address}["resource_id"]`.
You can found out more about the `state rm` command here [here](https://www.terraform.io/cli/commands/state/rm).
You may also find documentation about the GitHub provider which may provide insight into how the resources are composed [here](https://registry.terraform.io/providers/integrations/github/latest/docs)
You may also find documentation about the GitHub provider which may provide insight into how the resources are composed [here](https://registry.terraform.io/providers/integrations/github/latest/docs)

### Renaming Resources

To rename a resource you must first identify and rename the entry within `terraform.tfvars.json`.
Without further intervention Terraform will see this as deletion of one resource and creation of another, and would typically return a failure when trying to create the resource that already exists.
To resolve this issue you will need access to the Terraform Cloud GitHub workspace, if you don't have access then you may request access or have someone who does have access to perform the rename on your behalf.

Prior to renaming a resource you must ensure that you have the Terraform CLI tools and have authenticated with Terraform Cloud, instructions for this can be found [here](https://www.terraform.io/cli/commands/login).

In the following example we will rename the `ansible-role-os-networks` repository to `os-networks`.

Clone this repository and change to the `terraform/github` directory:

```sh
git clone [email protected]:stackhpc/stackhpc-release-train.git
cd stackhpc-release-train/terraform/github
```

Rename the `ansible-role-os-networks` entry in `terraform.tfvars.json`.
Commit the change and push to a branch on GitHub.

Create a script named `rename-repo.sh` with the following content:

```sh
#!/bin/bash -eux

repo_src=${1:?Repo source}
repo_dst=${2:?Repo destination}

# e.g. -dry-run
args=""

# This resource list will vary depending on the repository.
# In particurlar this may include the branch protection and team associations.
resources="github_branch_protection.ansible_branch_protection \
github_issue_label.community_files_label \
github_issue_label.stackhpc_ci_label \
github_issue_label.workflows_label \
github_team_repository.admin_repositories \
github_team_repository.ansible_repositories \
github_team_repository.developers_repositories \
github_repository.repositories"

for resource in $resources; do
terraform state mv $args "$resource[\"$repo_src\"]" "$resource[\"$repo_dst\"]"
done
```

Edit the `resources` list based on the output of `terraform state list | grep <repo>`

Make the script executable:

```sh
chmod +x rename-repo.sh
```

Run the script to rename the repository. Note that this will directly update the state file in Terraform cloud:

```sh
./rename-repo.sh ansible-role-os-networks os-networks
```

Create a PR for the changes.
6 changes: 3 additions & 3 deletions terraform/github/terraform.tfvars.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"repositories": {
"Ansible": [
"ansible-role-os-host-aggregates",
"ansible-role-os-networks",
"os-networks",
"ansible-role-os-projects",
"ansible-role-libvirt-host",
"ansible-role-libvirt-vm",
Expand All @@ -30,10 +30,10 @@
"stackhpc.ipmi-exporter",
"ansible-role-mlnx-ufm",
"ansible-role-rundeck",
"ansible-role-dell-powerconnect-switch",
"dell-powerconnect-switch",
"drac-facts",
"ansible-role-gluster-cluster",
"ansible-role-mellanox-switch",
"mellanox-switch",
"ansible-role-os-config",
"ansible-role-os-deploy-templates",
"ansible-role-mlnx-neo",
Expand Down

0 comments on commit 909e2c2

Please sign in to comment.