Skip to content

Commit

Permalink
Move to official provider for runner-manager app
Browse files Browse the repository at this point in the history
  • Loading branch information
rahearn committed Jan 15, 2025
1 parent 8103d60 commit 3bbe67c
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 36 deletions.
2 changes: 1 addition & 1 deletion README.terraform.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ For local development, there is a `sandbox-deploy` module set up to deploy the r
1. Create a [cloud.gov service account](https://cloud.gov/docs/services/cloud-gov-service-account/) with the `OrgManager` permission
```
./create_service_account -s SPACEPREFIX-mgmt -u glr-local-deploy -m > secrets.auto.tfvars
./create_service_account -s SPACEPREFIX-mgmt -u glr-local-deploy > secrets.auto.tfvars
```
1. Copy `vars.tfvars-example` to `vars.auto.tfvars`.
Expand Down
20 changes: 12 additions & 8 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,16 @@ locals {

# gitlab-runner-manager: the actual runner manager app
resource "cloudfoundry_app" "gitlab-runner-manager" {
provider = cloudfoundry-community
name = var.runner_manager_app_name
space = module.manager_space.space_id
space_name = module.manager_space.space_name
org_name = var.cf_org_name
path = data.archive_file.src.output_path
source_code_hash = data.archive_file.src.output_base64sha256
buildpacks = ["https://github.com/cloudfoundry/apt-buildpack", "binary_buildpack"]
instances = var.manager_instances
strategy = "rolling"
command = "gitlab-runner run"
no_route = true
memory = var.manager_memory
health_check_type = "process"

Expand Down Expand Up @@ -122,12 +124,14 @@ resource "cloudfoundry_app" "gitlab-runner-manager" {
DOCKER_HUB_USER = var.docker_hub_user
DOCKER_HUB_TOKEN = var.docker_hub_token
}
service_binding {
service_instance = module.object_store_instance.bucket_id
}
service_binding {
service_instance = cloudfoundry_service_instance.egress-proxy-credentials.id
}
service_bindings = [
{ service_instance = var.object_store_instance },
{ service_instance = cloudfoundry_service_instance.egress-proxy-credentials.name }
]
depends_on = [
module.object_store_instance,
cloudfoundry_service_instance.egress-proxy-credentials
]
}

# egress_space: cloud.gov space for running the egress proxy
Expand Down
33 changes: 12 additions & 21 deletions sandbox-deploy/create_service_account.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,17 @@ $0: Create a Service User Account for a given space
Usage:
$0 -h
$0 -s <SPACE NAME> -u <USER NAME> [-r <ROLE NAME>] [-o <ORG NAME>] [-m]
$0 -s <SPACE NAME> -u <USER NAME> [-r <ROLE NAME>] [-o <ORG NAME>]
Options:
-h: show help and exit
-s <SPACE NAME>: configure the space to act on. Required
-u <USER NAME>: set the service user name. Required
-r <ROLE NAME>: set the service user's role to either space-deployer or space-auditor. Default: space-deployer
-m: If provided, make the service user an OrgManager
-o <ORG NAME>: configure the organization to act on. Default: $org
Notes:
* OrgManager is required for terraform to create <env>-egress spaces
* Will make the service account an OrgManager in order to create spaces
* Requires cf-cli@8 & jq
"

Expand All @@ -35,10 +34,8 @@ set -o pipefail
space=""
service=""
role="space-deployer"
org_manager="false"
org_manager_output=""

while getopts ":hms:u:r:o:" opt; do
while getopts ":hs:u:r:o:" opt; do
case "$opt" in
s)
space=${OPTARG}
Expand All @@ -52,41 +49,35 @@ while getopts ":hms:u:r:o:" opt; do
o)
org=${OPTARG}
;;
m)
org_manager_output="-m"
org_manager="true"
;;
h)
echo "$usage"
exit 0
;;
esac
done

if [[ $space = "" || $service = "" ]]; then
if [[ -z "$space" || -z "$service" ]]; then
echo "$usage" >&2
exit 1
fi

cf target -o $org -s $space >&2
cf target -o "$org" -s "$space" >&2

# create user account service
cf create-service cloud-gov-service-account $role $service >&2
cf create-service cloud-gov-service-account "$role" "$service" >&2

# create service key
cf create-service-key $service service-account-key >&2
cf create-service-key "$service" service-account-key >&2

# output service key to stdout in secrets.auto.tfvars format
creds=`cf service-key $service service-account-key | tail -n +2 | jq '.credentials'`
username=`echo $creds | jq -r '.username'`
password=`echo $creds | jq -r '.password'`
creds=`cf service-key "$service" service-account-key | tail -n +2 | jq '.credentials'`
username=`echo "$creds" | jq -r '.username'`
password=`echo "$creds" | jq -r '.password'`

if [[ $org_manager = "true" ]]; then
cf set-org-role $username $org OrgManager >&2
fi
cf set-org-role "$username" "$org" OrgManager >&2

cat << EOF
# generated with $0 -s $space -u $service -r $role -o $org $org_manager_output
# generated with $0 -s $space -u $service -r $role -o $org
# revoke with $(dirname $0)/destroy_service_account.sh -s $space -u $service -o $org
cf_user = "$username"
Expand Down
6 changes: 3 additions & 3 deletions sandbox-deploy/destroy_service_account.sh
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,12 @@ while getopts ":hs:u:o:" opt; do
esac
done

if [[ $space = "" || $service = "" ]]; then
if [[ -z "$space" || -z "$service" ]]; then
echo "$usage"
exit 1
fi

cf target -o $org -s $space
cf target -o "$org" -s "$space"

# destroy service
cf delete-service $service -f
cf delete-service -f "$service"
6 changes: 3 additions & 3 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ variable "runner_concurrency" {
}

variable "manager_memory" {
type = number
default = 512
description = "Manager Runner Memory, given as number of megabytes"
type = string
default = "256M"
description = "Manager Runner Memory - Unit required (e.g. 512M or 2G)"
}

variable "worker_memory" {
Expand Down

0 comments on commit 3bbe67c

Please sign in to comment.