-
Notifications
You must be signed in to change notification settings - Fork 23
AAP-46310 Add aap_organization data source with name/id lookup support #107
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
Open
arrestle
wants to merge
27
commits into
ansible:main
Choose a base branch
from
arrestle:organization-data-source
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 24 commits
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
652f22f
first draft replacement of pr#90
arrestle a24e452
fix ReturnAAPNamedURL to not use null ids that are not promised.
arrestle 3029dbe
This is more accurate
arrestle c082607
update env hints
arrestle 6cac4f1
change id to name
arrestle b4e5cd3
lint
arrestle fd3c1d6
simplify utils.go remove env.sh
arrestle 05efbbd
simplify ReturnAAPNamedURL
arrestle 3dfd9d5
keep pulling in files
arrestle 27d94c0
Running Acceptance Tests
arrestle 1c3057c
docs
arrestle 47f28c4
missed checking for the randomInventoryName after creation
arrestle b6b0cda
add CheckDestroy
arrestle 2dfa645
Merge remote-tracking branch 'upstream/main' into organization-data-s…
arrestle bb7fb3f
Release prep for v1.3.0-prerelease (#109)
davemulford 640d7c0
Add text about linking workflow template to an organization and updat…
davemulford d362374
Merge branch 'organization-data-source' of github.com:arrestle/terraf…
arrestle a3a3a7c
merge fix for terraform plan with variables
arrestle 42d4d6a
AAP_TEST_ORGANIZATION_ID needs to maatch Non-Default Org
arrestle f2af347
remove unnecc. computes
arrestle e135626
docs
arrestle 19d5ef3
Update internal/provider/acceptance_test.go
arrestle 429a7b8
rename file
arrestle 8e9e40f
fix function name. clean up.
arrestle 4134159
fix base_datasource to not allow name instead of id, doesn't apply to…
arrestle 079eb85
override ConfigValidator for organization_data_source
arrestle be2e879
refactor and test CreateNamedURL
arrestle File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
--- | ||
page_title: "aap_organization Data Source - terraform-provider-aap" | ||
description: |- | ||
Get an existing Organization. | ||
--- | ||
|
||
# aap_organization (Data Source) | ||
|
||
Get an existing Organization. | ||
|
||
|
||
## Example Usage | ||
|
||
```terraform | ||
terraform { | ||
required_providers { | ||
aap = { | ||
source = "ansible/aap" | ||
} | ||
} | ||
} | ||
|
||
provider "aap" { | ||
host = "https://AAP_HOST" | ||
username = "ansible" | ||
password = "test123!" | ||
} | ||
|
||
# You can look up Organizations by using either the `id` or their `name`. | ||
|
||
# Look up organization by ID | ||
data "aap_organization" "sample_by_id" { | ||
id = 7 | ||
} | ||
|
||
output "organization_with_id" { | ||
value = data.aap_organization.sample_by_id | ||
} | ||
|
||
# Look up organization by name - this is the main use case for this data source | ||
data "aap_organization" "sample_by_name" { | ||
name = "Default" | ||
} | ||
|
||
output "organization_with_name" { | ||
value = data.aap_organization.sample_by_name | ||
} | ||
|
||
# Example: Using the organization data source with an inventory resource | ||
# This shows how to create an inventory in a specific organization by name | ||
# instead of hard-coding the organization ID | ||
resource "aap_inventory" "example" { | ||
name = "My Inventory" | ||
organization = data.aap_organization.sample_by_name.id | ||
description = "An inventory created using the organization data source" | ||
} | ||
``` | ||
|
||
|
||
<!-- schema generated by tfplugindocs --> | ||
## Schema | ||
|
||
### Optional | ||
|
||
- `id` (Number) Organization id | ||
- `name` (String) Name of the Organization | ||
|
||
### Read-Only | ||
|
||
- `description` (String) Description of the Organization | ||
- `named_url` (String) The Named Url of the Organization | ||
- `url` (String) Url of the Organization | ||
- `variables` (String, Deprecated) Variables of the Organization. Will be either JSON or YAML string depending on how the variables were entered into AAP. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
terraform { | ||
required_providers { | ||
aap = { | ||
source = "ansible/aap" | ||
} | ||
} | ||
} | ||
|
||
provider "aap" { | ||
host = "https://AAP_HOST" | ||
username = "ansible" | ||
password = "test123!" | ||
} | ||
|
||
# You can look up Organizations by using either the `id` or their `name`. | ||
|
||
# Look up organization by ID | ||
data "aap_organization" "sample_by_id" { | ||
id = 7 | ||
} | ||
|
||
output "organization_with_id" { | ||
value = data.aap_organization.sample_by_id | ||
} | ||
|
||
# Look up organization by name - this is the main use case for this data source | ||
data "aap_organization" "sample_by_name" { | ||
name = "Default" | ||
} | ||
|
||
output "organization_with_name" { | ||
value = data.aap_organization.sample_by_name | ||
} | ||
|
||
# Example: Using the organization data source with an inventory resource | ||
# This shows how to create an inventory in a specific organization by name | ||
# instead of hard-coding the organization ID | ||
resource "aap_inventory" "example" { | ||
name = "My Inventory" | ||
organization = data.aap_organization.sample_by_name.id | ||
description = "An inventory created using the organization data source" | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package provider | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform-plugin-testing/helper/acctest" | ||
"github.com/hashicorp/terraform-plugin-testing/helper/resource" | ||
) | ||
|
||
func TestAccInventoryResourceWithOrganizationDataSource(t *testing.T) { | ||
randomInventoryName := acctest.RandStringFromCharSet(10, acctest.CharSetAlphaNum) | ||
|
||
resource.Test(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, | ||
CheckDestroy: testAccCheckInventoryResourceDestroy, | ||
Steps: []resource.TestStep{ | ||
// Create an inventory using the organization data source | ||
{ | ||
Config: createOrganizationAndInventory("Default", randomInventoryName), | ||
Check: resource.ComposeAggregateTestCheckFunc( | ||
resource.TestCheckResourceAttr("data.aap_organization.default_org", "id", "1"), | ||
resource.TestCheckResourceAttr("data.aap_organization.default_org", "name", "Default"), | ||
resource.TestCheckResourceAttr("data.aap_organization.default_org", "description", "The default organization for Ansible Automation Platform"), | ||
resource.TestCheckResourceAttr("aap_inventory.new_inventory", "name", randomInventoryName), | ||
resource.TestCheckResourceAttr("data.aap_inventory.the_created_inventory", "name", randomInventoryName), | ||
resource.TestCheckResourceAttrPair("aap_inventory.new_inventory", "organization", "data.aap_inventory.the_created_inventory", "organization"), | ||
resource.TestCheckResourceAttrPair("aap_inventory.new_inventory", "description", "data.aap_inventory.the_created_inventory", "description"), | ||
resource.TestCheckResourceAttrPair("aap_inventory.new_inventory", "variables", "data.aap_inventory.the_created_inventory", "variables"), | ||
resource.TestCheckResourceAttrPair("aap_inventory.new_inventory", "url", "data.aap_inventory.the_created_inventory", "url"), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func createOrganizationAndInventory(organizationName string, inventoryName string) string { | ||
return fmt.Sprintf(` | ||
data "aap_organization" "default_org" { | ||
name = "%s" | ||
} | ||
|
||
resource "aap_inventory" "new_inventory" { | ||
name = "%s" | ||
organization = data.aap_organization.default_org.id | ||
description = "A test inventory" | ||
} | ||
|
||
data "aap_inventory" "the_created_inventory" { | ||
id = aap_inventory.new_inventory.id | ||
} | ||
`, organizationName, inventoryName) | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package provider | ||
|
||
import ( | ||
"github.com/hashicorp/terraform-plugin-framework/datasource" | ||
) | ||
|
||
// Organization AAP API model | ||
type OrganizationAPIModel struct { | ||
BaseDetailAPIModel | ||
} | ||
|
||
// OrganizationDataSourceModel maps the data source schema data. | ||
type OrganizationDataSourceModel struct { | ||
BaseDetailSourceModel | ||
} | ||
|
||
// OrganizationDataSource is the data source implementation. | ||
type OrganizationDataSource struct { | ||
BaseDataSource | ||
} | ||
|
||
// NewOrganizationDataSource is a helper function to simplify the provider implementation. | ||
func NewOrganizationDataSource() datasource.DataSource { | ||
return &OrganizationDataSource{ | ||
BaseDataSource: *NewBaseDataSource(nil, StringDescriptions{ | ||
MetadataEntitySlug: "organization", | ||
DescriptiveEntityName: "Organization", | ||
ApiEntitySlug: "organizations", | ||
}), | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.