terraform-aws-gitlab-runner icon indicating copy to clipboard operation
terraform-aws-gitlab-runner copied to clipboard

creating IAM policy XXX-service_linked_role: EntityAlreadyExists when changing the module name

Open allan-simon opened this issue 6 years ago • 2 comments

I've recently updated our modufle configuration to change the terraform ressource name

from

module "runner_c5_xlarge_eu_west_3_b" {                                                                                                                                                       
  source  = "npalm/gitlab-runner/aws"                                                                                                                                                        
  version = "4.1.0"                                                                                                                                                                          
                                                                                                                                                                                             
  aws_region = "eu-west-3"                                                                                                                                                                   
  aws_zone   = "b"                                                                                                                                                                           
                                                                                                                                                                                             
  # Here we set a different environment than the previous (and other runner modules)                                                                                                         
  # because every resource created by this module is indexed by this variable                                                                                                                
  # so in order not to have name conflicts, we need a different environment for                                                                                                              
  # each runner                                                                                                                                                                              
  environment = "Service-4"        
  ....
}

to

module "runner_c5_large_eu_west_3_b" {                                                                                                                                                       

(only the module name as changed)

when running the apply we got

Error: Error import KeyPair: InvalidKeyPair.Duplicate: The keypair 'Service-4-gitlab-runner' already exists.
	status code: 400, request id: f132a471-57ea-4106-97bb-5e8beb85a0a5

  on .terraform/modules/runner_c5_large_eu_west_3_b/npalm-terraform-aws-gitlab-runner-31b0bab/main.tf line 1, in resource "aws_key_pair" "key":
   1: resource "aws_key_pair" "key" {



Error: Error creating IAM Role Service-4-instance-role: EntityAlreadyExists: Role with name Service-4-instance-role already exists.
	status code: 409, request id: cbb8b28e-ca34-11e9-b038-abe555558e62

  on .terraform/modules/runner_c5_large_eu_west_3_b/npalm-terraform-aws-gitlab-runner-31b0bab/main.tf line 288, in resource "aws_iam_role" "instance":
 288: resource "aws_iam_role" "instance" {



Error: Error creating IAM policy Service-4-docker-machine: EntityAlreadyExists: A policy called Service-4-docker-machine already exists. Duplicate names are not allowed.
	status code: 409, request id: ca24f337-ca34-11e9-aaa5-3d97689ee397

  on .terraform/modules/runner_c5_large_eu_west_3_b/npalm-terraform-aws-gitlab-runner-31b0bab/main.tf line 302, in resource "aws_iam_policy" "instance_docker_machine_policy":
 302: resource "aws_iam_policy" "instance_docker_machine_policy" {



Error: Error creating IAM Role Service-4-docker-machine-role: EntityAlreadyExists: Role with name Service-4-docker-machine-role already exists.
	status code: 409, request id: cc06365f-ca34-11e9-ae4f-bb716bff761d

  on .terraform/modules/runner_c5_large_eu_west_3_b/npalm-terraform-aws-gitlab-runner-31b0bab/main.tf line 331, in resource "aws_iam_role" "docker_machine":
 331: resource "aws_iam_role" "docker_machine" {

I guess it happens because of a ordering problem in the order the resources are deleted / recreated ?

allan-simon avatar Aug 29 '19 08:08 allan-simon

doing a plan + apply, once again solved the problem....

allan-simon avatar Aug 29 '19 09:08 allan-simon

@allan-simon thank you for creating the issue. In case I rename a module I perform normally a terraform state mv so no side effects are caused.

But indeed the rename of a module does not work as expected.

npalm avatar Sep 02 '19 18:09 npalm

Related to #591

kayman-mk avatar Jan 01 '23 19:01 kayman-mk