Skip to content

Commit

Permalink
closes issue #36
Browse files Browse the repository at this point in the history
  • Loading branch information
samir-gandhi committed Feb 8, 2023
1 parent 04c3f47 commit 4cc84d7
Show file tree
Hide file tree
Showing 12 changed files with 29 additions and 26 deletions.
5 changes: 3 additions & 2 deletions examples/data-sources/davinci_application/data-source.tf
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
data "davinci_application" "one" {
application_id = "<app_id>"
data "davinci_application" "by_app_id" {
application_id = var.application_id
environment_id = var.environment_id
}

output "davinci_app_one_key" {
Expand Down
1 change: 1 addition & 0 deletions examples/data-sources/davinci_applications/data-source.tf
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
data "davinci_applications" "all" {
environment_id = var.environment_id
}

output "davinci_applications" {
Expand Down
2 changes: 1 addition & 1 deletion examples/resources/davinci_application/resource.tf
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ resource "davinci_application" "use_default_flow" {
name = "PingOne - Sign On and Password Reset"
status = "enabled"
policy_flows {
id = "abc123"
flow_id = var.davinci_flow_id
version_id = -1
weight = 100
}
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ require (
github.com/hashicorp/terraform-plugin-sdk/v2 v2.24.1
github.com/katbyte/terrafmt v0.5.2
github.com/pavius/impi v0.0.3
github.com/samir-gandhi/davinci-client-go v0.0.40
github.com/samir-gandhi/davinci-client-go v0.0.41
github.com/terraform-linters/tflint v0.44.1
)

Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -751,8 +751,8 @@ github.com/ryancurrah/gomodguard v1.3.0 h1:q15RT/pd6UggBXVBuLps8BXRvl5GPBcwVA7BJ
github.com/ryancurrah/gomodguard v1.3.0/go.mod h1:ggBxb3luypPEzqVtq33ee7YSN35V28XeGnid8dnni50=
github.com/ryanrolds/sqlclosecheck v0.4.0 h1:i8SX60Rppc1wRuyQjMciLqIzV3xnoHB7/tXbr6RGYNI=
github.com/ryanrolds/sqlclosecheck v0.4.0/go.mod h1:TBRRjzL31JONc9i4XMinicuo+s+E8yKZ5FN8X3G6CKQ=
github.com/samir-gandhi/davinci-client-go v0.0.40 h1:+f03woaYW5PsEmUqUV4QT+EG51WhPVvWvrRCQ1tboc0=
github.com/samir-gandhi/davinci-client-go v0.0.40/go.mod h1:BuwBLUsGtB91mN6nICnyCIrOmAPitaQ8JFmBaLyldyU=
github.com/samir-gandhi/davinci-client-go v0.0.41 h1:sjTE79K3J7PcFfbDguOiq0q+1eWEp19yeks7IDXI2cU=
github.com/samir-gandhi/davinci-client-go v0.0.41/go.mod h1:BuwBLUsGtB91mN6nICnyCIrOmAPitaQ8JFmBaLyldyU=
github.com/sanposhiho/wastedassign/v2 v2.0.7 h1:J+6nrY4VW+gC9xFzUc+XjPD3g3wF3je/NsJFwFK7Uxc=
github.com/sanposhiho/wastedassign/v2 v2.0.7/go.mod h1:KyZ0MWTwxxBmfwn33zh3k1dmsbF2ud9pAAGfoLfjhtI=
github.com/sashamelentyev/interfacebloat v1.1.0 h1:xdRdJp0irL086OyW1H/RTZTr1h/tMEOsumirXcOJqAw=
Expand Down
1 change: 1 addition & 0 deletions internal/service/davinci/data_source_application_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ func TestAccDatasourceApplication_Slim(t *testing.T) {
Config: hcl,
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrSet(dataSourceFullName, "name"),
resource.TestCheckResourceAttrSet(dataSourceFullName, "id"),
),
},
},
Expand Down
8 changes: 4 additions & 4 deletions internal/service/davinci/data_source_applications.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func DataSourceApplications() *schema.Resource {
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"application_id": {
"id": {
Type: schema.TypeString,
Computed: true,
},
Expand Down Expand Up @@ -276,7 +276,7 @@ func DataSourceApplications() *schema.Resource {
Description: "SAML configuration",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"id": {
"flow_id": {
Type: schema.TypeString,
Computed: true,
},
Expand Down Expand Up @@ -359,6 +359,7 @@ func dataSourceApplicationsRead(ctx context.Context, d *schema.ResourceData, m i
if err != nil {
return diag.FromErr(err)
}
app["id"] = thisApp.AppID
apps[i] = app
}

Expand All @@ -372,7 +373,6 @@ func dataSourceApplicationsRead(ctx context.Context, d *schema.ResourceData, m i

func flattenApp(app *dv.App) (map[string]interface{}, error) {
a := map[string]interface{}{
"application_id": app.AppID,
"environment_id": app.CompanyID,
"customer_id": app.CustomerID,
"name": app.Name,
Expand Down Expand Up @@ -462,7 +462,7 @@ func flattenApp(app *dv.App) (map[string]interface{}, error) {
polFlows := []interface{}{}
for _, w := range v.PolicyFlows {
thisPolFlow := map[string]interface{}{
"id": w.FlowID,
"flow_id": w.FlowID,
"weight": w.Weight,
"version_id": w.VersionID,
}
Expand Down
1 change: 1 addition & 0 deletions internal/service/davinci/data_source_applications_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ func TestAccDataSourceApplications_AllApplications(t *testing.T) {
Config: hcl,
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrSet(dataSourceFullName, "applications.0.environment_id"),
resource.TestCheckResourceAttrSet(dataSourceFullName, "applications.0.id"),
),
},
},
Expand Down
15 changes: 6 additions & 9 deletions internal/service/davinci/resource_application.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,6 @@ func ResourceApplication() *schema.Resource {
Required: true,
Description: "PingOne environment id",
},
"application_id": {
Type: schema.TypeString,
Computed: true,
Description: "DaVinci generated identifier",
},
"customer_id": {
Type: schema.TypeString,
Computed: true,
Expand Down Expand Up @@ -296,7 +291,7 @@ func ResourceApplication() *schema.Resource {
Description: "Weighted flows that this Application will use",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"id": {
"flow_id": {
Type: schema.TypeString,
Optional: true,
},
Expand Down Expand Up @@ -418,6 +413,7 @@ func resourceApplicationRead(ctx context.Context, d *schema.ResourceData, m inte

d.Set(i, v)
}
d.SetId(resp.AppID)
return diags
}

Expand All @@ -429,12 +425,13 @@ func resourceApplicationUpdate(ctx context.Context, d *schema.ResourceData, m in
return diag.FromErr(err)
}

appId := d.Id()

// if a new policy is added it must be created
if d.HasChanges("policies") {
_, new := d.GetChange("policies")
pols := expandFlowPolicies(new)
for _, v := range pols {
appId := d.Get("application_id").(string)
if v.PolicyID == "" {
sdkRes, err := sdk.DoRetryable(ctx, func() (interface{}, error) {
return c.CreateFlowPolicy(&c.CompanyID, appId, v)
Expand Down Expand Up @@ -468,7 +465,7 @@ func resourceApplicationUpdate(ctx context.Context, d *schema.ResourceData, m in
if err != nil {
return diag.FromErr(err)
}
app.AppID = d.Get("application_id").(string)
app.AppID = d.Get("id").(string)

sdkRes, err := sdk.DoRetryable(ctx, func() (interface{}, error) {
return c.UpdateApplication(&c.CompanyID, app)
Expand Down Expand Up @@ -638,7 +635,7 @@ func expandFlowPolicies(fp interface{}) []dv.Policy {
for _, w := range thisPolicyFlows {
flPMap := w.(map[string]interface{})
thisFvPUpdate := dv.PolicyFlow{
FlowID: flPMap["id"].(string),
FlowID: flPMap["flow_id"].(string),
VersionID: flPMap["version_id"].(int),
Weight: flPMap["weight"].(int),
}
Expand Down
14 changes: 8 additions & 6 deletions internal/service/davinci/resource_application_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ func TestAccResourceApplication_Slim(t *testing.T) {
Config: hcl,
Check: resource.ComposeTestCheckFunc(
//TODO - test attributes in TypeSet.
resource.TestCheckResourceAttrSet(resourceFullName, "application_id"),
resource.TestCheckResourceAttrSet(resourceFullName, "id"),
// resource.TestCheckNoResourceAttr(resourceFullName, "application_id"),
// TODO - use this on integrated acc test
// resource.TestCheckTypeSetElemNestedAttrs(resourceFullName,
// "policies.0.policy_flows.*",
Expand Down Expand Up @@ -87,14 +88,15 @@ func TestAccResourceApplication_WithFlowPolicy(t *testing.T) {
{
Config: testAccResourceApplication_WithFlowPolicy_Hcl(resourceName),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrSet(resourceFullName, "application_id"),
resource.TestCheckResourceAttrSet(resourceFullName, "id"),
resource.TestCheckResourceAttrSet(resourceFullName, "policies.0.policy_id"),
resource.TestCheckNoResourceAttr(resourceFullName, "policies.1.policy_id"),
),
},
{
Config: testAccResourceApplication_WithFlowPolicyUpdate_Hcl(resourceName),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrSet(resourceFullName, "application_id"),
resource.TestCheckResourceAttrSet(resourceFullName, "id"),
resource.TestCheckResourceAttrSet(resourceFullName, "policies.1.policy_id"),
resource.TestCheckResourceAttrSet(resourceFullName, "policies.0.policy_id"),
),
Expand Down Expand Up @@ -133,7 +135,7 @@ resource "davinci_application" "%[2]s" {
policies {
name = "simpleflow"
policy_flows {
id = resource.davinci_flow.%[3]s.id
flow_id = resource.davinci_flow.%[3]s.id
version_id = -1
weight = 100
}
Expand Down Expand Up @@ -174,7 +176,7 @@ resource "davinci_application" "%[2]s" {
policies {
name = "simpleflow"
policy_flows {
id = resource.davinci_flow.%[3]s.id
flow_id = resource.davinci_flow.%[3]s.id
version_id = -1
weight = 100
}
Expand All @@ -183,7 +185,7 @@ resource "davinci_application" "%[2]s" {
policies {
name = "subsequentPolicy"
policy_flows {
id = resource.davinci_flow.%[3]s.id
flow_id = resource.davinci_flow.%[3]s.id
version_id = -1
weight = 100
}
Expand Down
2 changes: 1 addition & 1 deletion internal/service/davinci/resource_connection_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ data "davinci_connection" "http_%[2]s_%[1]s" {
data "davinci_application" "http_%[2]s_%[1]s" {
environment_id = resource.pingone_role_assignment_user.%[2]s.scope_environment_id
application_id = davinci_application.%[2]s_simple_flow_app.application_id
application_id = davinci_application.%[2]s_simple_flow_app.id
depends_on = [data.davinci_connections.read_all]
}
Expand Down
Binary file added terraform-provider-davinci
Binary file not shown.

0 comments on commit 4cc84d7

Please sign in to comment.