Skip to content

Commit 3dfd9d5

Browse files
committed
keep pulling in files
1 parent 05efbbd commit 3dfd9d5

File tree

3 files changed

+147
-0
lines changed

3 files changed

+147
-0
lines changed

docs/data-sources/organization.md

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
---
2+
page_title: "aap_organization Data Source - terraform-provider-aap"
3+
description: |-
4+
Get an existing Organization.
5+
---
6+
7+
# aap_organization (Data Source)
8+
9+
Get an existing Organization.
10+
11+
12+
## Example Usage
13+
14+
```terraform
15+
terraform {
16+
required_providers {
17+
aap = {
18+
source = "ansible/aap"
19+
}
20+
}
21+
}
22+
23+
provider "aap" {
24+
host = "https://AAP_HOST"
25+
username = "ansible"
26+
password = "test123!"
27+
}
28+
29+
# You can look up Organizations by using either the `id` or their `name`.
30+
31+
# This example relies on a job template with id 7 that the user has access to.
32+
data "aap_organization" "sample_by_id" {
33+
id = 7
34+
}
35+
36+
output "organization_with_id" {
37+
value = data.aap_organization.sample_by_id
38+
}
39+
40+
data "aap_organization" "sample_with_name_and_org_name" {
41+
name = "Default"
42+
}
43+
44+
output "organization_with_name" {
45+
value = data.aap_organization.sample_with_name_and_org_name
46+
}
47+
```
48+
49+
50+
<!-- schema generated by tfplugindocs -->
51+
## Schema
52+
53+
### Optional
54+
55+
- `id` (Number) Organization id
56+
- `name` (String) Name of the Organization
57+
58+
### Read-Only
59+
60+
- `description` (String) Description of the Organization
61+
- `named_url` (String) The Named Url of the Organization
62+
- `url` (String) Url of the Organization
63+
- `variables` (String, Deprecated) Variables of the Organization. Will be either JSON or YAML string depending on how the variables were entered into AAP.
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
terraform {
2+
required_providers {
3+
aap = {
4+
source = "ansible/aap"
5+
}
6+
}
7+
}
8+
9+
provider "aap" {
10+
host = "https://AAP_HOST"
11+
username = "ansible"
12+
password = "test123!"
13+
}
14+
15+
# You can look up Organizations by using either the `id` or their `name`.
16+
17+
# This example relies on a job template with id 7 that the user has access to.
18+
data "aap_organization" "sample_by_id" {
19+
id = 7
20+
}
21+
22+
output "organization_with_id" {
23+
value = data.aap_organization.sample_by_id
24+
}
25+
26+
data "aap_organization" "sample_with_name_and_org_name" {
27+
name = "Default"
28+
}
29+
30+
output "organization_with_name" {
31+
value = data.aap_organization.sample_with_name_and_org_name
32+
}

internal/provider/acceptance_test.go

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
package provider
2+
3+
import (
4+
"fmt"
5+
"testing"
6+
7+
"github.com/hashicorp/terraform-plugin-testing/helper/acctest"
8+
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
9+
)
10+
11+
func TestAccInventoryResourceWithOrganizationDataSource(t *testing.T) {
12+
randomInventoryName := acctest.RandStringFromCharSet(10, acctest.CharSetAlphaNum)
13+
14+
resource.Test(t, resource.TestCase{
15+
PreCheck: func() { testAccPreCheck(t) },
16+
ProtoV6ProviderFactories: testAccProtoV6ProviderFactories,
17+
Steps: []resource.TestStep{
18+
// Create an inventory using the organization data source
19+
{
20+
Config: createTestAccOrganizationDataSourceNamedUrlCreateInventoryHCL("Default", randomInventoryName),
21+
Check: resource.ComposeAggregateTestCheckFunc(
22+
resource.TestCheckResourceAttr("data.aap_organization.default_org", "id", "1"),
23+
resource.TestCheckResourceAttr("data.aap_organization.default_org", "name", "Default"),
24+
resource.TestCheckResourceAttr("data.aap_organization.default_org", "description", "The default organization for Ansible Automation Platform"),
25+
resource.TestCheckResourceAttrPair("aap_inventory.new_inventory", "name", "data.aap_inventory.the_created_inventory", "name"),
26+
resource.TestCheckResourceAttrPair("aap_inventory.new_inventory", "organization", "data.aap_inventory.the_created_inventory", "organization"),
27+
resource.TestCheckResourceAttrPair("aap_inventory.new_inventory", "description", "data.aap_inventory.the_created_inventory", "description"),
28+
resource.TestCheckResourceAttrPair("aap_inventory.new_inventory", "variables", "data.aap_inventory.the_created_inventory", "variables"),
29+
resource.TestCheckResourceAttrPair("aap_inventory.new_inventory", "url", "data.aap_inventory.the_created_inventory", "url"),
30+
),
31+
},
32+
},
33+
})
34+
}
35+
36+
func createTestAccOrganizationDataSourceNamedUrlCreateInventoryHCL(organizationName string, inventoryName string) string {
37+
return fmt.Sprintf(`
38+
data "aap_organization" "default_org" {
39+
name = "%s"
40+
}
41+
42+
resource "aap_inventory" "new_inventory" {
43+
name = "%s"
44+
organization = data.aap_organization.default_org.id
45+
description = "A test inventory"
46+
}
47+
48+
data "aap_inventory" "the_created_inventory" {
49+
id = aap_inventory.new_inventory.id
50+
}
51+
`, organizationName, inventoryName)
52+
}

0 commit comments

Comments
 (0)