Skip to content
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

Use state for unknown for computed attributes which won't change during plan application #677

Merged
merged 21 commits into from
Aug 5, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions ec/ecresource/deploymentresource/apm/v2/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,15 +83,27 @@ func ApmSchema() schema.Attribute {
},
"resource_id": schema.StringAttribute{
Computed: true,
PlanModifiers: []planmodifier.String{
stringplanmodifier.UseStateForUnknown(),
},
},
"region": schema.StringAttribute{
Computed: true,
PlanModifiers: []planmodifier.String{
stringplanmodifier.UseStateForUnknown(),
},
},
"http_endpoint": schema.StringAttribute{
Computed: true,
PlanModifiers: []planmodifier.String{
stringplanmodifier.UseStateForUnknown(),
},
},
"https_endpoint": schema.StringAttribute{
Computed: true,
PlanModifiers: []planmodifier.String{
stringplanmodifier.UseStateForUnknown(),
},
},
"instance_configuration_id": schema.StringAttribute{
Optional: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ func Test_readDeployment(t *testing.T) {
ResourceId: &mock.ValidClusterID,
Region: ec.String("us-east-1"),
Config: &elasticsearchv2.ElasticsearchConfig{
Plugins: []string{},
UserSettingsYaml: ec.String("some.setting: value"),
UserSettingsOverrideYaml: ec.String("some.setting: value2"),
UserSettingsJson: ec.String("{\"some.setting\":\"value\"}"),
Expand Down Expand Up @@ -429,6 +430,7 @@ func Test_readDeployment(t *testing.T) {
ResourceId: &mock.ValidClusterID,
Region: ec.String("us-east-1"),
Config: &elasticsearchv2.ElasticsearchConfig{
Plugins: []string{},
UserSettingsYaml: ec.String("some.setting: value"),
UserSettingsOverrideYaml: ec.String("some.setting: value2"),
UserSettingsJson: ec.String("{\"some.setting\":\"value\"}"),
Expand Down Expand Up @@ -497,7 +499,9 @@ func Test_readDeployment(t *testing.T) {
Autoscaling: &elasticsearchv2.ElasticsearchTopologyAutoscaling{},
},
),
Config: &elasticsearchv2.ElasticsearchConfig{},
Config: &elasticsearchv2.ElasticsearchConfig{
Plugins: []string{},
},
},
Kibana: &kibanav2.Kibana{
ElasticsearchClusterRefId: ec.String("main-elasticsearch"),
Expand Down Expand Up @@ -544,7 +548,9 @@ func Test_readDeployment(t *testing.T) {
CloudID: ec.String("up2d:someCloudID"),
HttpEndpoint: ec.String("http://1239f7ee7196439ba2d105319ac5eba7.eu-central-1.aws.cloud.es.io:9200"),
HttpsEndpoint: ec.String("https://1239f7ee7196439ba2d105319ac5eba7.eu-central-1.aws.cloud.es.io:9243"),
Config: &elasticsearchv2.ElasticsearchConfig{},
Config: &elasticsearchv2.ElasticsearchConfig{
Plugins: []string{},
},
HotTier: elasticsearchv2.CreateTierForTest(
"hot_content",
elasticsearchv2.ElasticsearchTopology{
Expand Down Expand Up @@ -607,7 +613,9 @@ func Test_readDeployment(t *testing.T) {
CloudID: ec.String("up2d:someCloudID"),
HttpEndpoint: ec.String("http://1239f7ee7196439ba2d105319ac5eba7.eu-central-1.aws.cloud.es.io:9200"),
HttpsEndpoint: ec.String("https://1239f7ee7196439ba2d105319ac5eba7.eu-central-1.aws.cloud.es.io:9243"),
Config: &elasticsearchv2.ElasticsearchConfig{},
Config: &elasticsearchv2.ElasticsearchConfig{
Plugins: []string{},
},
HotTier: elasticsearchv2.CreateTierForTest(
"hot_content",
elasticsearchv2.ElasticsearchTopology{
Expand Down Expand Up @@ -753,7 +761,9 @@ func Test_readDeployment(t *testing.T) {
Elasticsearch: &elasticsearchv2.Elasticsearch{
RefId: ec.String("main-elasticsearch"),
Region: ec.String("aws-eu-central-1"),
Config: &elasticsearchv2.ElasticsearchConfig{},
Config: &elasticsearchv2.ElasticsearchConfig{
Plugins: []string{},
},
HotTier: elasticsearchv2.CreateTierForTest(
"hot_content",
elasticsearchv2.ElasticsearchTopology{
Expand Down Expand Up @@ -839,7 +849,9 @@ func Test_readDeployment(t *testing.T) {
Elasticsearch: &elasticsearchv2.Elasticsearch{
RefId: ec.String("main-elasticsearch"),
Region: ec.String("aws-eu-central-1"),
Config: &elasticsearchv2.ElasticsearchConfig{},
Config: &elasticsearchv2.ElasticsearchConfig{
Plugins: []string{},
},
HotTier: elasticsearchv2.CreateTierForTest(
"hot_content",
elasticsearchv2.ElasticsearchTopology{
Expand Down Expand Up @@ -986,6 +998,7 @@ func Test_readDeployment(t *testing.T) {
RefId: ec.String("main-elasticsearch"),
Region: ec.String("aws-eu-central-1"),
Config: &elasticsearchv2.ElasticsearchConfig{
Plugins: []string{},
DockerImage: ec.String("docker.elastic.com/elasticsearch/cloud:7.14.1-hash"),
},
HotTier: elasticsearchv2.CreateTierForTest(
Expand Down Expand Up @@ -1064,7 +1077,9 @@ func Test_readDeployment(t *testing.T) {
CloudID: ec.String("up2d:someCloudID"),
HttpEndpoint: ec.String("http://1239f7ee7196439ba2d105319ac5eba7.eu-central-1.aws.cloud.es.io:9200"),
HttpsEndpoint: ec.String("https://1239f7ee7196439ba2d105319ac5eba7.eu-central-1.aws.cloud.es.io:9243"),
Config: &elasticsearchv2.ElasticsearchConfig{},
Config: &elasticsearchv2.ElasticsearchConfig{
Plugins: []string{},
},
HotTier: elasticsearchv2.CreateTierForTest(
"hot_content",
elasticsearchv2.ElasticsearchTopology{
Expand Down Expand Up @@ -1125,7 +1140,9 @@ func Test_readDeployment(t *testing.T) {
CloudID: ec.String("up2d:someCloudID"),
HttpEndpoint: ec.String("http://123695e76d914005bf90b717e668ad4b.asia-east1.gcp.elastic-cloud.com:9200"),
HttpsEndpoint: ec.String("https://123695e76d914005bf90b717e668ad4b.asia-east1.gcp.elastic-cloud.com:9243"),
Config: &elasticsearchv2.ElasticsearchConfig{},
Config: &elasticsearchv2.ElasticsearchConfig{
Plugins: []string{},
},
HotTier: elasticsearchv2.CreateTierForTest(
"hot_content",
elasticsearchv2.ElasticsearchTopology{
Expand Down Expand Up @@ -1186,7 +1203,9 @@ func Test_readDeployment(t *testing.T) {
CloudID: ec.String("up2d:someCloudID"),
HttpEndpoint: ec.String("http://123695e76d914005bf90b717e668ad4b.asia-east1.gcp.elastic-cloud.com:9200"),
HttpsEndpoint: ec.String("https://123695e76d914005bf90b717e668ad4b.asia-east1.gcp.elastic-cloud.com:9243"),
Config: &elasticsearchv2.ElasticsearchConfig{},
Config: &elasticsearchv2.ElasticsearchConfig{
Plugins: []string{},
},
HotTier: elasticsearchv2.CreateTierForTest(
"hot_content",
elasticsearchv2.ElasticsearchTopology{
Expand Down Expand Up @@ -1297,7 +1316,9 @@ func Test_readDeployment(t *testing.T) {
CloudID: ec.String("up2d-hot-warm:someCloudID"),
HttpEndpoint: ec.String("http://123e837db6ee4391bb74887be35a7a91.us-central1.gcp.cloud.es.io:9200"),
HttpsEndpoint: ec.String("https://123e837db6ee4391bb74887be35a7a91.us-central1.gcp.cloud.es.io:9243"),
Config: &elasticsearchv2.ElasticsearchConfig{},
Config: &elasticsearchv2.ElasticsearchConfig{
Plugins: []string{},
},
HotTier: elasticsearchv2.CreateTierForTest(
"hot_content",
elasticsearchv2.ElasticsearchTopology{
Expand Down Expand Up @@ -1385,7 +1406,9 @@ func Test_readDeployment(t *testing.T) {
CloudID: ec.String("up2d-hot-warm:someCloudID"),
HttpEndpoint: ec.String("http://123e837db6ee4391bb74887be35a7a91.us-central1.gcp.cloud.es.io:9200"),
HttpsEndpoint: ec.String("https://123e837db6ee4391bb74887be35a7a91.us-central1.gcp.cloud.es.io:9243"),
Config: &elasticsearchv2.ElasticsearchConfig{},
Config: &elasticsearchv2.ElasticsearchConfig{
Plugins: []string{},
},
HotTier: elasticsearchv2.CreateTierForTest(
"hot_content",
elasticsearchv2.ElasticsearchTopology{
Expand Down Expand Up @@ -1510,7 +1533,9 @@ func Test_readDeployment(t *testing.T) {
CloudID: ec.String("ccs:someCloudID"),
HttpEndpoint: ec.String("http://1230b3ae633b4f51a432d50971f7f1c1.eu-west-1.aws.found.io:9200"),
HttpsEndpoint: ec.String("https://1230b3ae633b4f51a432d50971f7f1c1.eu-west-1.aws.found.io:9243"),
Config: &elasticsearchv2.ElasticsearchConfig{},
Config: &elasticsearchv2.ElasticsearchConfig{
Plugins: []string{},
},
RemoteCluster: elasticsearchv2.ElasticsearchRemoteClusters{
{
Alias: ec.String("alias"),
Expand Down
3 changes: 3 additions & 0 deletions ec/ecresource/deploymentresource/deployment/v2/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,9 @@ func DeploymentSchema() schema.Schema {
"apm_secret_token": schema.StringAttribute{
Computed: true,
Sensitive: true,
PlanModifiers: []planmodifier.String{
stringplanmodifier.UseStateForUnknown(),
},
},
"traffic_filter": schema.SetAttribute{
ElementType: types.StringType,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ func readElasticsearchConfig(in *models.ElasticsearchConfiguration) (*Elasticsea
return &ElasticsearchConfig{}, nil
}

config.Plugins = []string{}
Copy link
Contributor

Choose a reason for hiding this comment

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

It can lead to the inconsistency error if config is empty. Also it's not needed - append can append to nil.

Copy link
Contributor

Choose a reason for hiding this comment

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

I mean if TF configuration doesn't have config.

Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
config.Plugins = []string{}

if len(in.EnabledBuiltInPlugins) > 0 {
config.Plugins = append(config.Plugins, in.EnabledBuiltInPlugins...)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,9 @@ func Test_readElasticsearch(t *testing.T) {
CloudID: ec.String("some CLOUD ID"),
HttpEndpoint: ec.String("http://somecluster.cloud.elastic.co:9200"),
HttpsEndpoint: ec.String("https://somecluster.cloud.elastic.co:9243"),
Config: &ElasticsearchConfig{},
Config: &ElasticsearchConfig{
Plugins: []string{},
},
HotTier: &ElasticsearchTopology{
id: "hot_content",
InstanceConfigurationId: ec.String("aws.data.highio.i3"),
Expand Down Expand Up @@ -243,6 +245,7 @@ func Test_readElasticsearch(t *testing.T) {
HttpEndpoint: ec.String("http://othercluster.cloud.elastic.co:9200"),
HttpsEndpoint: ec.String("https://othercluster.cloud.elastic.co:9243"),
Config: &ElasticsearchConfig{
Plugins: []string{},
UserSettingsYaml: ec.String("some.setting: value"),
UserSettingsOverrideYaml: ec.String("some.setting: value2"),
UserSettingsJson: ec.String("{\"some.setting\":\"value\"}"),
Expand Down Expand Up @@ -374,7 +377,9 @@ func Test_readElasticsearch(t *testing.T) {
CloudID: ec.String("some CLOUD ID"),
HttpEndpoint: ec.String("http://somecluster.cloud.elastic.co:9200"),
HttpsEndpoint: ec.String("https://somecluster.cloud.elastic.co:9243"),
Config: &ElasticsearchConfig{},
Config: &ElasticsearchConfig{
Plugins: []string{},
},
HotTier: &ElasticsearchTopology{
id: "hot_content",
InstanceConfigurationId: ec.String("aws.data.highio.i3"),
Expand Down
15 changes: 15 additions & 0 deletions ec/ecresource/deploymentresource/elasticsearch/v2/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ func ElasticsearchSchema() schema.Attribute {
"resource_id": schema.StringAttribute{
Description: "The Elasticsearch resource unique identifier",
Computed: true,
PlanModifiers: []planmodifier.String{
stringplanmodifier.UseStateForUnknown(),
},
},
"region": schema.StringAttribute{
Description: "The Elasticsearch resource region",
Expand All @@ -84,14 +87,23 @@ func ElasticsearchSchema() schema.Attribute {
"cloud_id": schema.StringAttribute{
Description: "The encoded Elasticsearch credentials to use in Beats or Logstash",
Computed: true,
PlanModifiers: []planmodifier.String{
stringplanmodifier.UseStateForUnknown(),
},
},
"http_endpoint": schema.StringAttribute{
Description: "The Elasticsearch resource HTTP endpoint",
Computed: true,
PlanModifiers: []planmodifier.String{
stringplanmodifier.UseStateForUnknown(),
},
},
"https_endpoint": schema.StringAttribute{
Description: "The Elasticsearch resource HTTPs endpoint",
Computed: true,
PlanModifiers: []planmodifier.String{
stringplanmodifier.UseStateForUnknown(),
},
},

"hot": elasticsearchTopologySchema("'hot' topology element", true, "hot"),
Expand Down Expand Up @@ -139,6 +151,9 @@ func elasticsearchConfigSchema() schema.Attribute {
Description: "List of Elasticsearch supported plugins, which vary from version to version. Check the Stack Pack version to see which plugins are supported for each version. This is currently only available from the UI and [ecctl](https://www.elastic.co/guide/en/ecctl/master/ecctl_stack_list.html)",
Optional: true,
Computed: true,
PlanModifiers: []planmodifier.Set{
setplanmodifier.UseStateForUnknown(),
},
},
"user_settings_json": schema.StringAttribute{
Description: `JSON-formatted user level "elasticsearch.yml" setting overrides`,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"github.com/elastic/terraform-provider-ec/ec/internal/planmodifiers"
"github.com/hashicorp/terraform-plugin-framework/resource/schema"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/int64planmodifier"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/objectplanmodifier"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier"
)
Expand Down Expand Up @@ -87,6 +88,9 @@ func IntegrationsServerSchema() schema.Attribute {
},
},
},
PlanModifiers: []planmodifier.Object{
objectplanmodifier.UseStateForUnknown(),
},
},
"instance_configuration_id": schema.StringAttribute{
Optional: true,
Expand Down
10 changes: 10 additions & 0 deletions ec/ecresource/extensionresource/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"github.com/hashicorp/terraform-plugin-framework/path"
"github.com/hashicorp/terraform-plugin-framework/resource"
"github.com/hashicorp/terraform-plugin-framework/resource/schema"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/int64planmodifier"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier"
"github.com/hashicorp/terraform-plugin-framework/types"
Expand Down Expand Up @@ -91,14 +92,23 @@ func (r *Resource) Schema(_ context.Context, _ resource.SchemaRequest, resp *res
"url": schema.StringAttribute{
Description: "The extension URL which will be used in the Elastic Cloud deployment plan.",
Computed: true,
PlanModifiers: []planmodifier.String{
stringplanmodifier.UseStateForUnknown(),
},
},
"last_modified": schema.StringAttribute{
Description: "The datatime the extension was last modified.",
Computed: true,
PlanModifiers: []planmodifier.String{
stringplanmodifier.UseStateForUnknown(),
},
},
"size": schema.Int64Attribute{
Description: "The size of the extension file in bytes.",
Computed: true,
PlanModifiers: []planmodifier.Int64{
int64planmodifier.UseStateForUnknown(),
},
},
// Computed attributes
"id": schema.StringAttribute{
Expand Down