# Error: Cannot modify VpcID parameter(s) for a target group

**URL:** <https://forum.ansible.com/t/error-cannot-modify-vpcid-parameter-s-for-a-target-group/3570>\
**Category:** Get Help\
**Tags:** playbook, aws, collections\
**Created:** [February 1, 2024, 7:44pm UTC](https://forum.ansible.com/t/error-cannot-modify-vpcid-parameter-s-for-a-target-group/3570 "2024-02-01T19:44:11Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![FLBob](https://avatars.discourse-cdn.com/v4/letter/f/2acd7d/32.png) [@FLBob](https://forum.ansible.com/u/FLBob)\
**Post date:** [February 1, 2024, 7:44pm UTC](https://forum.ansible.com/t/error-cannot-modify-vpcid-parameter-s-for-a-target-group/3570/1 "2024-02-01T19:44:11Z")

</div>

I create a VPC:

- name: Create Customer VPC  
ec2\_vpc\_net:  
aws\_access\_key: “{{ aws\_access\_key }}”  
aws\_secret\_key: “{{ aws\_secret\_key }}”  
name: “{{ vpc\_name }}”  
cidr\_block: “{{ vpc\_cidr\_block }}”  
region: “{{ region }}”
# enable dns support
dns\_support: yes
# enable dns hostnames
dns\_hostnames: yes  
tenancy: default  
state: present  
register: ec2\_vpc\_net\_result

I add subnets and some instances in this vpc. My issue is creating a target group as follows:

- name: Create Target Group  
community.aws.elb\_target\_group:  
name: “{{ cust }}-target-group”  
protocol: http  
port: 80  
vpc\_id: “{{ ec2\_vpc\_net\_result.vpc.id }}”  
targets:  
- Id: “{{ app\_result.instance\_ids[0] }}”  
Port: 80  
state: present  
modify\_targets: false  
region: “{{ region }}”  
health\_check\_protocol: http  
health\_check\_path: /  
aws\_access\_key: “{{ aws\_access\_key }}”  
aws\_secret\_key: “{{ aws\_secret\_key }}”  
wait\_timeout: 200  
wait: true

It errors with “Cannot modify VpcID parameter(s) for a target group”. I cannot find any documentation on this error or it’s cause. I also get the error if I remove the entire vpc\_id line from the playbook.

Looking for any guidance on this error.

---

<div class="post-metadata">

**Author:** ![jrglynn2](https://avatars.discourse-cdn.com/v4/letter/j/94ad74/32.png) [@jrglynn2](https://forum.ansible.com/u/jrglynn2)\
**Post date:** [February 1, 2024, 8:33pm UTC](https://forum.ansible.com/t/error-cannot-modify-vpcid-parameter-s-for-a-target-group/3570/2 "2024-02-01T20:33:12Z")

</div>

Your indentation is bad, but I will assume it is a copy/paste issue.

Have you tried hard-coding the VPC ID in and see if it works? Something like `vpc_id: vpc-01234567`

That would show whether the issue is with the variable or something else.

Also, using `-vvv` when running the playbook might show you more information.

---

<div class="post-metadata">

**Author:** ![shertel](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/shertel/32/1241_2.png) [@shertel](https://forum.ansible.com/u/shertel)\
**Post date:** [February 1, 2024, 8:46pm UTC](https://forum.ansible.com/t/error-cannot-modify-vpcid-parameter-s-for-a-target-group/3570/3 "2024-02-01T20:46:30Z")

</div>

> [@FLBob](#):
>
> Cannot modify VpcID parameter(s) for a target group

I don’t think a target group’s VPC can be modified without deleting and recreating the target group. [ModifyTargetGroup - Elastic Load Balancing](https://docs.aws.amazon.com/elasticloadbalancing/latest/APIReference/API_ModifyTargetGroup.html)

---

<div class="post-metadata">

**Author:** ![FLBob](https://avatars.discourse-cdn.com/v4/letter/f/2acd7d/32.png) [@FLBob](https://forum.ansible.com/u/FLBob)\
**Post date:** [February 1, 2024, 8:53pm UTC](https://forum.ansible.com/t/error-cannot-modify-vpcid-parameter-s-for-a-target-group/3570/4 "2024-02-01T20:53:59Z")

</div>

Yes, it is a copy/paste issue.

I tried hard-coding the VPC ID and also running it with -vvv. No difference when I hard code and -vvv gave me no more information to go on. Also, I tried commenting out the VPC ID line in the play and the error still occurs and fails.

---

<div class="post-metadata">

**Author:** ![FLBob](https://avatars.discourse-cdn.com/v4/letter/f/2acd7d/32.png) [@FLBob](https://forum.ansible.com/u/FLBob)\
**Post date:** [February 1, 2024, 9:15pm UTC](https://forum.ansible.com/t/error-cannot-modify-vpcid-parameter-s-for-a-target-group/3570/5 "2024-02-01T21:15:20Z")

</div>

That was exactly the issue!! In testing this over and over I was deleting the vpc and all of it’s components, EXCEPT that it wasn’t deleting the target group, so ansible thought I was trying to modify the existing one. Once I manually deleted it and ran the playbook I get past this error. Thank You!!!
