Skip to content

Commit

Permalink
fix: remove the null resource (#441)
Browse files Browse the repository at this point in the history
* remove the null resource

* amend the docs to not forget to remove the runner manually
  • Loading branch information
kayman-mk authored Feb 27, 2022
1 parent a596aa8 commit 3037c54
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 30 deletions.
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,9 @@ module "runner" {
}
```

### Removing the module

Remove the module from your Terraform code and deregister the runner manually from your Gitlab instance.
### Scenario: Multi-region deployment

Name clashes due to multi-region deployments for global AWS ressources create by this module (IAM, S3) can be avoided by including a distinguishing region specific prefix via the _cache_bucket_prefix_ string respectively via _name_iam_objects_ in the _overrides_ map. A simple example for this would be to set _region-specific-prefix_ to the AWS region the module is deployed to.
Expand Down Expand Up @@ -252,18 +255,18 @@ module "runner" {
run_untagged = "false"
maximum_timeout = "3600"
}
overrides = {
name_iam_objects = "<region-specific-prefix>-gitlab-runner-iam"
}
cache_bucket_prefix = "<region-specific-prefix>"
}
```

## Examples

A few [examples](https://github.com/npalm/terraform-aws-gitlab-runner/tree/develop/examples/) are provided. Use the following steps to deploy. Ensure your AWS and Terraform environment is set up correctly. All commands below should be run from the `terraform-aws-gitlab-runner/examples/<example-dir>` directory.
A few [examples](https://github.com/npalm/terraform-aws-gitlab-runner/tree/develop/examples/) are provided. Use the following steps to deploy. Ensure your AWS and Terraform environment is set up correctly. All commands below should be run from the `terraform-aws-gitlab-runner/examples/<example-dir>` directory. Don't forget to remove the runners manually from your Gitlab instance as soon as your are done.

### SSH keys

Expand Down Expand Up @@ -307,8 +310,7 @@ terraform destroy

| Name | Version |
|------|---------|
| <a name="provider_aws"></a> [aws](#provider\_aws) | ~> 3.35 |
| <a name="provider_null"></a> [null](#provider\_null) | n/a |
| <a name="provider_aws"></a> [aws](#provider\_aws) | 3.71.0 |

## Modules

Expand Down Expand Up @@ -360,12 +362,10 @@ terraform destroy
| [aws_security_group_rule.runner_ping_group](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/security_group_rule) | resource |
| [aws_ssm_parameter.runner_registration_token](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/ssm_parameter) | resource |
| [aws_ssm_parameter.runner_sentry_dsn](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/ssm_parameter) | resource |
| [null_resource.remove_runner](https://registry.terraform.io/providers/hashicorp/null/latest/docs/resources/resource) | resource |
| [aws_ami.docker-machine](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/ami) | data source |
| [aws_ami.runner](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/ami) | data source |
| [aws_availability_zone.runners](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/availability_zone) | data source |
| [aws_caller_identity.current](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/caller_identity) | data source |
| [aws_ssm_parameter.current_runner_registration_token](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/ssm_parameter) | data source |
| [aws_subnet.runners](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/subnet) | data source |

## Inputs
Expand Down
23 changes: 0 additions & 23 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -21,29 +21,6 @@ resource "aws_ssm_parameter" "runner_registration_token" {
}
}

# to read the current token for the null_resource. aws_ssm_parameter.runner_registration_token.value is never updated!
data "aws_ssm_parameter" "current_runner_registration_token" {
depends_on = [aws_ssm_parameter.runner_registration_token]

name = local.secure_parameter_store_runner_token_key
}

resource "null_resource" "remove_runner" {
depends_on = [aws_ssm_parameter.runner_registration_token]

triggers = {
aws_region = var.aws_region
runners_gitlab_url = var.runners_gitlab_url
runner_registration_token = data.aws_ssm_parameter.current_runner_registration_token.value
}

provisioner "local-exec" {
when = destroy
on_failure = continue
command = "curl -sS --request DELETE \"${self.triggers.runners_gitlab_url}/api/v4/runners\" --form \"token=${self.triggers.runner_registration_token}\""
}
}

resource "aws_ssm_parameter" "runner_sentry_dsn" {
name = local.secure_parameter_store_runner_sentry_dsn
type = "SecureString"
Expand Down

0 comments on commit 3037c54

Please sign in to comment.