Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fail when both network_id & vpc_id are set in ipaddress #99

Merged
merged 3 commits into from
Mar 14, 2024

Conversation

vishesh92
Copy link
Member

Fixes #32

@vishesh92 vishesh92 marked this pull request as ready for review March 13, 2024 14:05
@rohityadavcloud rohityadavcloud added this to the v0.5.0 milestone Mar 14, 2024
Copy link
Member

@rohityadavcloud rohityadavcloud left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lgtm but needs testing

Copy link
Collaborator

@kiranchavala kiranchavala left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vishesh92

The network_id is still not saved in the tfstate

      "provider": "provider[\"localdomain/provider/cloudstack\"]",
      "instances": [
        {
          "schema_version": 0,
          "attributes": {
            "id": "31cd2075-41a4-4c88-a625-8b1af213026a",
            "ip_address": "10.0.57.165",
            "is_portable": false,
            "is_source_nat": false,
            "network_id": "",
            "project": "ed04078f-dd1e-471d-8c3d-5fb8554a0c8a",
            "tags": {},
            "vpc_id": "d12f2b16-03d2-404c-9627-808ad0d73317",
            "zone": "49e9ad34-8a3d-4f87-8ff5-90d65859f839"
          },
          "sensitive_attributes": [],
          "private": "bnVsbA=="
        }
  # cloudstack_ipaddress.galaxy_public_ip must be replaced
-/+ resource "cloudstack_ipaddress" "galaxy_public_ip" {
      ~ id            = "31cd2075-41a4-4c88-a625-8b1af213026a" -> (known after apply)
      ~ ip_address    = "10.0.57.165" -> (known after apply)
      ~ is_source_nat = false -> (known after apply)
      + network_id    = "d7617062-4305-4740-8581-a704cc9ec9e0" # forces replacement
      ~ tags          = {} -> (known after apply)
        # (4 unchanged attributes hidden)

Copy link
Collaborator

@kiranchavala kiranchavala left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vishesh92

When I provide both network_id and vpc_id and do terraform apply

cloudstack_ipaddress.galaxy_public_ip: Creating...
╷
│ Error: set only network_id or vpc_id

When i provide only network id

cloudstack_ipaddress.galaxy_public_ip: Creating...
╷
│ Error: Error associating a new IP address: Undefined error: {"errorcode":431,"errortext":"Can't assign ip to the network directly when network belongs to VPC.Specify vpcId to associate ip address to VPC"}
│ 
│   with cloudstack_ipaddress.galaxy_public_ip,
│   on main.tf line 8, in resource "cloudstack_ipaddress" "galaxy_public_ip":
│    8: resource "cloudstack_ipaddress" "galaxy_public_ip" {

When i provide only vpc_id no issues

cloudstack_ipaddress.galaxy_public_ip: Creating...
cloudstack_ipaddress.galaxy_public_ip: Creation complete after 1s [id=06ba3a09-f315-45cc-86b9-ec2a000965d2]

      "instances": [
        {
          "schema_version": 0,
          "attributes": {
            "id": "06ba3a09-f315-45cc-86b9-ec2a000965d2",
            "ip_address": "10.0.57.174",
            "is_portable": false,
            "is_source_nat": false,
            "network_id": null,
            "project": "ed04078f-dd1e-471d-8c3d-5fb8554a0c8a",
            "tags": {},
            "vpc_id": "ab9fc295-0bcc-4a2f-85a9-b98625e02b1d",
            "zone": "49e9ad34-8a3d-4f87-8ff5-90d65859f839"
          },
          "sensitive_attributes": []
        }
      ]
      

When i provide the network id of a isolated network it's working fine and tf state contains the network id.

cloudstack_ipaddress.galaxy_public_ip: Creating...
cloudstack_ipaddress.galaxy_public_ip: Creation complete after 1s [id=11788a4d-7fb5-48cd-a009-c89b0b309a07]
 "instances": [
        {
          "schema_version": 0,
          "attributes": {
            "id": "11788a4d-7fb5-48cd-a009-c89b0b309a07",
            "ip_address": "10.0.57.168",
            "is_portable": false,
            "is_source_nat": true,
            "network_id": "93f804b6-1e2b-4969-bbf8-244c93df11e2",
            "project": "ed04078f-dd1e-471d-8c3d-5fb8554a0c8a",
            "tags": {},
            "vpc_id": null,
            "zone": "49e9ad34-8a3d-4f87-8ff5-90d65859f839"
          },
          "sensitive_attributes": [],
          "private": "bnVsbA=="
        }

Do a terraform apply again , this time there is no change detacted

cloudstack_ipaddress.galaxy_public_ip: Refreshing state... [id=11788a4d-7fb5-48cd-a009-c89b0b309a07]

No changes. Your infrastructure matches the configuration.

Terraform has compared your real infrastructure against your configuration and found no differences, so no changes are needed.

Apply complete! Resources: 0 added, 0 changed, 0 destroyed.

@vishesh92 vishesh92 changed the title Fixup network_id in ipaddress when vpc_id is specified Fail when both network_id & vpc_id are set in ipaddress Mar 14, 2024
@vishesh92 vishesh92 merged commit 348253d into apache:main Mar 14, 2024
4 checks passed
@vishesh92 vishesh92 deleted the fixup-ipaddress-network-id branch March 14, 2024 11:55
@klaussilveira
Copy link

klaussilveira commented Jun 6, 2024

Why was this necessary, though @vishesh92? Is it implied that when using a network, it'll use the ID of the VPC that the network belongs to?

What about the following scenario:

Error: Error associating a new IP address: Undefined error: {"errorcode":431,"errortext":"Can't assign ip to the network directly when network belongs to VPC.Specify vpcId to associate ip address to VPC"}

Maybe a comment outlining this could be useful. I'm glad to add it if y'all agree that my statement is correct.

@vishesh92
Copy link
Member Author

Why was this necessary, though @vishesh92? Is it implied that when using a network, it'll use the ID of the VPC that the network belongs to?

What about the following scenario:

Error: Error associating a new IP address: Undefined error: {"errorcode":431,"errortext":"Can't assign ip to the network directly when network belongs to VPC.Specify vpcId to associate ip address to VPC"}

Maybe a comment outlining this could be useful. I'm glad to add it if y'all agree that my statement is correct.

@klaussilveira Yes. Public IPs get assigned to the VPC itself, which is the parent of its network tiers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

network_id remains empty after creating IP address resource
4 participants