-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #176 from dome9/CON-8179-AWP-Onboarding-AWS
This pull request introduces changes related to the AWP AWS onboarding process in the Dome9 Terraform provider. Implementing AWP Onboarding API (https://github.com/dome9/dome9-sdk-go/releases/tag/v1.18.4) * **resource** - dome9_awp_aws_onboarding * **data** - dome9_awp_aws_onboarding * **data** - dome9_awp_aws_onboarding_data
- Loading branch information
Showing
38 changed files
with
1,565 additions
and
53 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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 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 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,136 @@ | ||
package dome9 | ||
|
||
import ( | ||
"github.com/hashicorp/terraform-plugin-sdk/helper/schema" | ||
"log" | ||
) | ||
|
||
func dataSourceAwpAwsOnboarding() *schema.Resource { | ||
return &schema.Resource{ | ||
Read: dataSourceAwpAwsOnboardingRead, | ||
|
||
Schema: map[string]*schema.Schema{ | ||
"id": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
}, | ||
"scan_mode": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"agentless_account_settings": { | ||
Type: schema.TypeSet, | ||
Computed: true, | ||
Elem: &schema.Resource{ | ||
Schema: map[string]*schema.Schema{ | ||
"disabled_regions": { | ||
Type: schema.TypeList, | ||
Computed: true, | ||
Elem: &schema.Schema{ | ||
Type: schema.TypeString, | ||
}, | ||
}, | ||
"scan_machine_interval_in_hours": { | ||
Type: schema.TypeInt, | ||
Computed: true, | ||
}, | ||
"max_concurrent_scans_per_region": { | ||
Type: schema.TypeInt, | ||
Computed: true, | ||
}, | ||
"custom_tags": { | ||
Type: schema.TypeMap, | ||
Computed: true, | ||
Elem: &schema.Resource{ | ||
Schema: map[string]*schema.Schema{}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
"missing_awp_private_network_regions": { | ||
Type: schema.TypeList, | ||
Computed: true, | ||
Elem: &schema.Schema{Type: schema.TypeString}, | ||
}, | ||
"account_issues": { | ||
Type: schema.TypeList, | ||
Computed: true, | ||
Elem: &schema.Resource{ | ||
Schema: map[string]*schema.Schema{ | ||
"regions": { | ||
Type: schema.TypeMap, | ||
Optional: true, | ||
}, | ||
"account": { | ||
Type: schema.TypeMap, | ||
Optional: true, | ||
Elem: &schema.Resource{ | ||
Schema: map[string]*schema.Schema{ | ||
"issue_type": { | ||
Type: schema.TypeString, | ||
Optional: true, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
"cloud_account_id": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"agentless_protection_enabled": { | ||
Type: schema.TypeBool, | ||
Computed: true, | ||
}, | ||
"cloud_provider": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"should_update": { | ||
Type: schema.TypeBool, | ||
Computed: true, | ||
}, | ||
"is_org_onboarding": { | ||
Type: schema.TypeBool, | ||
Computed: true, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func dataSourceAwpAwsOnboardingRead(d *schema.ResourceData, meta interface{}) error { | ||
d9Client := meta.(*Client) | ||
|
||
cloudguardAccountId := d.Get("id").(string) | ||
log.Printf("Getting data for AWP AWS Onboarding id: %s\n", cloudguardAccountId) | ||
|
||
resp, _, err := d9Client.awpAwsOnboarding.GetAWPOnboarding("aws", cloudguardAccountId) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
d.SetId(resp.CloudAccountId) | ||
// Set other schema fields here | ||
_ = d.Set("scan_mode", resp.ScanMode) | ||
_ = d.Set("missing_awp_private_network_regions", resp.MissingAwpPrivateNetworkRegions) | ||
_ = d.Set("cloud_account_id", resp.CloudAccountId) | ||
_ = d.Set("agentless_protection_enabled", resp.AgentlessProtectionEnabled) | ||
_ = d.Set("cloud_provider", resp.Provider) | ||
_ = d.Set("should_update", resp.ShouldUpdate) | ||
_ = d.Set("is_org_onboarding", resp.IsOrgOnboarding) | ||
|
||
if resp.AgentlessAccountSettings != nil { | ||
if err := d.Set("agentless_account_settings", flattenAgentlessAccountSettings(resp.AgentlessAccountSettings)); err != nil { | ||
return err | ||
} | ||
} | ||
if resp.AccountIssues != nil { | ||
if err := d.Set("account_issues", flattenAccountIssues(resp.AccountIssues)); err != nil { | ||
return err | ||
} | ||
} | ||
return nil | ||
} |
This file contains 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,93 @@ | ||
package dome9 | ||
|
||
import ( | ||
"encoding/base64" | ||
"github.com/hashicorp/terraform-plugin-sdk/helper/schema" | ||
) | ||
|
||
func dataSourceAwpAwsOnboardingData() *schema.Resource { | ||
return &schema.Resource{ | ||
Read: dataSourceAwpAwsOnboardingDataRead, | ||
|
||
Schema: map[string]*schema.Schema{ | ||
"cloud_account_id": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
}, | ||
"stage": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"region": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"cloud_guard_backend_account_id": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"agentless_bucket_name": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"remote_functions_prefix_key": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"remote_snapshots_utils_function_name": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"remote_snapshots_utils_function_run_time": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"remote_snapshots_utils_function_time_out": { | ||
Type: schema.TypeInt, | ||
Computed: true, | ||
}, | ||
"awp_client_side_security_group_name": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"cross_account_role_external_id": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"remote_snapshots_utils_function_s3_pre_signed_url": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func dataSourceAwpAwsOnboardingDataRead(d *schema.ResourceData, meta interface{}) error { | ||
d9Client := meta.(*Client) | ||
|
||
resp, _, err := d9Client.awpAwsOnboarding.Get() | ||
if err != nil { | ||
return err | ||
} | ||
|
||
d.SetId(resp.CloudGuardBackendAccountId) | ||
_ = d.Set("stage", resp.Stage) | ||
_ = d.Set("region", resp.Region) | ||
_ = d.Set("cloud_guard_backend_account_id", resp.CloudGuardBackendAccountId) | ||
_ = d.Set("agentless_bucket_name", resp.AgentlessBucketName) | ||
_ = d.Set("remote_functions_prefix_key", resp.RemoteFunctionsPrefixKey) | ||
_ = d.Set("remote_snapshots_utils_function_name", resp.RemoteSnapshotsUtilsFunctionName) | ||
_ = d.Set("remote_snapshots_utils_function_run_time", resp.RemoteSnapshotsUtilsFunctionRunTime) | ||
_ = d.Set("remote_snapshots_utils_function_time_out", resp.RemoteSnapshotsUtilsFunctionTimeOut) | ||
_ = d.Set("awp_client_side_security_group_name", resp.AwpClientSideSecurityGroupName) | ||
cloudAccountID, _, err := d9Client.awpAwsOnboarding.GetCloudAccountId(d.Get("cloud_account_id").(string)) | ||
if err != nil { | ||
return err | ||
} | ||
combinedString := resp.CloudGuardBackendAccountId + "-" + cloudAccountID | ||
encodedString := base64.StdEncoding.EncodeToString([]byte(combinedString)) | ||
_ = d.Set("cross_account_role_external_id", encodedString) | ||
_ = d.Set("remote_snapshots_utils_function_s3_pre_signed_url", resp.RemoteSnapshotsUtilsFunctionS3PreSignedUrl) | ||
|
||
return nil | ||
} |
Oops, something went wrong.