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

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.

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.

I don’t think a target group’s VPC can be modified without deleting and recreating the target group. ModifyTargetGroup - Elastic Load Balancing

1 Like

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.

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!!!

1 Like