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

Keep failed resources, add state output value #331

Merged
merged 13 commits into from
Jun 28, 2022
1 change: 1 addition & 0 deletions docs/data-sources/aws_network_peering.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ data "hcp_aws_network_peering" "test" {
- `project_id` (String) The ID of the HCP project where the network peering is located. Always matches the HVN's project.
- `provider_peering_id` (String) The peering connection ID used by AWS.
- `self_link` (String) A unique URL identifying the network peering.
- `state` (String) The state of the network peering.

<a id="nestedblock--timeouts"></a>
### Nested Schema for `timeouts`
Expand Down
1 change: 1 addition & 0 deletions docs/data-sources/azure_peering_connection.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ data "hcp_azure_peering_connection" "test" {
- `peer_vnet_region` (String) The region of the peer VNet in Azure.
- `project_id` (String) The ID of the HCP project where the peering connection is located. Always matches the HVN's project.
- `self_link` (String) A unique URL identifying the peering connection
- `state` (String) The state of the Azure peering connection.

<a id="nestedblock--timeouts"></a>
### Nested Schema for `timeouts`
Expand Down
1 change: 1 addition & 0 deletions docs/data-sources/consul_cluster.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ data "hcp_consul_cluster" "example" {
- `scale` (Number) The the number of Consul server nodes in the cluster.
- `self_link` (String) A unique URL identifying the HCP Consul cluster.
- `size` (String) The t-shirt size representation of each server VM that this Consul cluster is provisioned with. Valid option for development tier - `x_small`. Valid options for other tiers - `small`, `medium`, `large`. For more details - https://cloud.hashicorp.com/pricing/consul
- `state` (String) The state of the HCP Consul cluster.
- `tier` (String) The tier that the HCP Consul cluster will be provisioned as. Only `development`, `standard` and `plus` are available at this time.

<a id="nestedblock--timeouts"></a>
Expand Down
1 change: 1 addition & 0 deletions docs/data-sources/hvn.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ data "hcp_hvn" "example" {
- `provider_account_id` (String) The provider account ID where the HVN is located.
- `region` (String) The region where the HVN is located.
- `self_link` (String) A unique URL identifying the HVN.
- `state` (String) The state of the HVN route.

<a id="nestedblock--timeouts"></a>
### Nested Schema for `timeouts`
Expand Down
1 change: 1 addition & 0 deletions docs/data-sources/hvn_peering_connection.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ data "hcp_hvn_peering_connection" "test" {
- `organization_id` (String) The ID of the HCP organization where the peering connection is located. Always matches the HVNs' organization.
- `project_id` (String) The ID of the HCP project where the peering connection is located. Always matches the HVNs' project.
- `self_link` (String) A unique URL identifying the peering connection
- `state` (String) The state of the HVN peering connection.

<a id="nestedblock--timeouts"></a>
### Nested Schema for `timeouts`
Expand Down
1 change: 1 addition & 0 deletions docs/data-sources/vault_cluster.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ data "hcp_vault_cluster" "example" {
- `public_endpoint` (Boolean) Denotes that the cluster has a public endpoint. Defaults to false.
- `region` (String) The region where the HCP Vault cluster is located.
- `self_link` (String) A unique URL identifying the Vault cluster.
- `state` (String) The state of the Vault cluster.
- `tier` (String) The tier that the HCP Vault cluster will be provisioned as. Only 'development' is available at this time.
- `vault_private_endpoint_url` (String) The private URL for the Vault cluster.
- `vault_public_endpoint_url` (String) The public URL for the Vault cluster. This will be empty if `public_endpoint` is `false`.
Expand Down
1 change: 1 addition & 0 deletions docs/resources/aws_network_peering.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ resource "aws_vpc_peering_connection_accepter" "peer" {
- `project_id` (String) The ID of the HCP project where the network peering is located. Always matches the HVN's project.
- `provider_peering_id` (String) The peering connection ID used by AWS.
- `self_link` (String) A unique URL identifying the network peering.
- `state` (String) The state of the network peering.

<a id="nestedblock--timeouts"></a>
### Nested Schema for `timeouts`
Expand Down
1 change: 1 addition & 0 deletions docs/resources/azure_peering_connection.md
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ resource "azurerm_role_assignment" "assignment" {
- `organization_id` (String) The ID of the HCP organization where the peering connection is located. Always matches the HVN's organization.
- `project_id` (String) The ID of the HCP project where the peering connection is located. Always matches the HVN's project.
- `self_link` (String) A unique URL identifying the peering connection.
- `state` (String) The state of the Azure peering connection.

<a id="nestedblock--timeouts"></a>
### Nested Schema for `timeouts`
Expand Down
1 change: 1 addition & 0 deletions docs/resources/consul_cluster.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ resource "hcp_consul_cluster" "example" {
- `region` (String) The region where the HCP Consul cluster is located.
- `scale` (Number) The number of Consul server nodes in the cluster.
- `self_link` (String) A unique URL identifying the HCP Consul cluster.
- `state` (String) The state of the HCP Consul cluster.

<a id="nestedblock--timeouts"></a>
### Nested Schema for `timeouts`
Expand Down
1 change: 1 addition & 0 deletions docs/resources/consul_snapshot.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ resource "hcp_consul_snapshot" "example" {
- `restored_at` (String) Timestamp of when the snapshot was restored. If the snapshot has not been restored, this field will be blank.
- `size` (Number) The size of the snapshot in bytes.
- `snapshot_id` (String) The ID of the Consul snapshot
- `state` (String) The state of an HCP Consul snapshot.

<a id="nestedblock--timeouts"></a>
### Nested Schema for `timeouts`
Expand Down
1 change: 1 addition & 0 deletions docs/resources/hvn.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ resource "hcp_hvn" "example" {
- `project_id` (String) The ID of the HCP project where the HVN is located.
- `provider_account_id` (String) The provider account ID where the HVN is located.
- `self_link` (String) A unique URL identifying the HVN.
- `state` (String) The state of the HVN.

<a id="nestedblock--timeouts"></a>
### Nested Schema for `timeouts`
Expand Down
1 change: 1 addition & 0 deletions docs/resources/hvn_peering_connection.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ resource "hcp_hvn_peering_connection" "peer_1" {
- `peering_id` (String) The ID of the peering connection.
- `project_id` (String) The ID of the HCP project where the peering connection is located. Always matches the HVNs' project.
- `self_link` (String) A unique URL identifying the peering connection
- `state` (String) The state of the HVN peering connection.

<a id="nestedblock--timeouts"></a>
### Nested Schema for `timeouts`
Expand Down
1 change: 1 addition & 0 deletions docs/resources/vault_cluster.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ resource "hcp_vault_cluster" "example" {
- `project_id` (String) The ID of the project this HCP Vault cluster is located in.
- `region` (String) The region where the HCP Vault cluster is located.
- `self_link` (String) A unique URL identifying the Vault cluster.
- `state` (String) The state of the Vault cluster.
- `vault_private_endpoint_url` (String) The private URL for the Vault cluster.
- `vault_public_endpoint_url` (String) The public URL for the Vault cluster. This will be empty if `public_endpoint` is `false`.
- `vault_version` (String) The Vault version of the cluster.
Expand Down
5 changes: 5 additions & 0 deletions internal/provider/data_source_aws_network_peering.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,11 @@ func dataSourceAwsNetworkPeering() *schema.Resource {
Type: schema.TypeString,
Computed: true,
},
"state": {
Description: "The state of the network peering.",
Type: schema.TypeString,
Computed: true,
},
},
}
}
Expand Down
5 changes: 5 additions & 0 deletions internal/provider/data_source_azure_peering_connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,11 @@ func dataSourceAzurePeeringConnection() *schema.Resource {
Type: schema.TypeString,
Computed: true,
},
"state": {
Description: "The state of the Azure peering connection.",
Type: schema.TypeString,
Computed: true,
},
},
}
}
Expand Down
49 changes: 37 additions & 12 deletions internal/provider/data_source_consul_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@ func dataSourceConsulCluster() *schema.Resource {
Type: schema.TypeString,
Computed: true,
},
"state": {
Description: "The state of the HCP Consul cluster.",
Type: schema.TypeString,
Computed: true,
},
"connect_enabled": {
Description: "Denotes the Consul connect feature should be enabled for this cluster. Default to true.",
Type: schema.TypeBool,
Expand Down Expand Up @@ -168,22 +173,30 @@ func dataSourceConsulClusterRead(ctx context.Context, d *schema.ResourceData, me

d.SetId(url)

// cluster found, set data source attributes
if err := setConsulClusterDataSourceAttributes(d, cluster); err != nil {
return diag.FromErr(err)
}

// get the cluster's Consul client config files
clientConfigFiles, err := clients.GetConsulClientConfigFiles(ctx, client, loc, clusterID)
if err != nil {
return diag.Errorf("unable to retrieve Consul cluster (%s) client config files: %v", clusterID, err)
}

// Cluster found, update resource data
if err := setConsulClusterDataSourceAttributes(d, cluster, clientConfigFiles); err != nil {
// client config found, set data source attributes
if err := setConsulClusterClientConfigDataSourceAttributes(d, clientConfigFiles); err != nil {
return diag.FromErr(err)
}

return nil
}

func setConsulClusterDataSourceAttributes(d *schema.ResourceData, cluster *consulmodels.HashicorpCloudConsul20210204Cluster,
clientConfigFiles *consulmodels.HashicorpCloudConsul20210204GetClientConfigResponse) error {
// setConsulClusterDataSourceAttributes sets all data source attributes from the cluster
func setConsulClusterDataSourceAttributes(
d *schema.ResourceData,
cluster *consulmodels.HashicorpCloudConsul20210204Cluster,
) error {

if err := d.Set("cluster_id", cluster.ID); err != nil {
return err
Expand Down Expand Up @@ -218,6 +231,10 @@ func setConsulClusterDataSourceAttributes(d *schema.ResourceData, cluster *consu
return err
}

if err := d.Set("state", cluster.State); err != nil {
return err
}

if err := d.Set("scale", cluster.Config.CapacityConfig.Scale); err != nil {
return err
}
Expand All @@ -238,14 +255,6 @@ func setConsulClusterDataSourceAttributes(d *schema.ResourceData, cluster *consu
return err
}

if err := d.Set("consul_config_file", clientConfigFiles.ConsulConfigFile.String()); err != nil {
return err
}

if err := d.Set("consul_ca_file", clientConfigFiles.CaFile.String()); err != nil {
return err
}

if err := d.Set("connect_enabled", cluster.Config.ConsulConfig.ConnectEnabled); err != nil {
return err
}
Expand Down Expand Up @@ -292,3 +301,19 @@ func setConsulClusterDataSourceAttributes(d *schema.ResourceData, cluster *consu

return nil
}

// setConsulClusterClientConfigResourceData sets all resource data that's derived from client config meta
func setConsulClusterClientConfigDataSourceAttributes(
d *schema.ResourceData,
clientConfigFiles *consulmodels.HashicorpCloudConsul20210204GetClientConfigResponse,
) error {
if err := d.Set("consul_config_file", clientConfigFiles.ConsulConfigFile.String()); err != nil {
return err
}

if err := d.Set("consul_ca_file", clientConfigFiles.CaFile.String()); err != nil {
return err
}

return nil
}
5 changes: 5 additions & 0 deletions internal/provider/data_source_hvn.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@ func dataSourceHvn() *schema.Resource {
Type: schema.TypeString,
Computed: true,
},
"state": {
Description: "The state of the HVN route.",
Type: schema.TypeString,
Computed: true,
},
},
}
}
Expand Down
5 changes: 5 additions & 0 deletions internal/provider/data_source_hvn_peering_connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@ func dataSourceHvnPeeringConnection() *schema.Resource {
Type: schema.TypeString,
Computed: true,
},
"state": {
Description: "The state of the HVN peering connection.",
Type: schema.TypeString,
Computed: true,
},
},
}
}
Expand Down
5 changes: 5 additions & 0 deletions internal/provider/data_source_vault_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,11 @@ func dataSourceVaultCluster() *schema.Resource {
Type: schema.TypeString,
Computed: true,
},
"state": {
Description: "The state of the Vault cluster.",
Type: schema.TypeString,
Computed: true,
},
"primary_link": {
Description: "The `self_link` of the HCP Vault Plus tier cluster which is the primary in the performance replication setup with this HCP Vault Plus tier cluster. If not specified, it is a standalone Plus tier HCP Vault cluster.",
Type: schema.TypeString,
Expand Down
16 changes: 8 additions & 8 deletions internal/provider/resource_aws_network_peering.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,11 @@ func resourceAwsNetworkPeering() *schema.Resource {
Type: schema.TypeString,
Computed: true,
},
"state": {
Description: "The state of the network peering.",
Type: schema.TypeString,
Computed: true,
},
},
}
}
Expand Down Expand Up @@ -231,14 +236,6 @@ func resourceAwsNetworkPeeringRead(ctx context.Context, d *schema.ResourceData,
return diag.Errorf("unable to retrieve network peering (%s): %v", peeringID, err)
}

// The network peering failed to provision properly so we want to let the user know and
// remove it from state
if peering.State == networkmodels.HashicorpCloudNetwork20200907PeeringStateFAILED {
log.Printf("[WARN] Network peering (%s) failed to provision, removing from state", peering.ID)
d.SetId("")
return nil
}

// Network peering found, update resource data
if err := setAwsPeeringResourceData(d, peering); err != nil {
return diag.FromErr(err)
Expand Down Expand Up @@ -321,6 +318,9 @@ func setAwsPeeringResourceData(d *schema.ResourceData, peering *networkmodels.Ha
if err := d.Set("expires_at", peering.ExpiresAt.String()); err != nil {
return err
}
if err := d.Set("state", peering.State); err != nil {
return err
}

link := newLink(peering.Hvn.Location, PeeringResourceType, peering.ID)
selfLink, err := linkURL(link)
Expand Down
2 changes: 2 additions & 0 deletions internal/provider/resource_aws_network_peering_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ func TestAccAwsPeering(t *testing.T) {
resource.TestCheckResourceAttrSet(resourceName, "project_id"),
resource.TestCheckResourceAttrSet(resourceName, "created_at"),
resource.TestCheckResourceAttrSet(resourceName, "expires_at"),
resource.TestCheckResourceAttrSet(resourceName, "state"),
testLink(resourceName, "self_link", "test-peering", PeeringResourceType, "hcp_hvn.test"),
),
},
Expand All @@ -130,6 +131,7 @@ func TestAccAwsPeering(t *testing.T) {
resource.TestCheckResourceAttrSet(resourceName, "project_id"),
resource.TestCheckResourceAttrSet(resourceName, "created_at"),
resource.TestCheckResourceAttrSet(resourceName, "expires_at"),
resource.TestCheckResourceAttrSet(resourceName, "state"),
testLink(resourceName, "self_link", "test-peering", PeeringResourceType, "hcp_hvn.test"),
),
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -226,14 +226,6 @@ func resourceAwsTransitGatewayAttachmentRead(ctx context.Context, d *schema.Reso
return diag.Errorf("unable to retrieve transit gateway attachment (%s): %v", tgwAttID, err)
}

// The TGW attachment failed to provision properly so we want to let the user know and
// remove it from state
if tgwAtt.State == networkmodels.HashicorpCloudNetwork20200907TGWAttachmentStateFAILED {
log.Printf("[WARN] Transit gateway attachment (%s) failed to provision, removing from state", tgwAtt.ID)
d.SetId("")
return nil
}

// TGW attachment has been found, update resource data
if err := setTransitGatewayAttachmentResourceData(d, tgwAtt); err != nil {
return diag.FromErr(err)
Expand Down
16 changes: 8 additions & 8 deletions internal/provider/resource_azure_peering_connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,11 @@ func resourceAzurePeeringConnection() *schema.Resource {
Type: schema.TypeString,
Computed: true,
},
"state": {
Description: "The state of the Azure peering connection.",
Type: schema.TypeString,
Computed: true,
},
},
}
}
Expand Down Expand Up @@ -254,14 +259,6 @@ func resourceAzurePeeringConnectionRead(ctx context.Context, d *schema.ResourceD
return diag.Errorf("unable to retrieve peering connection (%s): %v", peeringID, err)
}

// The peering connection failed to provision properly so we want to let the user know and
// remove it from state
if peering.State == networkmodels.HashicorpCloudNetwork20200907PeeringStateFAILED {
log.Printf("[WARN] peering connection (%s) failed to provision, removing from state", peering.ID)
d.SetId("")
return nil
}

// peering connection found, update resource data
if err := setAzurePeeringResourceData(d, peering); err != nil {
return diag.FromErr(err)
Expand Down Expand Up @@ -352,6 +349,9 @@ func setAzurePeeringResourceData(d *schema.ResourceData, peering *networkmodels.
if err := d.Set("expires_at", peering.ExpiresAt.String()); err != nil {
return err
}
if err := d.Set("state", peering.State); err != nil {
return err
}

link := newLink(peering.Hvn.Location, PeeringResourceType, peering.ID)
selfLink, err := linkURL(link)
Expand Down
2 changes: 2 additions & 0 deletions internal/provider/resource_azure_peering_connection_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ func TestAccAzurePeeringConnection(t *testing.T) {
resource.TestCheckResourceAttrSet(resourceName, "project_id"),
resource.TestCheckResourceAttrSet(resourceName, "created_at"),
resource.TestCheckResourceAttrSet(resourceName, "expires_at"),
resource.TestCheckResourceAttrSet(resourceName, "state"),
testLink(resourceName, "self_link", uniqueAzurePeeringTestID, PeeringResourceType, "hcp_hvn.test"),
),
},
Expand All @@ -153,6 +154,7 @@ func TestAccAzurePeeringConnection(t *testing.T) {
resource.TestCheckResourceAttrSet(resourceName, "project_id"),
resource.TestCheckResourceAttrSet(resourceName, "created_at"),
resource.TestCheckResourceAttrSet(resourceName, "expires_at"),
resource.TestCheckResourceAttrSet(resourceName, "state"),
testLink(resourceName, "self_link", uniqueAzurePeeringTestID, PeeringResourceType, "hcp_hvn.test"),
),
},
Expand Down
Loading