Skip to content

Conversation

@adambarreiro
Copy link
Contributor

@adambarreiro adambarreiro commented Jan 29, 2025

Add vcfa_api_token resource, used to create API Tokens in VCFA. It works similarly to the VCD resource.

How to test manually:

terraform {
  required_providers {
    vcfa = {
      source  = "vmware/vcfa"
      version = "= 0.1.0"
    }
  }
}

# ------------------------------------
# Regular
# ------------------------------------

provider "vcfa" {
  user                 = "serviceadministrator"
  password             = "*******"
  token                = ""
  api_token            = ""
  auth_type            = "integrated"
  url                  = "https://vcfaUrl/tm/api"
  sysorg               = "System"
  org                  = "System"
  allow_unverified_ssl = "true"
  logging              = true
  logging_file         = "go-vcloud-director.log"
}

resource "vcfa_api_token" "custom" {
  name = "token1"		

  file_name        = "token1"
  allow_token_file = true
}

# ------------------------------------
# API Token
# ------------------------------------

provider "vcfa" {
  alias = "token"
  auth_type            = "api_token"
  api_token            = jsondecode(file(vcfa_api_token.custom.file_name))["refresh_token"]
  sysorg               = "System"
  org                  = "System"
  url                  = "https://vcfaUrl/tm/api"
  allow_unverified_ssl = "true"
  logging              = true
  logging_file         = "go-vcloud-director-2.log"
}

data "vcfa_org" "org" {
  provider = vcfa.token
  name = "tenant1"
}

output "org_id" {
  value = data.vcfa_org.org.id
}

# ------------------------------------
# API Token file
# ------------------------------------

provider "vcfa" {
  alias = "token2"
  auth_type            = "api_token_file"
  allow_api_token_file = true
  api_token_file       = vcfa_api_token.custom.file_name
  sysorg               = "System"
  org                  = "System"
  url                  = "https://vcfaUrl/tm/api"
  allow_unverified_ssl = "true"
  logging              = true
  logging_file         = "go-vcloud-director-3.log"
}

data "vcfa_org" "org2" {
  provider = vcfa.token2
  name = "tenant1"
}

output "org_id2" {
  value = data.vcfa_org.org2.id
}

Signed-off-by: abarreiro <[email protected]>
@adambarreiro adambarreiro self-assigned this Jan 29, 2025
abarreiro added 4 commits January 29, 2025 09:56
#
Signed-off-by: abarreiro <[email protected]>
#
Signed-off-by: abarreiro <[email protected]>
#
Signed-off-by: abarreiro <[email protected]>
#
Signed-off-by: abarreiro <[email protected]>
@adambarreiro adambarreiro marked this pull request as ready for review January 29, 2025 09:23
abarreiro added 2 commits January 29, 2025 10:43
Signed-off-by: abarreiro <[email protected]>
Signed-off-by: abarreiro <[email protected]>
Copy link

@lvirbalas lvirbalas left a comment

Choose a reason for hiding this comment

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

One user-facing suggestion inline.

abarreiro added 3 commits January 29, 2025 14:09
#
Signed-off-by: abarreiro <[email protected]>
#
Signed-off-by: abarreiro <[email protected]>
#
Signed-off-by: abarreiro <[email protected]>
#
Signed-off-by: abarreiro <[email protected]>
@adambarreiro adambarreiro merged commit 1a18e90 into vmware:main Jan 29, 2025
2 checks passed
@adambarreiro adambarreiro deleted the api-token branch January 29, 2025 15:15
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.

3 participants